Skip to content

fastapi_sso.sso.generic

A generic OAuth client that can be used to quickly create support for any OAuth provider with close to no code.

create_provider(*, name='generic', default_scope=None, discovery_document, response_convertor=None)

A factory to create a generic OAuth client usable with almost any OAuth provider. Returns a class.

Parameters:

Name Type Description Default
name str

Name of the provider

'generic'
default_scope Optional[List[str]]

default list of scopes (can be overriden in constructor)

None
discovery_document Union[DiscoveryDocument, Callable[[SSOBase], DiscoveryDocument]]

a dictionary containing discovery document or a callable returning it

required
response_convertor Optional[Callable[[Dict[str, Any], Optional[AsyncClient]], OpenID]]

a callable that will receive JSON response from the userinfo endpoint and should return OpenID object

None
Example
Python
from fastapi_sso.sso.generic import create_provider

discovery = {
    "authorization_endpoint": "http://localhost:9090/auth",
    "token_endpoint": "http://localhost:9090/token",
    "userinfo_endpoint": "http://localhost:9090/me",
}

SSOProvider = create_provider(name="oidc", discovery_document=discovery)
sso = SSOProvider(
    client_id="test",
    client_secret="secret",
    redirect_uri="http://localhost:8080/callback",
    allow_insecure_http=True
    )