Google

自託管 gitlab 使用 Google 帳戶註冊

  • December 7, 2018

我正在設置一個 GitLab EE 實例,我想僅使用 Google 帳戶啟用註冊過程。我在這裡遵循了文件:https ://docs.gitlab.com/ce/integration/google.html和這裡:https ://docs.gitlab.com/ce/integration/omniauth.html 。

當我嘗試將現有帳戶綁定到 Google 時,與 Google 的集成工作正常,它完美無缺。

問題是,當我嘗試在沒有現有帳戶的情況下使用 Google 註冊時,會引發錯誤:

不允許在沒有預先存在的 GitLab 帳戶的情況下使用您的 Google 帳戶登錄。

我目前的/etc/gitlab/gitlab.rb配置如下:

### OmniAuth Settings
###! Docs: https://docs.gitlab.com/ce/integration/omniauth.html
gitlab_rails['omniauth_enabled'] = true
gitlab_rails['omniauth_allow_single_sign_on'] = ['google_oauth2']
gitlab_rails['omniauth_sync_email_from_provider'] = 'google_oauth2'
gitlab_rails['omniauth_sync_profile_from_provider'] = ['google_oauth2']
gitlab_rails['omniauth_sync_profile_attributes'] = ['email', 'name', 'location']
gitlab_rails['omniauth_auto_sign_in_with_provider'] = 'google_oauth2'
gitlab_rails['omniauth_block_auto_created_users'] = false
# gitlab_rails['omniauth_auto_link_ldap_user'] = false
# gitlab_rails['omniauth_auto_link_saml_user'] = false
# gitlab_rails['omniauth_external_providers'] = ['google_oauth2']
gitlab_rails['omniauth_providers'] = [
  {
    "name" => "google_oauth2",
    "app_id" => "my-app-id",
    "app_secret" => "my-app-secret",
    "args" => { "access_type" => "offline", "approval_prompt" => "" }
  }
]

我究竟做錯了什麼?GitLab 甚至可以使用 Google 註冊嗎?

在對配置進行了一些調整後,我設法找到了一個可行的設置:

### OmniAuth Settings
###! Docs: https://docs.gitlab.com/ce/integration/omniauth.html
gitlab_rails['omniauth_enabled'] = true
gitlab_rails['omniauth_allow_single_sign_on'] = ['google_oauth2']
# gitlab_rails['omniauth_sync_email_from_provider'] = 'google_oauth2'
gitlab_rails['omniauth_sync_profile_from_provider'] = ['google_oauth2']
# gitlab_rails['omniauth_sync_profile_attributes'] = ['email']
# gitlab_rails['omniauth_auto_sign_in_with_provider'] = 'google_oauth2'
gitlab_rails['omniauth_block_auto_created_users'] = false
gitlab_rails['omniauth_auto_link_ldap_user'] = true
# gitlab_rails['omniauth_auto_link_saml_user'] = false
# gitlab_rails['omniauth_external_providers'] = ['google_oauth2']
gitlab_rails['omniauth_providers'] = [
  {
    "name" => "google_oauth2",
    "app_id" => "<APP_ID>",
    "app_secret" => "<APP_SECRET>",
    "args" => { "access_type" => "offline", "approval_prompt" => "" }
  }
]

引用自:https://serverfault.com/questions/903552