Skip to main content

OpenIdConnect

OpenID Connect authentication class. An instance of it would be used as a dependency. Warning: this is only a stub to connect the components with OpenAPI in FastAPI, but it doesn't implement the full OpenIdConnect scheme, for example, it doesn't use the OpenIDConnect URL. You would need to subclass it and implement it in your code.

Constructor

Signature

def OpenIdConnect(
openIdConnectUrl: str,
scheme_name: str | None = None,
description: str | None = None,
auto_error: bool = True
)

Parameters

NameTypeDescription
openIdConnectUrlstrThe OpenID Connect URL.
scheme_name`strNone` = None
description`strNone` = None
auto_errorbool = TrueBy default, if no HTTP Authorization header is provided, required for OpenID Connect authentication, it will automatically cancel the request and send the client an error. If auto_error is set to False, when the HTTP Authorization header is not available, instead of erroring out, the dependency result will be None. This is useful when you want to have optional authentication. It is also useful when you want to have authentication that can be provided in one of multiple optional ways (for example, with OpenID Connect or in a cookie).

Methods


make_not_authenticated_error()

@classmethod
def make_not_authenticated_error() - > [HTTPException](../../../../../exceptions/httpexception.md?sid=fastapi_exceptions_httpexception)

Creates and returns an HTTPException instance configured for a 401 Unauthorized response. This method is used internally when authentication fails and auto_error is enabled.

Returns

TypeDescription
[HTTPException](../../../../../exceptions/httpexception.md?sid=fastapi_exceptions_httpexception)An HTTPException object with a 401 status code, 'Not authenticated' detail, and a 'WWW-Authenticate: Bearer' header.