LoginSignup
0
1

More than 3 years have passed since last update.

【GitLab】Google OAuth2 OmniAuth Providerを使ってアカウント管理を楽にする

Last updated at Posted at 2020-05-03

社内でGsuiteを使っている環境でGitLabを立てたが、アカウント管理が面倒なので、
Google Oauth2を使って楽に管理することにした。

参考:
https://docs.gitlab.com/ee/integration/google.html

Google Api側の設定

プロジェクト作成
https://console.developers.google.com/apis/

新しいプロジェクトよりOAuth-Web-credentialsを作成
806a6ae7-5b33-44d1-a1e1-d84e469ad7c6.png

認証情報を作成

認証情報を作成 > OauthクライアントIDを選択
dc10a2a3-f43f-4143-a2e6-4b4dd16e3823.png

ウェブアプリケーションを選択して作成
5dbd1101-b132-4ad1-9477-eff4ff1173e9.png

認証情報を以下のように設定
名前:GitLabCE

承認済みの JavaScript 生成元
URI:
https://gitlab.hoge.net

承認済みのリダイレクト URI
URI:
https://gitlab.hoge.net/users/auth/google_oauth2/callback
https://gitlab.hoge.net/-/google_api/auth/callback

d67cb99c-03d9-41a9-bdfe-78bf66ba8522.png

発行されるクライアントIDとクライアントシークレットは控えておく。

OAuth同意画面

組織内で利用するため内部を選択する

3c616027-3979-436f-b988-49226664bffd.png

GitLab側の設定

/etc/gitlab/gitlab.rbよりOminiAuthを有効にする。

### OmniAuth Settings
###! Docs: https://docs.gitlab.com/ee/integration/omniauth.html
gitlab_rails['omniauth_enabled'] = true
gitlab_rails['omniauth_allow_single_sign_on'] = ['google_oauth2']
gitlab_rails['omniauth_external_providers'] = ['google_oauth2']
#  trueはブロック
gitlab_rails['omniauth_block_auto_created_users'] = false
# gitlab_rails['omniauth_sync_email_from_provider'] = 'saml'
# gitlab_rails['omniauth_sync_profile_from_provider'] = ['saml']
# gitlab_rails['omniauth_sync_profile_attributes'] = ['email']
# gitlab_rails['omniauth_auto_sign_in_with_provider'] = 'saml'
# gitlab_rails['omniauth_block_auto_created_users'] = true
# gitlab_rails['omniauth_auto_link_ldap_user'] = false
# gitlab_rails['omniauth_auto_link_saml_user'] = false
# gitlab_rails['omniauth_allow_bypass_two_factor'] = ['google_oauth2']

gitlab_rails['omniauth_providers'] = [
  {
    "name" => "google_oauth2",
    "app_id" => "XXXXXXXXXXXXXXXXXXXXXXXXXXX.apps.googleusercontent.com",
    "app_secret" => "XXXXXXXXXXXXXXXXXXXXXXXXXXX",
    "args" => { "access_type" => "offline", "approval_prompt" => "" }
  }
]

設定を有効にする

$ gitlab-ctl reconfigure

ログイン画面に以下が表示され、Gsuiteのログイン画面にリダイレクトされたらOK
2ee1d588-1286-444d-99a1-f33465b5bb99.png

0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1