gitlab-org--gitlab-foss/doc/integration/google.md

110 lines
3.8 KiB
Markdown
Raw Normal View History

# Google OAuth2 OmniAuth Provider
2017-10-05 12:15:12 -04:00
To enable the Google OAuth2 OmniAuth provider you must register your application
with Google. Google will generate a client ID and secret key for you to use.
## Enabling Google OAuth
In Google's side:
1. Navigate to the [cloud resource manager](https://console.cloud.google.com/cloud-resource-manager) page
2017-10-06 08:41:43 -04:00
1. Select **Create Project**
2017-10-05 12:15:12 -04:00
1. Provide the project information:
- **Project name** - "GitLab" works just fine here.
- **Project ID** - Must be unique to all Google Developer registered applications.
Google provides a randomly generated Project ID by default. You can use
the randomly generated ID or choose a new one.
1. Refresh the page and you should see your new project in the list
1. Go to the [Google API Console](https://console.developers.google.com/apis/dashboard)
1. Select the previously created project form the upper left corner
2017-10-06 08:41:43 -04:00
1. Select **Credentials** from the sidebar
1. Select **OAuth consent screen** and fill the form with the required information
1. In the **Credentials** tab, select **Create credentials > OAuth client ID**
2017-10-05 12:15:12 -04:00
1. Fill in the required information
- **Application type** - Choose "Web Application"
2017-10-06 08:41:43 -04:00
- **Name** - Use the default one or provide your own
2017-10-05 12:15:12 -04:00
- **Authorized JavaScript origins** -This isn't really used by GitLab but go
ahead and put `https://gitlab.example.com`
- **Authorized redirect URIs** - Enter your domain name followed by the
2017-10-06 08:41:43 -04:00
callback URIs one at a time:
2017-10-05 12:15:12 -04:00
```
https://gitlab.example.com/users/auth/google_oauth2/callback
https://gitlab.exampl.com/-/google_api/auth/callback
2017-10-05 12:15:12 -04:00
```
2014-04-24 18:48:22 -04:00
2017-10-06 08:41:43 -04:00
1. You should now be able to see a Client ID and Client secret. Note them down
or keep this page open as you will need them later.
1. From the **Dashboard** select **ENABLE APIS AND SERVICES > Google Cloud APIs > Container Engine API > Enable**
2014-04-24 18:48:22 -04:00
2017-10-05 12:15:12 -04:00
On your GitLab server:
2014-04-24 18:48:22 -04:00
2017-10-05 12:15:12 -04:00
1. Open the configuration file.
2017-10-05 12:15:12 -04:00
For Omnibus GitLab:
```sh
2017-10-05 12:15:12 -04:00
sudo editor /etc/gitlab/gitlab.rb
```
2015-12-07 04:28:47 -05:00
For installations from source:
2014-04-24 18:48:22 -04:00
```sh
2017-10-05 12:15:12 -04:00
cd /home/git/gitlab
sudo -u git -H editor config/gitlab.yml
```
2014-04-24 18:48:22 -04:00
2017-10-05 12:15:12 -04:00
1. See [Initial OmniAuth Configuration](omniauth.md#initial-omniauth-configuration) for initial settings.
1. Add the provider configuration:
2017-10-05 12:15:12 -04:00
For Omnibus GitLab:
```ruby
2017-10-05 12:15:12 -04:00
gitlab_rails['omniauth_providers'] = [
{
"name" => "google_oauth2",
"app_id" => "YOUR_APP_ID",
"app_secret" => "YOUR_APP_SECRET",
"args" => { "access_type" => "offline", "approval_prompt" => '' }
}
]
```
2014-04-24 18:48:22 -04:00
For installations from source:
```
2017-10-05 12:15:12 -04:00
- { name: 'google_oauth2', app_id: 'YOUR_APP_ID',
app_secret: 'YOUR_APP_SECRET',
args: { access_type: 'offline', approval_prompt: '' } }
```
2017-10-05 12:15:12 -04:00
1. Change `YOUR_APP_ID` to the client ID from the Google Developer page
1. Similarly, change `YOUR_APP_SECRET` to the client secret
1. Make sure that you configure GitLab to use an FQDN as Google will not accept
raw IP addresses.
2017-06-08 07:51:44 -04:00
For Omnibus packages:
```ruby
2017-10-05 12:15:12 -04:00
external_url 'https://gitlab.example.com'
2017-06-08 07:51:44 -04:00
```
For installations from source:
```yaml
gitlab:
host: https://gitlab.example.com
```
2014-04-24 18:48:22 -04:00
1. Save the configuration file.
1. [Reconfigure][] or [restart GitLab][] for the changes to take effect if you
installed GitLab via Omnibus or from source respectively.
2017-10-05 12:15:12 -04:00
On the sign in page there should now be a Google icon below the regular sign in
form. Click the icon to begin the authentication process. Google will ask the
user to sign in and authorize the GitLab application. If everything goes well
the user will be returned to GitLab and will be signed in.
[reconfigure]: ../administration/restart_gitlab.md#omnibus-gitlab-reconfigure
[restart GitLab]: ../administration/restart_gitlab.md#installations-from-source