Skip to content

Commit 5e28118

Browse files
zaryatyklingpre-commit-ci[bot]
authored
oidc: use bornhack:v2:public_credit_name claim instead of the standard nickname claim (#1838)
* set username same as sub, set nickname and prefered_username to public_credit_name but only show if there is a approved public name * Only set nickname / prefered_username if the public name is available * stop using nickname claim, start using custom bornhack:v2:public_credit_name claim instead * update scope description a bit * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --------- Co-authored-by: Thomas Steen Rasmussen <tykling@bornhack.org> Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
1 parent 370cdb0 commit 5e28118

2 files changed

Lines changed: 17 additions & 5 deletions

File tree

src/bornhack/oauth_validators.py

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,18 +11,18 @@ class BornhackOAuth2Validator(OAuth2Validator):
1111
oidc_claim_scope = OAuth2Validator.oidc_claim_scope
1212
oidc_claim_scope.update(
1313
{
14-
# the OIDC standard user claims we support, and the OIDC stanard scopes they require
14+
# the OIDC standard user claims we support, and the OIDC standard scopes they require
1515
"address": "address",
1616
"email": "email",
1717
"email_verified": "email",
18-
"nickname": "profile",
1918
"phone_number": "phone",
2019
"phone_number_verified": "phone",
2120
"updated_at": "profile",
22-
# the custom user claims we support, and the (mostly cusom) scopes they require
21+
# the custom user claims we support, and the (mostly custom) scopes they require
2322
"bornhack:v2:description": "profile",
2423
"bornhack:v2:groups": "groups:read",
2524
"bornhack:v2:permissions": "permissions:read",
25+
"bornhack:v2:public_credit_name": "profile",
2626
"bornhack:v2:teams": "teams:read",
2727
},
2828
)
@@ -50,7 +50,6 @@ def get_additional_claims(self, request) -> dict[str, str | list[dict[str, str]]
5050
# standard OIDC claims
5151
"email": request.user.email,
5252
"email_verified": True,
53-
"nickname": request.user.profile.get_public_credit_name,
5453
"updated_at": int(request.user.profile.updated.timestamp()),
5554
# bornhack custom claims
5655
"bornhack:v2:teams": [
@@ -68,13 +67,25 @@ def get_additional_claims(self, request) -> dict[str, str | list[dict[str, str]]
6867
},
6968
)
7069

70+
# include bornhack:v2:public_credit_name?
71+
if (
72+
request.user.profile.public_credit_name_approved
73+
and request.user.profile.public_credit_name
74+
):
75+
claims["bornhack:v2:public_credit_name"] = (
76+
request.user.profile.public_credit_name
77+
)
78+
79+
# include location?
7180
if request.user.profile.location:
7281
claims["address"] = {"formatted": request.user.profile.location}
7382

83+
# include phonenumber?
7484
if request.user.profile.phonenumber:
7585
claims["phone_number"] = request.user.profile.phonenumber
7686
claims["phone_number_verified"] = True
7787

88+
# include profile description?
7889
if request.user.profile.description:
7990
claims["bornhack:v2:description"] = request.user.profile.description
8091
return claims
@@ -98,5 +109,6 @@ def get_discovery_claims(self, request) -> list[str]:
98109
"bornhack:v2:description",
99110
"bornhack:v2:groups",
100111
"bornhack:v2:permissions",
112+
"bornhack:v2:public_credit_name",
101113
"bornhack:v2:teams",
102114
]

src/bornhack/settings.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,7 @@
233233
"permissions:read": "Allow the remote site to read a list of your assigned permissions (scope: permissions:read).",
234234
"teams:read": "Allow the remote site to read a list of your team memberships and team lead status (scope: teams)",
235235
# api scopes
236-
"phonebook:admin": "Allow the remote site to read the camp phonebook including service numbers and unlisted numbers. Also allows access to the POC API. Only relevant for POC team leads (scope: phonebook:admin).",
236+
"phonebook:admin": "Allow the remote site to read the camp phonebook, including service numbers and unlisted numbers. Also allow the remote site to use to the POC API. This scope is only relevant for POC team leads (scope: phonebook:admin).",
237237
"phonebook:read": "Allow the remote site to read the camp phonebook (scope: phonebook:read).",
238238
},
239239
"PKCE_REQUIRED": True,

0 commit comments

Comments
 (0)