-
Notifications
You must be signed in to change notification settings - Fork 0
feat(auth): add OpenID Connect (OIDC) SSO login #238
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
Open
pchopinet
wants to merge
6
commits into
main
Choose a base branch
from
feat/openid
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
12c78d3
feat(auth): add OpenID Connect (OIDC) SSO login
pchopinet 4c7d4c4
feat(auth): sync profile from IdP and lock password for OIDC users
pchopinet 225546f
fix(auth): clarify OIDC login comments and formatting adjustments
pchopinet ac507a7
docs(auth): document OIDC SSO configuration for self-hosting
pchopinet 3c137dc
fix(auth): harden OIDC username de-duplication and subject linking
pchopinet f54f590
style(auth): tidy login layout (single OR divider, discreet admin link)
pchopinet 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
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
Empty file.
Empty file.
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,56 @@ | ||
| """Print mozilla-django-oidc endpoint settings discovered from an OIDC issuer. | ||
|
|
||
| Usage: | ||
| manage.py oidc_discover https://idp.example.com/realms/myrealm | ||
|
|
||
| Fetches the issuer's `.well-known/openid-configuration` and prints the | ||
| `OIDC_OP_*` environment lines to copy into the deployment config. This is a | ||
| config-time helper only - the running app uses the explicit endpoints from the | ||
| environment, so the boot never depends on the IdP being reachable. | ||
| """ | ||
|
|
||
| import httpx | ||
| from django.core.management.base import BaseCommand, CommandError | ||
|
|
||
| from workspace.common.logging import scrub | ||
|
|
||
| WELL_KNOWN = '/.well-known/openid-configuration' | ||
|
|
||
|
|
||
| class Command(BaseCommand): | ||
| help = ( | ||
| "Fetch an OIDC issuer's discovery document and print the OIDC_OP_* " | ||
| "environment variables to configure." | ||
| ) | ||
|
|
||
| def add_arguments(self, parser): | ||
| parser.add_argument( | ||
| 'issuer', | ||
| help='OIDC issuer URL (with or without the .well-known suffix).', | ||
| ) | ||
|
|
||
| def handle(self, *args, **options): | ||
| issuer = options['issuer'].rstrip('/') | ||
| url = issuer if issuer.endswith(WELL_KNOWN) else issuer + WELL_KNOWN | ||
|
|
||
| try: | ||
| resp = httpx.get(url, timeout=10, follow_redirects=True) | ||
| resp.raise_for_status() | ||
| doc = resp.json() | ||
| except (httpx.HTTPError, ValueError) as exc: | ||
| raise CommandError( | ||
| f'Failed to fetch discovery document from {scrub(url)}: {exc}') | ||
|
|
||
| mapping = { | ||
| 'OIDC_OP_AUTHORIZATION_ENDPOINT': doc.get('authorization_endpoint'), | ||
| 'OIDC_OP_TOKEN_ENDPOINT': doc.get('token_endpoint'), | ||
| 'OIDC_OP_USER_ENDPOINT': doc.get('userinfo_endpoint'), | ||
| 'OIDC_OP_JWKS_ENDPOINT': doc.get('jwks_uri'), | ||
| } | ||
| missing = [key for key, value in mapping.items() if not value] | ||
| if missing: | ||
| raise CommandError( | ||
| 'Discovery document is missing: ' + ', '.join(missing)) | ||
|
|
||
| for key, value in mapping.items(): | ||
| self.stdout.write(f'{key}={value}') |
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,30 @@ | ||
| # Generated by Django 6.0.5 on 2026-05-30 13:02 | ||
|
|
||
| import django.db.models.deletion | ||
| import workspace.common.uuids | ||
| from django.conf import settings | ||
| from django.db import migrations, models | ||
|
|
||
|
|
||
| class Migration(migrations.Migration): | ||
|
|
||
| dependencies = [ | ||
| ('users', '0007_drop_redundant_indexes'), | ||
| migrations.swappable_dependency(settings.AUTH_USER_MODEL), | ||
| ] | ||
|
|
||
| operations = [ | ||
| migrations.CreateModel( | ||
| name='OIDCIdentity', | ||
| fields=[ | ||
| ('uuid', models.UUIDField(default=workspace.common.uuids.uuid_v7_or_v4, editable=False, primary_key=True, serialize=False)), | ||
| ('sub', models.CharField(max_length=255, unique=True)), | ||
| ('created_at', models.DateTimeField(auto_now_add=True)), | ||
| ('user', models.OneToOneField(on_delete=django.db.models.deletion.CASCADE, related_name='oidc_identity', to=settings.AUTH_USER_MODEL)), | ||
| ], | ||
| options={ | ||
| 'verbose_name': 'OIDC identity', | ||
| 'verbose_name_plural': 'OIDC identities', | ||
| }, | ||
| ), | ||
| ] |
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
Oops, something went wrong.
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.