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
---
2021-11-18 22:05:49 +05:30
# Microsoft Azure OAuth 2.0 OmniAuth Provider **(FREE SELF)**
2016-01-14 18:37:52 +05:30
2021-03-11 19:13:27 +05:30
NOTE:
Per Microsoft, this provider uses the [older Azure Active Directory v1.0 endpoint ](https://docs.microsoft.com/en-us/azure/active-directory/azuread-dev/v1-protocols-oauth-code ).
Microsoft documentation suggests that you should use the [OpenID Connect protocol to use the v2 endpoints ](../administration/auth/oidc.md#microsoft-azure ) for new projects.
2021-11-11 11:23:49 +05:30
To use v2 endpoints via OmniAuth, please follow [Microsoft Azure OAuth 2.0 OmniAuth Provider v2 instructions ](#microsoft-azure-oauth-20-omniauth-provider-v2 ).
2021-03-11 19:13:27 +05:30
2021-11-11 11:23:49 +05:30
To enable the Microsoft Azure OAuth 2.0 OmniAuth provider, you must register
your application with Azure. Azure generates a client ID and secret key for you
to use.
2016-01-14 18:37:52 +05:30
2021-11-11 11:23:49 +05:30
Sign in to the [Azure Portal ](https://portal.azure.com ), and follow the
instructions in the [Microsoft Quickstart documentation ](https://docs.microsoft.com/en-us/azure/active-directory/develop/quickstart-register-app ).
2016-01-14 18:37:52 +05:30
2020-06-23 00:09:42 +05:30
As you go through the Microsoft procedure, keep the following in mind:
2016-01-14 18:37:52 +05:30
2020-06-23 00:09:42 +05:30
- If you have multiple instances of Azure Active Directory, you can switch to the desired tenant.
- You're setting up a Web application.
2021-01-29 00:20:46 +05:30
- The redirect URI requires the URL of the Azure OAuth callback of your GitLab
installation. For example, `https://gitlab.mycompany.com/users/auth/azure_oauth2/callback` .
The type dropdown should be set to **Web** .
2021-11-11 11:23:49 +05:30
- The `client ID` and `client secret` are terms associated with OAuth 2.0. In some Microsoft documentation,
2020-06-23 00:09:42 +05:30
the terms may be listed as `Application ID` and `Application Secret` .
2021-11-11 11:23:49 +05:30
- If you have to generate a new client secret, follow the Microsoft documentation
2021-01-29 00:20:46 +05:30
for [creating a new application secret ](https://docs.microsoft.com/en-us/azure/active-directory/develop/howto-create-service-principal-portal#create-a-new-application-secret ).
- Save the client ID and client secret for your new app, as the client secret is only
displayed one time.
2016-01-14 18:37:52 +05:30
2019-09-30 21:07:59 +05:30
1. On your GitLab server, open the configuration file.
2016-01-14 18:37:52 +05:30
2021-01-29 00:20:46 +05:30
For Omnibus GitLab:
2016-01-14 18:37:52 +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
```
2016-01-14 18:37:52 +05:30
2019-09-30 21:07:59 +05:30
For installations from source:
2016-01-14 18:37:52 +05:30
2020-03-13 15:44:24 +05:30
```shell
2019-09-30 21:07:59 +05:30
cd /home/git/gitlab
2016-01-14 18:37:52 +05:30
2019-09-30 21:07:59 +05:30
sudo -u git -H editor config/gitlab.yml
```
2016-01-14 18:37:52 +05:30
2021-12-11 22:18:48 +05:30
1. Refer to [Configure initial settings ](omniauth.md#configure-initial-settings )
2021-01-29 00:20:46 +05:30
for initial settings.
2016-01-14 18:37:52 +05:30
2019-09-30 21:07:59 +05:30
1. Add the provider configuration:
2016-01-14 18:37:52 +05:30
2021-01-29 00:20:46 +05:30
For Omnibus GitLab:
2016-01-14 18:37:52 +05:30
2019-09-30 21:07:59 +05:30
```ruby
gitlab_rails['omniauth_providers'] = [
{
"name" => "azure_oauth2",
"args" => {
"client_id" => "CLIENT ID",
"client_secret" => "CLIENT SECRET",
"tenant_id" => "TENANT ID",
}
}
]
```
2016-01-14 18:37:52 +05:30
2019-09-30 21:07:59 +05:30
For installations from source:
2016-01-14 18:37:52 +05:30
2020-04-22 19:07:51 +05:30
```yaml
2019-09-30 21:07:59 +05:30
- { name: 'azure_oauth2',
args: { client_id: "CLIENT ID",
client_secret: "CLIENT SECRET",
tenant_id: "TENANT ID" } }
```
2016-01-14 18:37:52 +05:30
2019-09-30 21:07:59 +05:30
The `base_azure_url` is optional and can be added for different locales;
2021-01-29 00:20:46 +05:30
such as `base_azure_url: "https://login.microsoftonline.de"` .
2018-03-17 18:26:18 +05:30
2021-01-29 00:20:46 +05:30
1. Replace `CLIENT ID` , `CLIENT SECRET` and `TENANT ID` with the values you got above.
2016-01-14 18:37:52 +05:30
2019-09-30 21:07:59 +05:30
1. Save the configuration file.
2016-01-14 18:37:52 +05:30
2021-01-29 00:20:46 +05:30
1. Reconfigure or restart GitLab, depending on your installation method:
- *If you installed from Omnibus GitLab,*
[reconfigure ](../administration/restart_gitlab.md#omnibus-gitlab-reconfigure ) GitLab.
- *If you installed from source,*
[restart GitLab ](../administration/restart_gitlab.md#installations-from-source ).
2021-11-11 11:23:49 +05:30
On the sign-in page, you should now see a Microsoft icon below the regular
sign-in form. Click the icon to begin the authentication process. Microsoft then
asks you to sign in and authorize the GitLab application. If successful, you are
returned to GitLab and signed in.
2016-01-14 18:37:52 +05:30
2021-01-29 00:20:46 +05:30
Read [Enable OmniAuth for an Existing User ](omniauth.md#enable-omniauth-for-an-existing-user )
2020-06-23 00:09:42 +05:30
for information on how existing GitLab users can connect to their newly-available Azure AD accounts.
2021-04-17 20:07:23 +05:30
2021-11-11 11:23:49 +05:30
## Microsoft Azure OAuth 2.0 OmniAuth Provider v2
2021-04-17 20:07:23 +05:30
2021-11-11 11:23:49 +05:30
To use v2 endpoints provided by Microsoft Azure Active Directory you must to
configure it via Azure OAuth 2.0 OmniAuth Provider v2.
2021-04-17 20:07:23 +05:30
### Registering an Azure application
2021-11-11 11:23:49 +05:30
To enable the Microsoft Azure OAuth 2.0 OmniAuth provider, you must register
your application with Azure. Azure generates a client ID and secret key for you
to use.
2021-04-17 20:07:23 +05:30
2021-11-11 11:23:49 +05:30
Sign in to the [Azure Portal ](https://portal.azure.com ), and follow the
instructions in the [Microsoft Quickstart documentation ](https://docs.microsoft.com/en-us/azure/active-directory/develop/quickstart-register-app ).
2021-04-17 20:07:23 +05:30
As you go through the Microsoft procedure, keep the following in mind:
2021-11-11 11:23:49 +05:30
- If you have multiple instances of Azure Active Directory, you can switch to
the desired tenant.
2021-04-17 20:07:23 +05:30
- You're setting up a Web application.
- The redirect URI requires the URL of the Azure OAuth callback of your GitLab
installation. For example, `https://gitlab.example.com/users/auth/azure_activedirectory_v2/callback` .
The type dropdown should be set to **Web** .
2021-11-11 11:23:49 +05:30
- The `client ID` and `client secret` are terms associated with OAuth 2.0. In some Microsoft documentation,
2021-04-17 20:07:23 +05:30
the terms may be listed as `Application ID` and `Application Secret` .
2021-11-11 11:23:49 +05:30
- If you have to generate a new client secret, follow the Microsoft documentation
2021-04-17 20:07:23 +05:30
for [creating a new application secret ](https://docs.microsoft.com/en-us/azure/active-directory/develop/howto-create-service-principal-portal#create-a-new-application-secret ).
- Save the client ID and client secret for your new app, as the client secret is only
displayed one time.
### Adding API permissions (scopes)
2021-11-11 11:23:49 +05:30
After you have created an application, follow the [Microsoft Quickstart documentation to expose a web API ](https://docs.microsoft.com/en-us/azure/active-directory/develop/quickstart-configure-app-expose-web-apis ). Be sure to add the following delegated permissions under the Microsoft Graph API:
2021-04-17 20:07:23 +05:30
- `email`
- `openid`
- `profile`
2021-12-11 22:18:48 +05:30
Alternatively, add the `User.Read.All` application permission.
2021-04-17 20:07:23 +05:30
### Configuring GitLab
1. On your GitLab server, open the configuration file.
For Omnibus GitLab:
```shell
sudo editor /etc/gitlab/gitlab.rb
```
For installations from source:
```shell
cd /home/git/gitlab
sudo -u git -H editor config/gitlab.yml
```
2021-12-11 22:18:48 +05:30
1. Refer to [Configure initial settings ](omniauth.md#configure-initial-settings )
2021-04-17 20:07:23 +05:30
for initial settings.
1. Add the provider configuration:
For Omnibus GitLab:
```ruby
gitlab_rails['omniauth_providers'] = [
{
"name" => "azure_activedirectory_v2",
"args" => {
"client_id" => "CLIENT ID",
"client_secret" => "CLIENT SECRET",
"tenant_id" => "TENANT ID",
}
}
]
```
For installations from source:
```yaml
- { name: 'azure_activedirectory_v2',
args: { client_id: "CLIENT ID",
client_secret: "CLIENT SECRET",
tenant_id: "TENANT ID" } }
```
The `base_azure_url` is optional and can be added for different locales;
such as `base_azure_url: "https://login.microsoftonline.de"` .
The `scope` parameter is optional and can be added to `args` . Default `scope` is: `openid profile email` .
2021-11-11 11:23:49 +05:30
1. Replace `CLIENT ID` , `CLIENT SECRET` , and `TENANT ID` with the values you got
above.
2021-04-17 20:07:23 +05:30
1. Save the configuration file.
1. Reconfigure or restart GitLab, depending on your installation method:
- *If you installed from Omnibus GitLab,*
[reconfigure ](../administration/restart_gitlab.md#omnibus-gitlab-reconfigure ) GitLab.
- *If you installed from source,*
[restart GitLab ](../administration/restart_gitlab.md#installations-from-source ).
On the sign-in page, you should now see a Microsoft icon below the regular sign-in form.
Select the icon to begin the authentication process. Microsoft then asks you to
sign in and authorize the GitLab application. If successful, you are returned to GitLab and signed in.
Read [Enable OmniAuth for an Existing User ](omniauth.md#enable-omniauth-for-an-existing-user )
for information on how existing GitLab users can connect to their newly available Azure AD accounts.