身份核對

使用者註冊

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無法將功勞歸於作出貢獻的使用者。

提示

大部分的後端授權需要 HTTPS。一旦啟用網頁服務上的 HTTPS,請設定 Weblate 環境參數 ENABLE_HTTPS 或 Docker 環境參數 WEBLATE_ENABLE_HTTPS

也參考

python seamial auth stend

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"]

The GitHub should be configured to have callback URL as https://WEBLATE SERVER/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://WEBLATE SERVER/accounts/complete/github-org/ and https://WEBLATE SERVER/accounts/complete/github-teams/.

備註

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

也參考

GitHub

GitHub EE authentication

You need to register an OAuth App on GitHub EE and then tell Weblate all its secrets:

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

# Social auth backends setup
SOCIAL_AUTH_GITHUB_ENTERPRISE_KEY = "GitHub OAuth App Client ID"
SOCIAL_AUTH_GITHUB_ENTERPRISE_SECRET = "GitHub OAuth App Client Secret"
SOCIAL_AUTH_GITHUB_ENTERPRISE_URL = "https://git.example.com/"
SOCIAL_AUTH_GITHUB_ENTERPRISE_API_URL = "https://git.example.com/api/v3/"
SOCIAL_AUTH_GITHUB_ENTERPRISE_SCOPE = ["user:email"]

The GitHub OAuth App should be configured to have callback URL as https://WEBLATE SERVER/accounts/complete/github-enterprise/.

Instead GitHub OAuth App, GitHub App can also be used. With GitHub App permissions can be granted on repositories, organisation and/or user level. If you decide to use GitHub App, you need to enable Access: Read-only permission for Users - <Email addresses> and Organisation - <Members>.

備註

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

也參考

GitHub Enterprise

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/ 用於租戶專屬的身份驗證。

You will need following:

  • Application (client) ID can be obtained from application page. Object ID is not used in Weblate.

  • Directory (tenant) ID is needed for tenant scoped authentication, what is usually desired.

  • Secret value is displayed once you generate a secret for an application. Secret ID is not used in Weblate.

# 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",
)

# Application (client) ID
SOCIAL_AUTH_AZUREAD_TENANT_OAUTH2_KEY = ""
# Secret value
SOCIAL_AUTH_AZUREAD_TENANT_OAUTH2_SECRET = ""
# Directory (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

您可以複寫認證方式的顯示名稱與圖示使用 SOCIAL_AUTH_<NAME>_IMAGESOCIAL_AUTH_<NAME>_TITLE 參數設定。例如複寫 Auth0 的名稱可以看起來像這樣:

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 身份驗證

Added in version 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"
}

預設的設定檔會萃取出使用者資訊透過以下的屬性值,請設定您的 IDP 來提估給他們:

屬性值

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

提示

在以上的範例中與被定義為 IDP 的 Docker 映像檔名為 weblate。您可能需要設定此字串為 Relay 在您的 IDP 中。

也參考

:ref:“在Docker <docker-collect>`中組態收集,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 容器中,見 使用 Docker 安裝

備註

在 Python LDAP 3.1.0 模組中有一些不相容,導致可能無法使用那個版本。如果得到錯誤資訊 AttributeError: 『module』 object has no attribute 『_trace_level』,將 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

備註

You should remove 'social_core.backends.email.EmailAuth' from the AUTHENTICATION_BACKENDS setting, otherwise users will be able to set their password in Weblate, and authenticate using that. Keeping 'weblate.accounts.auth.WeblateUserBackend' is still needed in order to make permissions and facilitate anonymous users. It will also allow you to sign in using a local admin account, if you have created it (e.g. by using createadmin).

使用 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 伺服器和屬性。

安裝 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
)