身份核對

使用者註冊

Weblate 的默認設置使用 python-social-auth,網站上處理新用戶註冊的一種形式。確定電子郵箱後,新用戶可以通過使用一種第三方服務來貢獻或證實。

還可以使用 REGISTRATION_OPEN 關閉新用戶註冊。

身份驗證嘗試服從於 頻次限制

身份驗證後台

Django的內置解決方案用途是進行身份驗證,包括用各種社交登錄選項進行驗證。使用它意味著可以導入基於 Django 其他項目的用戶數據庫(請參見 Migrating from Pootle )。

也可以另外新建 Django,相對於其他方式進行身份驗證。

也參考

身份驗證設置 描述瞭如何配置官方 Docker 鏡像的身份驗證。

社交身份驗證

由於 Welcome to Python Social Auth’s documentation!, Weblate 支持很多使用第三方服務的身份驗證,如 GitLab 、 Ubuntu 、 Fedora 等。

請檢查 Django Framework 中的通用配置指示的文件。

備註

Weblate 默認依賴於第三方身份驗證服務來提供合法的電子郵箱地址。如果想要使用的一些服務不支持,請通過為其配置 FORCE_EMAIL_VALIDATION,來強制 Weblate 網站上的電子郵箱驗證:

SOCIAL_AUTH_OPENSUSE_FORCE_EMAIL_VALIDATION = True

也參考

Pipeline

啟用單獨的後端非常簡單,只需添加一個條目至設置:setting:`django:AUTHENTICATION_BACKENDS`即可(可能還需為一個給定的驗證方式添加密鑰) 請注意,一些後端默認不提供用戶電子郵件,你必須明確地請求,否則Weblate無法將功勞歸於作出貢獻的用戶。

提示

Most of the authentication backends require HTTPS. Once HTTPS is enabled in your web server please configure Weblate to report it properly using ENABLE_HTTPS, or by WEBLATE_ENABLE_HTTPS in the Docker container.

也參考

:doc:python seamial auth stend <psa:backends / index>

OpenID 驗證

對於基於 OpenID 的服務,通常只要啟用它們就行了。後面的部分關於對於 OpenSUSE 、 Fedora 和 Ubuntu 允許 OpenID 身份驗證:

# Authentication configuration
AUTHENTICATION_BACKENDS = (
    "social_core.backends.email.EmailAuth",
    "social_core.backends.suse.OpenSUSEOpenId",
    "social_core.backends.ubuntu.UbuntuOpenId",
    "social_core.backends.fedora.FedoraOpenId",
    "weblate.accounts.auth.WeblateUserBackend",
)

也參考

OpenID

GitHub 驗證

需要在 GitHub 上註冊一個 OAuth 應用,然後告訴 Weblate 所有的 secrets:

# Authentication configuration
AUTHENTICATION_BACKENDS = (
    "social_core.backends.github.GithubOAuth2",
    "social_core.backends.email.EmailAuth",
    "weblate.accounts.auth.WeblateUserBackend",
)

# Social auth backends setup
SOCIAL_AUTH_GITHUB_KEY = "GitHub Client ID"
SOCIAL_AUTH_GITHUB_SECRET = "GitHub Client Secret"
SOCIAL_AUTH_GITHUB_SCOPE = ["user:email"]

應該配置GitHub 具有回調 URL 作為 https://example.com/accounts/complete/github/

There are similar authentication backends for GitHub for Organizations and GitHub for Teams. Their settings are named SOCIAL_AUTH_GITHUB_ORG_* and SOCIAL_AUTH_GITHUB_TEAM_*, and they require additional setting of the scope - SOCIAL_AUTH_GITHUB_ORG_NAME or SOCIAL_AUTH_GITHUB_TEAM_ID. Their callback URLs are https://example.com/accounts/complete/github-org/ and https://example.com/accounts/complete/github-teams/.

備註

Weblate 在身份驗證時提供的回調 URL。在得到 URL 不匹配的錯誤時,可以根據需要來修復,請參見 設置正確的網站域名

也參考

GitHub

Butbucket 驗證

需要在 Bitbucket 上註冊應用,然後告訴 Weblate 所有的秘密:

# Authentication configuration
AUTHENTICATION_BACKENDS = (
    "social_core.backends.bitbucket.BitbucketOAuth2",
    "social_core.backends.email.EmailAuth",
    "weblate.accounts.auth.WeblateUserBackend",
)

# Social auth backends setup
SOCIAL_AUTH_BITBUCKET_OAUTH2_KEY = "Bitbucket Client ID"
SOCIAL_AUTH_BITBUCKET_OAUTH2_SECRET = "Bitbucket Client Secret"
SOCIAL_AUTH_BITBUCKET_OAUTH2_VERIFIED_EMAILS_ONLY = True

備註

Weblate 在身份驗證時提供的回調 URL。在得到 URL 不匹配的錯誤時,可以根據需要來修復,請參見 設置正確的網站域名

也參考

Bitbucket

Google OAuth 2

為了使用 Google OAuth 2,可以在 <https://console.developers.google.com/> 上註冊應用,並允許 Google+ API。

重定向 URL 為 https://WEBLATE SERVER/accounts/complete/google-oauth2/

# Authentication configuration
AUTHENTICATION_BACKENDS = (
    "social_core.backends.google.GoogleOAuth2",
    "social_core.backends.email.EmailAuth",
    "weblate.accounts.auth.WeblateUserBackend",
)

# Social auth backends setup
SOCIAL_AUTH_GOOGLE_OAUTH2_KEY = "Client ID"
SOCIAL_AUTH_GOOGLE_OAUTH2_SECRET = "Client secret"

備註

Weblate 在身份驗證時提供的回調 URL。在得到 URL 不匹配的錯誤時,可以根據需要來修復,請參見 設置正確的網站域名

也參考

Google

Facebook 驗證 2

通常通過 OAuth2 服務,需要用 Facebook 來註冊應用。一旦完成,就可以新建 Weblate 來使用了:

重定向 URL 為 https://WEBLATE SERVER/accounts/complete/facebook/

# Authentication configuration
AUTHENTICATION_BACKENDS = (
    "social_core.backends.facebook.FacebookOAuth2",
    "social_core.backends.email.EmailAuth",
    "weblate.accounts.auth.WeblateUserBackend",
)

# Social auth backends setup
SOCIAL_AUTH_FACEBOOK_KEY = "key"
SOCIAL_AUTH_FACEBOOK_SECRET = "secret"
SOCIAL_AUTH_FACEBOOK_SCOPE = ["email", "public_profile"]

備註

Weblate 在身份驗證時提供的回調 URL。在得到 URL 不匹配的錯誤時,可以根據需要來修復,請參見 設置正確的網站域名

也參考

Facebook

GitLab 驗證 2

為了使用 GitLab OAuth 2,需要在 <https://gitlab.com/profile/applications> 上註冊應用。

重定向 URL 為 https://WEBLATE SERVER/accounts/complete/gitlab/,並確保你標記 read_user 範圍。

# Authentication configuration
AUTHENTICATION_BACKENDS = (
    "social_core.backends.gitlab.GitLabOAuth2",
    "social_core.backends.email.EmailAuth",
    "weblate.accounts.auth.WeblateUserBackend",
)

# Social auth backends setup
SOCIAL_AUTH_GITLAB_KEY = "Application ID"
SOCIAL_AUTH_GITLAB_SECRET = "Secret"
SOCIAL_AUTH_GITLAB_SCOPE = ["read_user"]

# If you are using your own GitLab
# SOCIAL_AUTH_GITLAB_API_URL = 'https://gitlab.example.com/'

備註

Weblate 在身份驗證時提供的回調 URL。在得到 URL 不匹配的錯誤時,可以根據需要來修復,請參見 設置正確的網站域名

也參考

GitLab

微軟 Azure Active Directory

可以配置 Weblate,使用一般或特定租戶進行身份驗證。

常見的重定向URL 為``https://WEBLATE SERVER/accounts/complete/azuread-oauth2/ ``https://WEBLATE SERVER/accounts/complete/azuread-tenant-oauth2/ 用於租戶特定身份驗證。

# Azure AD common

# Authentication configuration
AUTHENTICATION_BACKENDS = (
    "social_core.backends.azuread.AzureADOAuth2",
    "social_core.backends.email.EmailAuth",
    "weblate.accounts.auth.WeblateUserBackend",
)

# OAuth2 keys
SOCIAL_AUTH_AZUREAD_OAUTH2_KEY = ""
SOCIAL_AUTH_AZUREAD_OAUTH2_SECRET = ""
# Azure AD Tenant

# Authentication configuration
AUTHENTICATION_BACKENDS = (
    "social_core.backends.azuread_tenant.AzureADTenantOAuth2",
    "social_core.backends.email.EmailAuth",
    "weblate.accounts.auth.WeblateUserBackend",
)

# OAuth2 keys
SOCIAL_AUTH_AZUREAD_TENANT_OAUTH2_KEY = ""
SOCIAL_AUTH_AZUREAD_TENANT_OAUTH2_SECRET = ""
# Tenant ID
SOCIAL_AUTH_AZUREAD_TENANT_OAUTH2_TENANT_ID = ""

備註

Weblate 在身份驗證時提供的回調 URL。在得到 URL 不匹配的錯誤時,可以根據需要來修復,請參見 設置正確的網站域名

Slack

為了使用 Slack OAuth 2,需要在 <https://api.slack.com/apps> 上註冊應用。

重定向 URL 為 https://WEBLATE SERVER/accounts/complete/slack/

# Authentication configuration
AUTHENTICATION_BACKENDS = (
    "social_core.backends.slack.SlackOAuth2",
    "social_core.backends.email.EmailAuth",
    "weblate.accounts.auth.WeblateUserBackend",
)

# Social auth backends setup
SOCIAL_AUTH_SLACK_KEY = ""
SOCIAL_AUTH_SLACK_SECRET = ""

備註

Weblate 在身份驗證時提供的回調 URL。在得到 URL 不匹配的錯誤時,可以根據需要來修復,請參見 設置正確的網站域名

也參考

Slack

Overriding authentication method names and icons

You can override the authentication method display name and icon using using settings as SOCIAL_AUTH_<NAME>_IMAGE and SOCIAL_AUTH_<NAME>_TITLE. For example overriding naming for Auth0 would look like:

SOCIAL_AUTH_AUTH0_IMAGE = "custom.svg"
SOCIAL_AUTH_AUTH0_TITLE = "Custom auth"

關閉密碼身份驗證

通過從 AUTHENTICATION_BACKENDS 刪除 social_core.backends.email.EmailAuth,可以關閉電子郵箱和密碼身份驗證。總是將 weblate.accounts.auth.WeblateUserBackend 保留在那裡,它用於 Weblate 核心功能。

Disabling e-mail authentication will disable all e-mail related functionality – user invitation or password reset feature.

小訣竅

You can still use password authentication for the admin interface, for users you manually create there. Just navigate to /admin/login/.

例如,使用後面的設置可以實現只是用 openSUSE Open ID 的身份驗證:

# Authentication configuration
AUTHENTICATION_BACKENDS = (
    "social_core.backends.suse.OpenSUSEOpenId",
    "weblate.accounts.auth.WeblateUserBackend",
)

密碼驗證

默認 settings.py 與一組合理的設置 AUTH_PASSWORD_VALIDATORS 在一起:

  • 密碼不能與其它個人信息太相似。

  • 密碼需只少10個字元。

  • 密碼不能是常見的密碼。

  • 密碼不能只含數字。

  • 密碼不能包括單個字符或只有空白字符。

  • 密碼與你過去使用的密碼不匹配。

可以自定義這個設置來匹配密碼政策。

可以另外安裝 django-zxcvbn-password 這會非常實際地估計密碼的難度,並允許拒絕低於下面適當閾值的密碼。

SAML 身份驗證

在 4.1.1 版本新加入.

请遵守 Python Social Auth 的指示来配置。显著的差异有:

  • Weblate 支持單一 IDP,在 SOCIAL_AUTH_SAML_ENABLED_IDPS 中被稱為 weblate

  • SAML XML 元數據 URL 為 /accounts/metadata/saml/

  • 後面的設置自動填入: SOCIAL_AUTH_SAML_SP_ENTITY_IDSOCIAL_AUTH_SAML_TECHNICAL_CONTACTSOCIAL_AUTH_SAML_SUPPORT_CONTACT

配置的例子:

# Authentication configuration
AUTHENTICATION_BACKENDS = (
    "social_core.backends.email.EmailAuth",
    "social_core.backends.saml.SAMLAuth",
    "weblate.accounts.auth.WeblateUserBackend",
)

# Social auth backends setup
SOCIAL_AUTH_SAML_SP_ENTITY_ID = f"https://{SITE_DOMAIN}/accounts/metadata/saml/"
SOCIAL_AUTH_SAML_SP_PUBLIC_CERT = "-----BEGIN CERTIFICATE-----"
SOCIAL_AUTH_SAML_SP_PRIVATE_KEY = "-----BEGIN PRIVATE KEY-----"
SOCIAL_AUTH_SAML_ENABLED_IDPS = {
    "weblate": {
        "entity_id": "https://idp.testshib.org/idp/shibboleth",
        "url": "https://idp.testshib.org/idp/profile/SAML2/Redirect/SSO",
        "x509cert": "MIIEDjCCAvagAwIBAgIBADA ... 8Bbnl+ev0peYzxFyF5sQA==",
        "attr_name": "full_name",
        "attr_username": "username",
        "attr_email": "email",
    }
}
SOCIAL_AUTH_SAML_ORG_INFO = {
    "en-US": {
        "name": "example",
        "displayname": "Example Inc.",
        "url": "http://example.com"
    }
}
SOCIAL_AUTH_SAML_TECHNICAL_CONTACT = {
    "givenName": "Tech Gal",
    "emailAddress": "technical@example.com"
}
SOCIAL_AUTH_SAML_SUPPORT_CONTACT = {
    "givenName": "Support Guy",
    "emailAddress": "support@example.com"
}

The default configuration extracts user details from following attributes, configure your IDP to provide them:

Attribute

SAML URI reference

全名

urn:oid:2.5.4.3

名字

urn:oid:2.5.4.42

Last name

urn:oid:2.5.4.4

電子郵件

urn:oid:0.9.2342.19200300.100.1.3

使用者名稱

urn:oid:0.9.2342.19200300.100.1.1

提示

The example above and the Docker image define an IDP called weblate. You might need to configure this string as Relay in your IDP.

也參考

:參考:“在Docker <docker-collect>`中配置收集,:doc:psa:beftends / collect

LDAP 身份驗證

LDAP 身份驗證可以使用 django-auth-ldap 軟件包而最好地實現。可以使用通常的方式安裝:

# Using PyPI
pip install django-auth-ldap>=1.3.0

# Using apt-get
apt-get install python-django-auth-ldap

提示

此包包含於 Docker 容器中,見 Installing using Docker

備註

在 Python LDAP 3.1.0 模塊中有一些不兼容,導致可能無法使用那個版本。如果得到錯誤信息`AttributeError: 『module』 object has no attribute 『_trace_level』 <https://github.com/python-ldap/python-ldap/issues/226>`_,將python-ldap 降回到3.0. 0 版可能會有幫助。

一旦安裝了軟件包,就可以將其鉤入 Django 身份驗證了:

# Add LDAP backed, keep Django one if you want to be able to sign in
# even without LDAP for admin account
AUTHENTICATION_BACKENDS = (
    "django_auth_ldap.backend.LDAPBackend",
    "weblate.accounts.auth.WeblateUserBackend",
)

# LDAP server address
AUTH_LDAP_SERVER_URI = "ldaps://ldap.example.net"

# DN to use for authentication
AUTH_LDAP_USER_DN_TEMPLATE = "cn=%(user)s,o=Example"
# Depending on your LDAP server, you might use a different DN
# like:
# AUTH_LDAP_USER_DN_TEMPLATE = 'ou=users,dc=example,dc=com'

# List of attributes to import from LDAP upon sign in
# Weblate stores full name of the user in the full_name attribute
AUTH_LDAP_USER_ATTR_MAP = {
    "full_name": "name",
    # Use the following if your LDAP server does not have full name
    # Weblate will merge them later
    # 'first_name': 'givenName',
    # 'last_name': 'sn',
    # Email is required for Weblate (used in VCS commits)
    "email": "mail",
}

# Hide the registration form
REGISTRATION_OPEN = False

備註

你應當從設置的:setting:django:AUTHENTICATION_BACKENDS`部分移除`』social_core.backends.email.EmailAuth』,否則用戶不能夠在Weblate中設置他們的密碼,並使用它進行身份驗證。為了生成權限和方便匿名用戶,仍需保留’weblate.accounts.auth.WeblateUserBackend』``。它還允許你使用一個本地管理帳戶登錄,如果你已經創建了它 (如,通過使用:djadmin:createadmin)。

Using bind password

如果可以為身份驗證使用直接綁定,那麼需要使用搜索,並為用戶搜索提供綁定,例如:

import ldap
from django_auth_ldap.config import LDAPSearch

AUTH_LDAP_BIND_DN = ""
AUTH_LDAP_BIND_PASSWORD = ""
AUTH_LDAP_USER_SEARCH = LDAPSearch(
    "ou=users,dc=example,dc=com", ldap.SCOPE_SUBTREE, "(uid=%(user)s)"
)

Active Directory integration

import ldap
from django_auth_ldap.config import LDAPSearch, NestedActiveDirectoryGroupType

AUTH_LDAP_BIND_DN = "CN=ldap,CN=Users,DC=example,DC=com"
AUTH_LDAP_BIND_PASSWORD = "password"

# User and group search objects and types
AUTH_LDAP_USER_SEARCH = LDAPSearch(
    "CN=Users,DC=example,DC=com", ldap.SCOPE_SUBTREE, "(sAMAccountName=%(user)s)"
)

# Make selected group a superuser in Weblate
AUTH_LDAP_USER_FLAGS_BY_GROUP = {
    # is_superuser means user has all permissions
    "is_superuser": "CN=weblate_AdminUsers,OU=Groups,DC=example,DC=com",
}

# Map groups from AD to Weblate
AUTH_LDAP_GROUP_SEARCH = LDAPSearch(
    "OU=Groups,DC=example,DC=com", ldap.SCOPE_SUBTREE, "(objectClass=group)"
)
AUTH_LDAP_GROUP_TYPE = NestedActiveDirectoryGroupType()
AUTH_LDAP_FIND_GROUP_PERMS = True

# Optionally enable group mirroring from LDAP to Weblate
# AUTH_LDAP_MIRROR_GROUPS = True

CAS 身份驗證

可以使用軟件包如 django-cas-ng 來實現 CAS 身份驗證。

第一步通過 CAS 揭示了用戶電子郵箱字段。這必須在 CAS 服務器自身來配置,並需要至少運行 CAS v2,因為 CAS v1 不支持屬性。

第二步更新 Weblate,來使用 CAS 服務器和屬性。

To install django-cas-ng:

pip install django-cas-ng

一旦安裝了軟件包,就可以通過修改 settings.py 文件將其鉤連到 Django 身份驗證系統:

# Add CAS backed, keep the Django one if you want to be able to sign in
# even without LDAP for the admin account
AUTHENTICATION_BACKENDS = (
    "django_cas_ng.backends.CASBackend",
    "weblate.accounts.auth.WeblateUserBackend",
)

# CAS server address
CAS_SERVER_URL = "https://cas.example.net/cas/"

# Add django_cas_ng somewhere in the list of INSTALLED_APPS
INSTALLED_APPS = (..., "django_cas_ng")

最後,可以使用信號將電子郵箱字段投射到用戶對像上。為了生效,必須將信號從 django-cas-ng 軟件包導入,並將你的代碼與這個信號連接。在設置文件中這樣做可能產生問題,這樣建議將它放進去:

from django_cas_ng.signals import cas_user_authenticated
from django.dispatch import receiver


@receiver(cas_user_authenticated)
def update_user_email_address(sender, user=None, attributes=None, **kwargs):
    # If your CAS server does not always include the email attribute
    # you can wrap the next two lines of code in a try/catch block.
    user.email = attributes["email"]
    user.save()

配置第三方 Django 身份驗證

一般地,任何 Django 身份認證插件應該可以在 Weblate 上工作。只需要按照插件的說明,只記住安裝了 Weblate 用戶後台。

典型的安裝包括,將身份驗證後台添加到 AUTHENTICATION_BACKENDS,並將身份驗證 app (如果有的話)安裝到 INSTALLED_APPS

AUTHENTICATION_BACKENDS = (
    # Add authentication backend here
    "weblate.accounts.auth.WeblateUserBackend",
)

INSTALLED_APPS += (
    # Install authentication app here
)