Skip to content

xtr_security_openid_connect_server.bundle

The bundle wiring the OpenID Connect provider into an application.

An application lists :class:OpenIdConnectServerBundle, which brings the OAuth 2.0 authorization server's bundle along, and configures it with an :class:OpenIdConnectServerConfig.

:data:PROMPT_LISTENER is the qualifier of the chain step deciding prompt and max_age: the application lists it in the listeners of the firewall that signs end-users in.

OpenIdConnectServerBundle

Bases: Bundle[OpenIdConnectServerConfig]

Turns this deployment's authorization server into an OpenID Connect provider.

An identity layer exists only on top of a server that already issues access tokens, so listing this bundle brings the authorization server along, with the security family, the clock, the event dispatcher and the HTTP kernel that server is built on. The authorization server knows nothing of this bundle: this one plugs into it, through the settings it prepends and the flow it tags as a grant.

Each peer is named by its "module:Class" string, the way the authorization server names its own: the kernel imports each one as it resolves the bundles, so a peer that is not installed is reported there, by name.

It builds and boots with no configuration at all.

prepend_extension

prepend_extension(builder: ContainerBuilder) -> None

Put the sign-in's flow, answer and scope in place of the shipped ones.

load_extension

load_extension(config: OpenIdConnectServerConfig, services: ServiceConfigurator, builder: ContainerBuilder) -> None

Register the claim sets, ID-token settings, identity provider, flow and endpoints.

The token answer itself is not registered here: the authorization server registers whichever class its response_type_class names, which the prepend made this package's.

The listener is a function, not a service: the dispatcher keeps a listener service once fetched, so it would have to be a singleton, and the security facade it reads is scoped to the request. A function's injected parameters are filled on every call instead.

The userinfo controller is per-request for the same reason: it reads the token the request's firewall settled on. Its route resource is scanned so the HTTP kernel hands it to the application's routes files. The identity provider it asks is per-request too, so an application's provider may read users through the session of the request's unit of work.

The prompt step is per-request too, over the request's token storage, and is only registered: the application lists its qualifier in the login firewall's listeners, since only it knows which firewall signs end-users in.

process

process(builder: ContainerBuilder) -> None

Refuse a deployment whose own configuration undid what this bundle prepended.

Raises:

  • InvalidConfigurationError –

    When the authorization server runs its shipped redirect flow, answers with something that cannot carry an ID token, does not describe itself, or signs with a shared secret; or when the login firewall exists and does not list the prompt step.

OpenIdConnectServerConfig dataclass

OpenIdConnectServerConfig(identity_provider: type[IdentityProviderInterface] | None = None, claim_sets: Mapping[str, tuple[str, ...]] = dict[str, tuple[str, ...]](), id_token_ttl: timedelta | None = None, login_path: str = '/login', login_firewall: str = 'main', authorize_path: str = '/authorize')

Everything this deployment's OpenID Connect provider is configured with.

Buildable with no arguments: the provider builds and boots on its defaults, and the one setting only the application can supply — where a signed-in user's claims come from — is reported where it is first needed, by the userinfo endpoint, never by the build.

Attributes:

  • identity_provider (type[IdentityProviderInterface] | None) –

    The application's class that finds a signed-in user and their claims. The bundle registers it, so the container builds it from its constructor; the application does not register it itself.

  • claim_sets (Mapping[str, tuple[str, ...]]) –

    The claims each scope of the application's own reveals, by scope. The four scopes OpenID Connect Core defines come with theirs and cannot be given here.

  • id_token_ttl (timedelta | None) –

    How long an ID token is good for, or None to have it expire with the access token issued beside it.

  • login_path (str) –

    Where an end-user asked to sign in again is sent.

  • login_firewall (str) –

    The firewall that signs an end-user in at login_path, which remembers where to send them back.

  • authorize_path (str) –

    Where the authorization endpoint is served.