Skip to content

Add discovery-based GenericOIDCProvider - #14

Open
carlosplanchon wants to merge 1 commit into
benavlabs:mainfrom
carlosplanchon:feat/generic-oidc-provider
Open

Add discovery-based GenericOIDCProvider#14
carlosplanchon wants to merge 1 commit into
benavlabs:mainfrom
carlosplanchon:feat/generic-oidc-provider

Conversation

@carlosplanchon

Copy link
Copy Markdown

One provider class for any spec-compliant OIDC IdP (Zitadel, Keycloak, Authentik, Auth0, Okta, Entra ID): from_discovery() fetches {issuer}/.well-known/openid-configuration, resolves the authorize/token/userinfo endpoints, and validates that the document's declared issuer matches the requested one (a spec requirement that hand-rolled subclasses tend to skip). process_user_info maps the standard OIDC claims.

Design notes:

  • Construction is an async classmethod because discovery is a network call and the port's sync surface cannot await; build it once at startup. The plain init also works when the endpoints are already known.
  • Deliberately NOT registered with OAuthProviderFactory: create_provider builds from name plus credentials alone and cannot carry an issuer, so registering it would only produce a confusing TypeError.
  • Maintenance surface is small: OIDC Discovery 1.0 has been frozen since 2014, and the tests use a MockTransport (no network in CI).

Why core rather than a docs example: the issuer validation is the security-sensitive part, and as a copy-paste example every app re-implements it and some will skip it. As core it is written once, tested, and versioned.

Validated live: this class (via a downstream integration) ran a full login against a real self-hosted Zitadel instance, public PKCE client included (pairs with #13 for secretless clients).

Possible follow-up, your call: plumb an issuer field through OAuthCredentials so oauth={...} supports OIDC providers natively; that change would use this class internally and deserves its own design discussion (async init would move to initialize()).

A single provider for any spec-compliant OpenID Connect IdP (Zitadel,
Keycloak, Authentik, Auth0, Okta, Entra ID, ...). from_discovery() fetches
{issuer}/.well-known/openid-configuration, resolves the authorize/token/
userinfo endpoints, and validates the declared issuer; process_user_info
maps the standard OIDC claims.

Construction is via an async classmethod because discovery is a network
call and the port's sync surface (get_authorization_url) cannot await;
build it once at startup. Deliberately not registered with
OAuthProviderFactory: create_provider builds from name + credentials
alone and cannot carry an issuer, so registering it would only produce a
confusing TypeError. Callers construct it directly instead.

Adds OIDC_DISCOVERY_PATH / OIDC_DEFAULT_SCOPES constants and test_oidc.py
(discovery resolution, PKCE URL, issuer/endpoint validation, claim mapping).

Signed-off-by: Carlos Andrés Planchón Prestes <carlosandresplanchonprestes@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant