-
Notifications
You must be signed in to change notification settings - Fork 3
CU-869ajt55f: Add option to use OIDC auth in medcat-trainer #161
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
jocelyneholdbrook
merged 24 commits into
main
from
CU-869ajt55f_Add-auth-via-centralised-IdP-with-feature-flag
Oct 8, 2025
Merged
Changes from all commits
Commits
Show all changes
24 commits
Select commit
Hold shift + click to select a range
5a68acb
- Add tests to increase coverage in medcat-trainer frontend
jocelyneholdbrook fb7752a
Fix indentation
jocelyneholdbrook 37643c7
Update medcat-trainer_ci.yml
jocelyneholdbrook ea5153c
Fix line endings
jocelyneholdbrook 86cb877
properly fix line endings mismatch
jocelyneholdbrook 727aec0
Create ConceptDatabase.spec.ts
jocelyneholdbrook 5b9d2da
Merge branch 'CU-869admfwg-increase-test-coverage-in-medcattrainer' o…
jocelyneholdbrook 678adba
remove erroneously added test files
jocelyneholdbrook 0a8397c
re-add end of file return
jocelyneholdbrook 7962ac7
readd new line at end of file
jocelyneholdbrook 413a8ab
properly fix line endings mismatch
jocelyneholdbrook 99e6a67
Merge branch 'CU-869admfwg-increase-test-coverage-in-medcattrainer' o…
jocelyneholdbrook 24f9bb2
CU-869admfwg: Disable push to dockerhub in QA workflow for testing
jocelyneholdbrook 462c569
CU-869admfwg: Remove workflow dispatch from QA workflow now that test…
jocelyneholdbrook 435f855
CU-869ajt55f: Initial dev setup with feature flag
jocelyneholdbrook 894dfa4
CU-869ajt55f: Map Keycloak Roles to Django User
jocelyneholdbrook 6012f20
CU-869ajt55f: Add env var expansion to optionally include Traefik lab…
jocelyneholdbrook 0aab53a
CU-869ajt55f: Tidy up configuration and fix logout
jocelyneholdbrook b0a2325
CU-869ajt55f: Disable OIDC auth by default
jocelyneholdbrook 1a95506
CU-869ajt55f: Revert unintended changes
jocelyneholdbrook 5c85b0d
CU-869ajt55f: Addressing code review feedback
jocelyneholdbrook de9c139
Merge branch 'main' into CU-869ajt55f_Add-auth-via-centralised-IdP-wi…
jocelyneholdbrook d47162d
CU-869ajt55f: Fix broken test
jocelyneholdbrook 6856a20
Merge remote-tracking branch 'origin/CU-869ajt55f_Add-auth-via-centra…
jocelyneholdbrook File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
from django.contrib.auth import get_user_model | ||
import secrets | ||
|
||
def get_user_by_email(request, id_token): | ||
""" | ||
Resolve or create a Django user using the email claim from OIDC. | ||
""" | ||
User = get_user_model() | ||
email = id_token.get('email') | ||
username = id_token.get('preferred_username') | ||
print(id_token) | ||
roles = [] | ||
if 'realm_access' in id_token: | ||
roles = id_token['realm_access'].get('roles', []) | ||
|
||
is_superuser = 'medcattrainer_superuser' in roles | ||
is_staff = 'medcattrainer_staff' in roles | ||
|
||
user, created = User.objects.get_or_create( | ||
email=email, | ||
defaults={ | ||
"username": username, | ||
"first_name": id_token.get("given_name", ""), | ||
"last_name": id_token.get("family_name", ""), | ||
"is_active": True, | ||
"password": secrets.token_urlsafe(32), | ||
}, | ||
) | ||
|
||
user.username = username | ||
user.first_name = id_token.get("given_name", "") | ||
user.last_name = id_token.get("family_name", "") | ||
user.is_superuser = is_superuser | ||
user.is_staff = is_staff | ||
|
||
user.save() | ||
return user |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
# Override this with your .env.production | ||
# Frontend auth settings | ||
VITE_USE_OIDC=0 | ||
VITE_KEYCLOAK_URL=http://keycloak.cogstack.localhost/ | ||
VITE_KEYCLOAK_REALM=cogstack-realm | ||
VITE_KEYCLOAK_CLIENT_ID=cogstack-medcattrainer-frontend | ||
VITE_KEYCLOAK_TOKEN_REFRESH_INTERVAL_MS=10000 | ||
VITE_KEYCLOAK_TOKEN_MIN_VALIDITY_SECS=30 | ||
VITE_LOGOUT_REDIRECT_URI=http://home.cogstack.localhost/ |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.