{"revision":"c10276e953456835cdbb1f3a60d58ae1980be353","document":{"id":32226,"path":"it-service-management/devops-change-velocity/setting-up-gitlab-oauth.md","title":"Setting up GitLab OAuth 2.0 credentials for DevOps","bundle":null,"doc_type":null,"release":"australia","body":"\n# Setting up GitLab OAuth 2.0 credentials for DevOps\n\nIntegrate your GitLab account with your ServiceNow instance by creating a custom OAuth application in GitLab and authenticating requests from ServiceNow DevOps.\n\nConfigure your GitLab account, register GitLab in the application registry, and create a credential record for the GitLab App provider.\n\nRole required: oauth\\_admin.\n\n**Parent Topic:**[GitLab integration with DevOps Change Velocity](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/it-service-management/devops-change-velocity/gitlab-integration-dev-ops.md)\n\n## Configure the GitLab App in your GitLab account \\(Authorization Code\\)\n\nCreate a custom GitLab App from your GitLab account to enable OAuth 2.0 authentication with your ServiceNow instance.\n\n### Before you begin\n\nRole required: admin\n\n### About this task\n\nConfigure GitLab as an OAuth 2.0 authentication identity provider. For more information, see [GitLab documentation](https://docs.gitlab.com/ee/integration/oauth_provider.html#user-owned-applications).\n\n### Procedure\n\n1.  From your GitLab account, create your App by navigating to **Edit Profile** &gt; **Applications**.\n\n2.  In the **Add new application** form, specify a **Name**, and in **Redirect URI** field, enter `https://<instance-name>.service-now.com/oauth_redirect.do`.\n\n3.  In the **Scopes** section, ensure that you select the **api** check box.\n\n4.  Leave the remaining fields empty \\(default\\).\n\n5.  Click **Save application**.\n\n    The application is created. You can open the application to access the Application ID, Secret key, and Callback URL.\n\n6.  Install the newly created GitLab App on the accounts of your choice.\n\n\n## Register GitLab as an OAuth Provider \\(Authorization Code\\)\n\nUse the information generated during GitLab App account configuration to register GitLab as an OAuth provider and allow the instance to request OAuth 2.0 tokens.\n\n### Before you begin\n\nRole required: admin\n\n### Procedure\n\n1.  Navigate to **System OAuth** &gt; **Application Registry**.\n\n2.  Click **New**.\n\n    The system displays the message **What kind of OAuth application?**\n\n3.  Select **Connect to a third party OAuth Provider**.\n\n    The system displays an empty Application Registries form.\n\n4.  Complete the form.\n\n<table id=\"table_fd2_2xr_4mb\"><thead><tr><th>\n\nField\n\n</th><th>\n\nValue required\n\n</th></tr></thead><tbody><tr><td>\n\nName\n\n</td><td>\n\nEnter any name to uniquely identify the record. For example, enter `My GitLab App Provider`.\n\n</td></tr><tr><td>\n\nClient ID\n\n</td><td>\n\nEnter the Application ID of your GitLab App.\n\n</td></tr><tr><td>\n\nClient Secret\n\n</td><td>\n\nEnter the secret key of your GitLab App.\n\n</td></tr><tr><td>\n\nOAuth API script\n\n</td><td>\n\nSelect **OAuthDevOpsGitLabHandler**.\n\n</td></tr><tr><td>\n\nDefault Grant type\n\n</td><td>\n\nSelect **Authorization Code**.\n\n</td></tr><tr><td>\n\nAuthorization URL\n\n</td><td>\n\nEnter `https://gitlab.com/oauth/authorize`.\n\n For an on-premise deployment, use the proper GitLab host URL.\n\n</td></tr><tr><td>\n\nToken URL\n\n</td><td>\n\nEnter `https://gitlab.com/oauth/token`.\n\n For an on-premise deployment, use the proper GitLab host URL.\n\n</td></tr></tbody>\n</table>5.  Leave the rest of the form fields as default.\n\n6.  Right-click the form header, and click **Save**.\n\n    -   The system validates the OAuth credentials and populates the **Redirect URL** \\(Hint: It should match the **Redirect URI** value previously provided in your GitLab App configuration\\).\n    -   The system populates **OAuth Entity Profile** with **Grant Type** as **Authorization Code**. For example, **OAuth Entity Profile** is created with default **Name**, **My GitLab App Provider default\\_profile**.\n7.  Validate that the **OAuth Entity Scopes** related list contains the **api** scope.\n\n\n## Create a credential record for GitLab App provider \\(Authorization Code\\)\n\nCreate a credential record for the GitLab App provider previously created to authorize actions.\n\n### Before you begin\n\nRole required: admin\n\n**Note:** The user who creates the credential record, and generates the OAuth token in ServiceNow must have at least the Maintainer role in GitLab for project webhooks, and Owner role for group webhooks to ensure that webhooks can be auto-configured. For more information, see [GitLab](https://docs.gitlab.com/ee/user/project/integrations/webhooks.html) documentation.\n\n### Procedure\n\n1.  Navigate to **Connections &amp; Credentials** &gt; **Credentials**.\n\n2.  Click **New**.\n\n    The system displays the message **What type of Credentials would you like to create?**.\n\n3.  Select **OAuth 2.0 Credentials**.\n\n    The pop-up window displays an empty OAuth 2.0 Credentials form.\n\n4.  Fill in these values.\n\n    |Field|Value required|\n    |-----|--------------|\n    |Name|Enter any name to uniquely identify the record. For example, enter `My GitLab App Credential`.|\n    |Active|Enable|\n    |OAuth Entity Profile|Select the default OAuth Entity profile you created previously.|\n    |Applies to|Select the MID Servers that can use this credential. For example, select **All MID Servers**.|\n    |Order|Select the order to apply this credential. For example, enter `100`.|\n\n5.  Save the record.\n\n6.  Click the **Get OAuth Token** related link to generate the OAuth token.\n\n    A successful token generation indicates that you can now authenticate connection between ServiceNow DevOps and GitLab via OAuth.\n\n\n"}}