2020-10-29 11:09:12 -04:00
---
2022-05-12 23:08:13 -04:00
stage: Manage
group: Authentication and Authorization
2022-09-21 17:13:33 -04:00
info: To determine the technical writer assigned to the Stage/Group associated with this page, see https://about.gitlab.com/handbook/product/ux/technical-writing/#assignments
2020-10-29 11:09:12 -04:00
---
2022-09-29 14:08:16 -04:00
# Generic OAuth 2.0 provider **(FREE SELF)**
2017-02-07 15:43:08 -05:00
2021-12-14 07:13:33 -05:00
The `omniauth-oauth2-generic` gem allows single sign-on (SSO) between GitLab
2022-09-29 14:08:16 -04:00
and your OAuth 2.0 provider, or any OAuth 2.0 provider compatible with this gem).
2017-02-07 15:43:08 -05:00
2021-12-14 07:13:33 -05:00
This strategy allows for the configuration of this OmniAuth SSO process:
2017-02-07 15:43:08 -05:00
2021-12-14 07:13:33 -05:00
1. Strategy directs the client to your authorization URL (**configurable**), with
the specified ID and key.
2022-09-29 14:08:16 -04:00
1. The OAuth 2.0 provider handles authentication of the request, user, and (optionally)
authorization to access the user's profile.
1. The OAuth 2.0 provider directs the client back to GitLab where Strategy
retrieves the access token.
2021-12-14 07:13:33 -05:00
1. Strategy requests user information from a **configurable** "user profile"
2022-09-29 14:08:16 -04:00
URL using the access token.
1. Strategy parses user information from the response using a **configurable**
2021-12-14 07:13:33 -05:00
format.
1. GitLab finds or creates the returned user and signs them in.
2017-02-07 15:43:08 -05:00
2022-09-29 14:08:16 -04:00
This strategy:
2017-02-07 15:43:08 -05:00
2022-09-29 14:08:16 -04:00
- Can only be used for single sign-on, and does not provide any other access
granted by any OAuth 2.0 provider. For example, importing projects or users.
- Only supports the Authorization Grant flow, which is most common for client-server
applications like GitLab.
- Cannot fetch user information from more than one URL.
- Has not been tested with user information formats, except JSON.
2017-02-07 15:43:08 -05:00
2022-09-29 14:08:16 -04:00
## Configure the OAuth 2.0 provider
2017-02-13 10:57:36 -05:00
2021-12-14 07:13:33 -05:00
To configure the provider:
2022-09-29 14:08:16 -04:00
1. Register your application in the OAuth 2.0 provider you want to authenticate with.
2017-02-07 15:43:08 -05:00
2019-07-11 11:21:26 -04:00
The redirect URI you provide when registering the application should be:
2017-02-07 15:43:08 -05:00
2020-03-25 02:07:58 -04:00
```plaintext
2019-07-11 11:21:26 -04:00
http://your-gitlab.host.com/users/auth/oauth2_generic/callback
```
2017-02-07 15:43:08 -05:00
2022-09-29 14:08:16 -04:00
You should now be able to get a client ID and client secret. Where these
appear is different for each provider. This may also be called application ID
and application secret.
2017-02-07 15:43:08 -05:00
2021-12-14 07:13:33 -05:00
1. On your GitLab server, open the appropriate configuration file.
2017-02-07 15:43:08 -05:00
2021-12-14 07:13:33 -05:00
For Omnibus GitLab:
2017-02-07 15:43:08 -05:00
2020-01-30 10:09:15 -05:00
```shell
2019-07-11 11:21:26 -04:00
sudo editor /etc/gitlab/gitlab.rb
```
2017-02-07 15:43:08 -05:00
2019-07-11 11:21:26 -04:00
For installations from source:
2017-02-07 15:43:08 -05:00
2020-01-30 10:09:15 -05:00
```shell
2019-07-11 11:21:26 -04:00
cd /home/git/gitlab
sudo -u git -H editor config/gitlab.yml
```
2017-02-07 15:43:08 -05:00
2021-12-14 07:13:33 -05:00
1. See [Configure initial settings ](omniauth.md#configure-initial-settings ) for
initial settings.
2017-02-07 15:43:08 -05:00
2021-12-14 07:13:33 -05:00
1. Add the provider-specific configuration for your provider. For example:
2021-11-12 04:10:03 -05:00
```ruby
gitlab_rails['omniauth_providers'] = [
2021-11-19 04:13:48 -05:00
{
name: "oauth2_generic",
label: "Provider name", # optional label for login button, defaults to "Oauth2 Generic"
app_id: "< your_app_client_id > ",
app_secret: "< your_app_client_secret > ",
args: {
2021-11-12 04:10:03 -05:00
client_options: {
2021-11-19 04:13:48 -05:00
site: "< your_auth_server_url > ",
user_info_url: "/oauth2/v1/userinfo",
authorize_url: "/oauth2/v1/authorize",
token_url: "/oauth2/v1/token"
},
user_response_structure: {
root_path: [],
id_path: ["sub"],
attributes: {
email: "email",
name: "name"
}
},
authorize_params: {
scope: "openid profile email"
},
strategy_class: "OmniAuth::Strategies::OAuth2Generic"
2021-11-12 04:10:03 -05:00
}
}
]
```
2022-09-29 14:08:16 -04:00
For more information about these settings, see the [gem's README ](https://gitlab.com/satorix/omniauth-oauth2-generic#gitlab-config-example ).
2017-02-07 15:43:08 -05:00
2021-12-14 07:13:33 -05:00
1. Save the configuration file.
2017-02-07 15:43:08 -05:00
2022-09-29 14:08:16 -04:00
1. For the changes to take effect, [restart GitLab ](../administration/restart_gitlab.md#installations-from-source ).
2017-02-07 15:43:08 -05:00
2022-09-29 14:08:16 -04:00
On the sign-in page there should now be a new icon below the regular sign-in
form. Select that icon to begin your provider's authentication process. This
directs the browser to your OAuth 2.0 provider's authentication page. If
everything goes well, you are returned to your GitLab instance and
2021-12-14 07:13:33 -05:00
signed in.