2021-01-29 00:20:46 +05:30
---
2021-10-27 15:23:28 +05:30
stage: Ecosystem
group: Integrations
2021-02-22 17:27:13 +05:30
info: To determine the technical writer assigned to the Stage/Group associated with this page, see https://about.gitlab.com/handbook/engineering/ux/technical-writing/#assignments
2021-01-29 00:20:46 +05:30
---
2022-01-26 12:08:38 +05:30
# Generic OAuth2 provider **(FREE SELF)**
2017-08-17 22:00:37 +05:30
2022-01-26 12:08:38 +05:30
The `omniauth-oauth2-generic` gem allows single sign-on (SSO) between GitLab
and your OAuth2 provider (or any OAuth2 provider compatible with this gem).
2017-08-17 22:00:37 +05:30
2022-01-26 12:08:38 +05:30
This strategy allows for the configuration of this OmniAuth SSO process:
2017-08-17 22:00:37 +05:30
2022-01-26 12:08:38 +05:30
1. Strategy directs the client to your authorization URL (**configurable**), with
the specified ID and key.
1. The OAuth2 provider handles authentication of the request, user, and (optionally)
authorization to access user's profile.
1. The OAuth2 provider directs the client back to GitLab where Strategy handles
the retrieval of the access token.
1. Strategy requests user information from a **configurable** "user profile"
URL (using the access token).
1. Strategy parses user information from the response, using a **configurable**
format.
1. GitLab finds or creates the returned user and signs them in.
2017-08-17 22:00:37 +05:30
2022-01-26 12:08:38 +05:30
## Limitations of this strategy
2017-08-17 22:00:37 +05:30
2022-01-26 12:08:38 +05:30
- It can only be used for single sign-on, and doesn't provide any other access
granted by any OAuth2 provider (like importing projects or users).
- It supports only the Authorization Grant flow (most common for client-server
applications, like GitLab).
- It can't fetch user information from more than one URL.
- It hasn't been tested with user information formats, other than JSON.
2017-08-17 22:00:37 +05:30
2022-01-26 12:08:38 +05:30
## Configure the OAuth2 provider
2017-08-17 22:00:37 +05:30
2022-01-26 12:08:38 +05:30
To configure the provider:
1. Register your application in the OAuth2 provider you want to authenticate with.
2017-08-17 22:00:37 +05:30
2019-09-30 21:07:59 +05:30
The redirect URI you provide when registering the application should be:
2017-08-17 22:00:37 +05:30
2020-04-22 19:07:51 +05:30
```plaintext
2019-09-30 21:07:59 +05:30
http://your-gitlab.host.com/users/auth/oauth2_generic/callback
```
2017-08-17 22:00:37 +05:30
2022-01-26 12:08:38 +05:30
You should now be able to get a Client ID and Client Secret. Where this
appears differs for each provider. This may also be called Application ID
and Secret.
2017-08-17 22:00:37 +05:30
2022-01-26 12:08:38 +05:30
1. On your GitLab server, open the appropriate configuration file.
2017-08-17 22:00:37 +05:30
2022-01-26 12:08:38 +05:30
For Omnibus GitLab:
2017-08-17 22:00:37 +05:30
2020-03-13 15:44:24 +05:30
```shell
2019-09-30 21:07:59 +05:30
sudo editor /etc/gitlab/gitlab.rb
```
2017-08-17 22:00:37 +05:30
2019-09-30 21:07:59 +05:30
For installations from source:
2017-08-17 22:00:37 +05:30
2020-03-13 15:44:24 +05:30
```shell
2019-09-30 21:07:59 +05:30
cd /home/git/gitlab
sudo -u git -H editor config/gitlab.yml
```
2017-08-17 22:00:37 +05:30
2022-01-26 12:08:38 +05:30
1. See [Configure initial settings ](omniauth.md#configure-initial-settings ) for
initial settings.
2021-12-11 22:18:48 +05:30
2022-01-26 12:08:38 +05:30
1. Add the provider-specific configuration for your provider. For example:
2021-12-11 22:18:48 +05:30
```ruby
gitlab_rails['omniauth_providers'] = [
2022-01-26 12:08:38 +05:30
{
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-12-11 22:18:48 +05:30
client_options: {
2022-01-26 12:08:38 +05:30
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-12-11 22:18:48 +05:30
}
}
]
```
2017-08-17 22:00:37 +05:30
2021-12-11 22:18:48 +05:30
For more information about these settings, see [the gem's README ](https://gitlab.com/satorix/omniauth-oauth2-generic#gitlab-config-example ).
2017-08-17 22:00:37 +05:30
2022-01-26 12:08:38 +05:30
1. Save the configuration file.
2017-08-17 22:00:37 +05:30
2022-01-26 12:08:38 +05:30
1. [Restart ](../administration/restart_gitlab.md#installations-from-source )
GitLab for the changes to take effect.
2017-08-17 22:00:37 +05:30
2022-01-26 12:08:38 +05:30
On the sign-in page there should now be a new button below the regular sign-in
form. Select the button to begin your provider's authentication process. This
directs the browser to your OAuth2 provider's authentication page. If
everything goes well, you are returned to your GitLab instance and are
signed in.