diff --git a/docs/web/authentication.md b/docs/web/authentication.md index 3efbea55a9..fda750757f 100644 --- a/docs/web/authentication.md +++ b/docs/web/authentication.md @@ -431,6 +431,11 @@ Specific behavior related to each provider is configured by a provider `template * `username` - Company's signum will be the user's identifier. * `email` - an email associated with this Microsoft account will be used as user's identifier. + `gitlab/v1` + * `username` - the username the user prefers to be referred to as, usually their login or the login from the authentication provider. + * `email` - an email associated with this Gitlab account will be used as user's identifier. + * `name` - user's full name. + The properties below are automatically set by templates, but can be overridden for testing purposes, and when using a custom OAuth provider. * `callback_url` diff --git a/web/codechecker_web/server/oauth_templates.py b/web/codechecker_web/server/oauth_templates.py index d21b9e169d..56cb315820 100644 --- a/web/codechecker_web/server/oauth_templates.py +++ b/web/codechecker_web/server/oauth_templates.py @@ -46,5 +46,15 @@ "user_info_mapping": { "username": "email" } + }, + "gitlab/v1": { + "authorization_url": "https://gitlab.com/oauth/authorize", + "callback_url": "{host}/login/OAuthLogin/{provider}", + "token_url": "https://gitlab.com/oauth/token", + "user_info_url": "https://gitlab.com/oauth/userinfo", + "scope": "openid email profile", + "user_info_mapping": { + "username": "email" + } } } diff --git a/web/server/codechecker_server/api/authentication.py b/web/server/codechecker_server/api/authentication.py index 88d4d1fbc1..2a402d17b4 100644 --- a/web/server/codechecker_server/api/authentication.py +++ b/web/server/codechecker_server/api/authentication.py @@ -484,9 +484,15 @@ def performLogin(self, auth_method, auth_string): username = claims.get("Signum") else: username = user_info.get("mail") + elif template == "gitlab/v1": + if username_key == "username": + username = user_info.get("preferred_username") + elif username_key == "email": + username = user_info.get("email") + elif username_key == "name": + username = user_info.get("name") LOG.debug(f"groups fetched for {username}, are: {groups}") - LOG.info("Username fetched, for username: %s", username) except Exception as ex: LOG.error("Username fetch failed: %s", str(ex)) diff --git a/web/server/config/server_config.json b/web/server/config/server_config.json index 2af90b1f7b..548eb9858c 100644 --- a/web/server/config/server_config.json +++ b/web/server/config/server_config.json @@ -84,6 +84,17 @@ "variables": { "tenant_id": "common" } + }, + "gitlab": { + "enabled": false, + "client_id": "", + "client_secret": "", + "template": "gitlab/v1", + "variables": { + "authorization_url": "https://gitlab.custom.com/oauth/authorize", + "token_url": "https://gitlab.custom.com/oauth/token", + "user_info_url": "https://gitlab.custom.com/oauth/userinfo" + } } } },