Skip to content

Commit c27f211

Browse files
committed
added gitlab authentication with documentation
1 parent ff0c03d commit c27f211

File tree

4 files changed

+30
-1
lines changed

4 files changed

+30
-1
lines changed

docs/web/authentication.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -415,6 +415,11 @@ Specific behavior related to each provider is configured by a provider `template
415415
* `username` - Company's signum will be the user's identifier.
416416
* `email` - an email associated with this Microsoft account will be used as user's identifier.
417417

418+
`gitlab/v1`
419+
* `username` - the username the user prefers to be referred to as, usually their login or the login from the authentication provider.
420+
* `email` - an email associated with this Gitlab account will be used as user's identifier.
421+
* `name` - user's full name.
422+
418423
The properties below are automatically set by templates, but can be overridden for testing purposes, and when using a custom OAuth provider.
419424

420425
* `callback_url`

web/codechecker_web/server/oauth_templates.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,5 +46,15 @@
4646
"user_info_mapping": {
4747
"username": "email"
4848
}
49+
},
50+
"gitlab/v1": {
51+
"authorization_url": "https://gitlab.com/oauth/authorize",
52+
"callback_url": "{host}/login/OAuthLogin/{provider}",
53+
"token_url": "https://gitlab.com/oauth/token",
54+
"user_info_url": "https://gitlab.com/oauth/userinfo",
55+
"scope": "openid email profile",
56+
"user_info_mapping": {
57+
"username": "email"
58+
}
4959
}
5060
}

web/server/codechecker_server/api/authentication.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -484,9 +484,17 @@ def performLogin(self, auth_method, auth_string):
484484
username = claims.get("Signum")
485485
else:
486486
username = user_info.get("mail")
487+
elif template == "gitlab/v1":
488+
print(user_info)
489+
if username_key == "username":
490+
username = user_info.get("preferred_username")
491+
elif username_key == "email":
492+
print(user_info)
493+
username = user_info.get("email")
494+
elif username_key == "name":
495+
username = user_info.get("name")
487496

488497
LOG.debug(f"groups fetched for {username}, are: {groups}")
489-
490498
LOG.info("Username fetched, for username: %s", username)
491499
except Exception as ex:
492500
LOG.error("Username fetch failed: %s", str(ex))

web/server/config/server_config.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,12 @@
8282
"variables": {
8383
"tenant_id": "common"
8484
}
85+
},
86+
"gitlab": {
87+
"enabled": false,
88+
"client_id": "<ExampleClientID>",
89+
"client_secret": "<ExampleClientSecret>",
90+
"template": "gitlab/v1"
8591
}
8692
}
8793
},

0 commit comments

Comments
 (0)