Skip to main content

GitLab

Follow these steps to add GitLab as a social sign-in provider to your project using the Ory Console:

  1. Sign in to Ory Console and select Social Sign-in.

  2. Click the switch next to the GitLab logo to start the configuration.

  3. Copy the Redirect URI and save it for later use.

  4. Create a GitLab OAuth2 Application.

  5. Paste the saved Redirect URI from Ory into the corresponding field in the Gitlab OAuth2 Application configuration.

  6. Enable the relevant Scopes for the application, by ticking the relevant boxes in the GitLab form:

    • read_user
    • openid
    • profile
    • email
  7. Click Save application on the GitLab form, which brings you to a summary of the registered application's properties.

  8. On the summary page, copy the Secret field.

    caution

    Make sure to copy the Secret field on this summary page right away. This is the only opportunity you will get to copy the secret.

  9. Copy the Secret from the registered application in GitLab to the Client Secret field in the Ory Console.

  10. Copy the Application ID from the registered application in GitLab to the Client ID field in the form in the Ory Console.

  11. In the Scopes field of the form in the Ory Console, add the following scopes:

    • read_user
    • openid
    • profile
    • email
  12. In the Data Mapping field of the form in the Ory Console, add the following Jsonnet code snippet, which maps the desired claims to the Ory Identity schema:

    local claims = {
    email_verified: false,
    } + std.extVar('claims');
    {
    identity: {
    traits: {
    // Allowing unverified email addresses enables account
    // enumeration attacks, if the value is used for
    // verification or as a password login identifier.
    //
    // Therefore we only return the email if it (a) exists and (b) is marked verified
    // by GitLab.
    [if 'email' in claims && claims.email_verified then 'email' else null]: claims.email,
    },
    },
    }
    info

    GitLab returns only the sub and sub_legacy claims in the id_token. Ory makes a request to GitLab's /oauth/userinfo API and adds the user info to std.extVar('claims').

    danger

    Don't save secrets such as API keys, credentials, or personal data directly in Jsonnet code snippets. Jsonnet code snippets used for data mapping aren't stored in an encrypted format in Ory Network.

  13. Click Save Configuration.

Troubleshooting

When you add a social sign-in provider, you can encounter common problems such as:

  • Redirect URI mismatch
  • Redirect loops during registration
  • Domain verification issues

To troubleshoot those issues, read Social sign-in troubleshooting.