Skip to content

Commit 65d77e2

Browse files
authored
Merge pull request #4624 from feyruzb/provider-gitlab-addition
Addition of Gitlab authentication.
2 parents 77d0404 + 13270fb commit 65d77e2

4 files changed

Lines changed: 33 additions & 1 deletion

File tree

docs/web/authentication.md

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

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

436441
* `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: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -484,9 +484,15 @@ 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+
if username_key == "username":
489+
username = user_info.get("preferred_username")
490+
elif username_key == "email":
491+
username = user_info.get("email")
492+
elif username_key == "name":
493+
username = user_info.get("name")
487494

488495
LOG.debug(f"groups fetched for {username}, are: {groups}")
489-
490496
LOG.info("Username fetched, for username: %s", username)
491497
except Exception as ex:
492498
LOG.error("Username fetch failed: %s", str(ex))

web/server/config/server_config.json

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,17 @@
8484
"variables": {
8585
"tenant_id": "common"
8686
}
87+
},
88+
"gitlab": {
89+
"enabled": false,
90+
"client_id": "<ExampleClientID>",
91+
"client_secret": "<ExampleClientSecret>",
92+
"template": "gitlab/v1",
93+
"variables": {
94+
"authorization_url": "https://gitlab.custom.com/oauth/authorize",
95+
"token_url": "https://gitlab.custom.com/oauth/token",
96+
"user_info_url": "https://gitlab.custom.com/oauth/userinfo"
97+
}
8798
}
8899
}
89100
},

0 commit comments

Comments
 (0)