authentik.sources.oauth.types.gitlab

GitLab OAuth Views

See authentik.sources.oauth.types.gitlab.com/ee/integration/oauth_provider.html">https://docsauthentik.sources.oauth.types.gitlab.com/ee/integration/oauth_provider.html and authentik.sources.oauth.types.gitlab.com/ee/integration/openid_connect_provider.html">https://docsauthentik.sources.oauth.types.gitlab.com/ee/integration/openid_connect_provider.html

 1"""
 2GitLab OAuth Views
 3
 4See https://docs.gitlab.com/ee/integration/oauth_provider.html
 5and https://docs.gitlab.com/ee/integration/openid_connect_provider.html
 6"""
 7
 8from typing import Any
 9
10from authentik.sources.oauth.models import AuthorizationCodeAuthMethod, OAuthSource
11from authentik.sources.oauth.types.registry import SourceType, registry
12from authentik.sources.oauth.views.redirect import OAuthRedirect
13
14
15class GitLabOAuthRedirect(OAuthRedirect):
16    """GitLab OAuth2 Redirect"""
17
18    def get_additional_parameters(self, source: OAuthSource):
19        return {
20            "scope": ["read_user", "openid", "profile", "email"],
21        }
22
23
24@registry.register()
25class GitLabType(SourceType):
26    """GitLab Type definition"""
27
28    redirect_view = GitLabOAuthRedirect
29    verbose_name = "GitLab"
30    name = "gitlab"
31
32    urls_customizable = True
33
34    authorization_url = "https://gitlab.com/oauth/authorize"
35    access_token_url = "https://gitlab.com/oauth/token"  # nosec
36    profile_url = "https://gitlab.com/oauth/userinfo"
37    oidc_well_known_url = "https://gitlab.com/.well-known/openid-configuration"
38    oidc_jwks_url = "https://gitlab.com/oauth/discovery/keys"
39
40    authorization_code_auth_method = AuthorizationCodeAuthMethod.POST_BODY
41
42    def get_base_user_properties(self, info: dict[str, Any], **kwargs) -> dict[str, Any]:
43        return {
44            "username": info.get("preferred_username"),
45            "email": info.get("email"),
46            "name": info.get("name"),
47        }
class GitLabOAuthRedirect(authentik.sources.oauth.views.redirect.OAuthRedirect):
16class GitLabOAuthRedirect(OAuthRedirect):
17    """GitLab OAuth2 Redirect"""
18
19    def get_additional_parameters(self, source: OAuthSource):
20        return {
21            "scope": ["read_user", "openid", "profile", "email"],
22        }

GitLab OAuth2 Redirect

def get_additional_parameters(self, source: authentik.sources.oauth.models.OAuthSource):
19    def get_additional_parameters(self, source: OAuthSource):
20        return {
21            "scope": ["read_user", "openid", "profile", "email"],
22        }

Return additional redirect parameters for this source.

@registry.register()
class GitLabType(authentik.sources.oauth.types.registry.SourceType):
25@registry.register()
26class GitLabType(SourceType):
27    """GitLab Type definition"""
28
29    redirect_view = GitLabOAuthRedirect
30    verbose_name = "GitLab"
31    name = "gitlab"
32
33    urls_customizable = True
34
35    authorization_url = "https://gitlab.com/oauth/authorize"
36    access_token_url = "https://gitlab.com/oauth/token"  # nosec
37    profile_url = "https://gitlab.com/oauth/userinfo"
38    oidc_well_known_url = "https://gitlab.com/.well-known/openid-configuration"
39    oidc_jwks_url = "https://gitlab.com/oauth/discovery/keys"
40
41    authorization_code_auth_method = AuthorizationCodeAuthMethod.POST_BODY
42
43    def get_base_user_properties(self, info: dict[str, Any], **kwargs) -> dict[str, Any]:
44        return {
45            "username": info.get("preferred_username"),
46            "email": info.get("email"),
47            "name": info.get("name"),
48        }

GitLab Type definition

redirect_view = <class 'GitLabOAuthRedirect'>
verbose_name = 'GitLab'
name = 'gitlab'
urls_customizable = True
authorization_url = 'https://gitlab.com/oauth/authorize'
access_token_url = 'https://gitlab.com/oauth/token'
profile_url = 'https://gitlab.com/oauth/userinfo'
oidc_well_known_url = 'https://gitlab.com/.well-known/openid-configuration'
oidc_jwks_url = 'https://gitlab.com/oauth/discovery/keys'
authorization_code_auth_method = AuthorizationCodeAuthMethod.POST_BODY
def get_base_user_properties(self, info: dict[str, typing.Any], **kwargs) -> dict[str, typing.Any]:
43    def get_base_user_properties(self, info: dict[str, Any], **kwargs) -> dict[str, Any]:
44        return {
45            "username": info.get("preferred_username"),
46            "email": info.get("email"),
47            "name": info.get("name"),
48        }

Get base user properties for enrollment/update