使用者註冊 #

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 不匹配的錯誤時,可以根據需要來修復,請參見 設置正確的網站域名

    Microsoft Azure Active Directory

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

    请遵守 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

    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 weblate 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
    

    Django Authentication Using LDAP, Authentication

    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 軟件包導入,並將您的代碼與這個信號連接。在設置文件中這樣做可能產生問題,這樣建議將它放進去:

  • 在您的 app 配置的 django.apps.AppConfig.ready() 方法

  • 在專案的 urls.py 檔案中(當沒有模組存在時)

  • 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 CAS NG <https://github.com/django-cas-ng/django-cas-ng>`_`Django CAS NG

    配置第三方 Django 身份驗證#

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

    LDAP 身份驗證, CAS 身份驗證

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

    AUTHENTICATION_BACKENDS = (
        # Add authentication backend here
        "weblate.accounts.auth.WeblateUserBackend",
    INSTALLED_APPS += (
        # Install authentication app here