Conversation
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #96 +/- ##
==========================================
+ Coverage 76.00% 76.52% +0.51%
==========================================
Files 26 26
Lines 3776 3863 +87
==========================================
+ Hits 2870 2956 +86
- Misses 906 907 +1 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Add tests for HTTPOIDCAuth.__init__ failure modes (jwt not installed, unsupported password version, JWKS fetch error), verify_token jwt=None guard, DAVAuth init with wrong *oidc password format, and bearer pick_out_user when user is unknown with no fallback template.
| { | ||
| "username": "*oidc", | ||
| "password": "<oidc>#1#https://idp.example.com/realms/PIC#https://idp.example.com/realms/institution/protocol/openid-connect/certs#account#cosmohub-test#RS256#openid", | ||
| "permissions": ["+^/$"] |
There was a problem hiding this comment.
add a example that without permissions in config file
There was a problem hiding this comment.
all info(username and permissions) come from oauth maybe better in real deploy
There was a problem hiding this comment.
Hey,
Implemented OIDC groups-based permission resolution. Permissions can now
come from the access_token's groups claim.
What changed:
- password format: 8 → 9 fields, 9th is group_prefix (e.g.
asgi-webdav_). - HTTPOIDCAuth stores the prefix.
- New _extract_groups_permissions() filters token groups by prefix,
strips prefix, returns permission list. - pick_out_user now has 3-tier priority:
- User in config → config permissions (groups ignored)
- User not in config, has matching groups → groups as permissions
- User not in config, no matching groups → *oidc template fallback
- 6 new tests covering all priority paths, prefix filtering, empty
groups, no groups claim. - Updated docs.
There was a problem hiding this comment.
Please add a new example that without permissions in config file. If possible, please add the configuration information for the OIDC porvider(Keycloak) part.
|
Support OIDC is greate idea! Is it compatible with Authelia? btw: I'll be 2-4 weeks before I have time to do a full review. |
The password format expands from 8 to 9 fields, adding a (e.g. ). When an OIDC Bearer user is not listed in , the server now extracts permissions from the token's pic mhedas test_proxy users claim, filtering by prefix and stripping it before use. Priority chain: 1. User in config → config permissions (groups ignored) 2. User not in config, has matching groups → groups as permissions 3. User not in config, no matching groups → *oidc template fallback 4. No *oidc template → denied Breaking: existing 8-field <oidc> configs must add a 9th field.
bfb1e8b to
597ee54
Compare
|
This implementation is designed specifically for Keycloak. It relies on Keycloak-specific behavior, such as the |
This is a real sad. I didn't use Keycloak, so please provide as much detailed documentation as possible on how to integrate it with Keycloak. |
|
Sorry, I didn't explain myself clearly. The feature was developed and tested using Keycloak backed by FreeIPA, but the implementation itself only relies on the standard OpenID Connect authentication flow and OAuth 2.0 specifications. It does not depend on any Keycloak-specific APIs or features, so in principle it should work with any standards-compliant OIDC provider. The only part that is provider-specific is the configuration of the issued access token. The application expects the access token to contain a set of standard claims (issuer, audience, scopes, username, etc.). These are mostly defined by the OpenID Connect and OAuth 2.0 specifications rather than by Keycloak itself. Based on your comment, I realized this wasn't documented clearly enough, so I've added documentation describing the required access token claims and what each of them is used for. This should make it easier to configure other providers, such as Authelia, Authentik, Dex, or Zitadel, to be compatible with the application. Since our environment uses Keycloak, I haven't been able to verify the configuration with Authelia myself. If you happen to configure OpenID Connect with Authelia following the documentation, I'd be interested to know whether everything works as expected. That would help confirm that the documentation is complete. |
|
Hi @rexzhang, just following up on this PR. Have you had a chance to review it? I’d be happy to address any feedback or make any changes needed. Thanks! |
|
Hi @SilviaSWR , I will review it during the October 1st holiday. |
OIDC Bearer Token Authentication
Checklist
changelog.en.mdif necessary? Don't forget to add your name and github profile link!Description
Add HTTP Bearer token authentication using OpenID Connect (OIDC). When a client sends
Authorization: Bearer <access_token>, the server verifies the JWT locally against the IdP's JWKS public keys (fetched at startup, no per-request network call), validates required claims (iss,aud,azp,typ,scope,exp), extractspreferred_username, and resolves permissions fromaccount_mapping.What's new
HTTPOIDCAuthclass (asgi_webdav/auth.py) — verifies JWTs locally against JWKS public keys. Eagerly fetches keys at startup; failure is fatal.DAVPasswordType.OIDC— new password type with format<oidc>#1#issuer#jwks_uri#audience#client_id#algorithm#scope.*oidcsentinel user — mirrors the*ldapconvention. Configures the OIDC provider and serves as the default permission template for authenticated Bearer users not explicitly listed inaccount_mapping.DAVAuth.pick_out_user()— handlesAuthorization: Bearerheader, verifies token, looks up user permissions, falls back to*oidctemplate.WWW-Authenticate: Bearerappended to 401 challenge when OIDC is configured.Configuration
Add a
*oidcentry toaccount_mapping:{ "account_mapping": [ { "username": "*oidc", "password": "<oidc>#1#https://idp.example.com/realms/PIC#https://idp.example.com/realms/PIC/protocol/openid-connect/certs#account#cosmohub-test#RS256#openid", "permissions": ["+^/$"] } ] }Install the optional dependency:
pip install ASGIWebDAV[oidc]Key design decisions
*oidctemplate permissions. Invalid Bearer tokens always return 401 (never degrade to anonymous).*oidcpassword field is only used for JWT configuration.[oidc]extra to avoid bloating the core install.Files changed
asgi_webdav/auth.pyHTTPOIDCAuthclass,DAVPasswordType.OIDC, Bearer handling inpick_out_user()andcreate_response_401()requirements.d/oidc.txtPyJWT>=2.11.0,cryptographyrequirements.d/full.txt-r oidc.txtpyproject.toml[oidc]extratests/conftest.pytests/test_auth_oidc.pydocs/guide/authentication.en.mddocs/guide/protect-your-password-in-the-config.en.mddocs/changelog.en.mdfixes #95