Skip to content

Commit 7437c88

Browse files
Remove is_in_allow_list and use preferred_username (the thundermail address) instead of recovery email (Fixes #1329) (#1331)
1 parent 5c13d2c commit 7437c88

File tree

2 files changed

+3
-21
lines changed

2 files changed

+3
-21
lines changed

backend/src/appointment/routes/auth.py

Lines changed: 2 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -653,8 +653,7 @@ def oidc_token(
653653
raise HTTPException(status_code=403, detail=l10n('invalid-credentials'))
654654

655655
oidc_id = token_data.get('sub')
656-
email = token_data.get('email')
657-
username = token_data.get('username')
656+
username = email = token_data.get('preferred_username', token_data.get('username'))
658657
name = token_data.get('name')
659658

660659
subscriber = repo.external_connection.get_subscriber_by_oidc_id(db, oidc_id)
@@ -665,14 +664,6 @@ def oidc_token(
665664
subscriber = repo.external_connection.get_subscriber_without_oidc_by_email(db, email)
666665

667666
if not subscriber:
668-
is_in_allow_list = utils.is_in_allow_list(db, email)
669-
670-
if not is_in_allow_list:
671-
if not repo.invite.code_exists(db, data.invite_code):
672-
raise HTTPException(404, l10n('invite-code-not-valid'))
673-
if not repo.invite.code_is_available(db, data.invite_code):
674-
raise HTTPException(403, l10n('invite-code-not-valid'))
675-
676667
subscriber = repo.subscriber.create(
677668
db,
678669
schemas.SubscriberBase(
@@ -683,18 +674,10 @@ def oidc_token(
683674
),
684675
)
685676

677+
# FIXME: This functionality doesn't work, but we might re-use it later. If not please delete.
686678
# Give them 10 invites
687679
repo.invite.generate_codes(db, INVITES_TO_GIVE_OUT, subscriber.id)
688680

689-
if not is_in_allow_list:
690-
# Use the invite code after we've created the new subscriber
691-
used = repo.invite.use_code(db, data.invite_code, subscriber.id)
692-
693-
# This shouldn't happen, but just in case!
694-
if not used:
695-
repo.subscriber.hard_delete(db, subscriber)
696-
raise HTTPException(500, l10n('unknown-error'))
697-
698681
# FIXME: OIDC should handle this check
699682
# Only proceed if user account is enabled (which is the default case for new users)
700683
if subscriber.is_deleted:
@@ -718,7 +701,6 @@ def oidc_token(
718701
owner_id=subscriber.id,
719702
token='', # We don't need token data here
720703
)
721-
print(external_connection_schema)
722704
repo.external_connection.create(db, external_connection_schema)
723705

724706
return JSONResponse(True)

backend/test/integration/test_auth.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -923,7 +923,7 @@ def test_oidc_token_fallback_match_by_email(self, with_db, with_client, make_pro
923923
mock_introspect.return_value = {
924924
'sub': oidc_id,
925925
'email': subscriber.email,
926-
'username': subscriber.username,
926+
'preferred_username': subscriber.email, # preferred_username is the thundermail address
927927
'name': subscriber.name,
928928
}
929929

0 commit comments

Comments
 (0)