Data Models#

Typed data structures for tokens and device codes used throughout the client library.

class py_oidc_auth_client.schema.DeviceCode#

Bases: TypedDict

Device authorization response.

Returned by get_device_code(). Pass device_code and interval to poll() to complete the flow.

uri#

Verification URL the user should open in a browser. This is verification_uri_complete when the provider supports it, otherwise verification_uri.

Type:

str

user_code#

Short code the user enters at the verification URI (e.g. "ABCD-EFGH").

Type:

str

device_code#

Opaque code used to poll the token endpoint.

Type:

str

interval#

Minimum polling interval in seconds.

Type:

int

Examples

Manual device flow:

from py_oidc_auth_client import DeviceFlow

flow = DeviceFlow("https://myapp.example.com")
code = await flow.get_device_code()

print(f"Open {code['uri']} and enter: {code['user_code']}")

token = await flow.poll(
    device_code=code["device_code"],
    interval=code["interval"],
)
device_code: str#
interval: int#
uri: str#
user_code: str#
class py_oidc_auth_client.schema.Token#

Bases: TypedDict

OAuth 2.0 token payload.

access_token#

The bearer access token (JWT).

Type:

str

token_type#

Token type, typically "Bearer".

Type:

str

expires#

Access token expiry as a Unix timestamp (seconds).

Type:

int

refresh_token#

The refresh token for obtaining new access tokens.

Type:

str

refresh_expires#

Refresh token expiry as a Unix timestamp (seconds).

Type:

int

scope#

Space separated list of granted scopes.

Type:

str

headers#

Pre built Authorization header ready for use with HTTP clients (e.g. {"Authorization": "Bearer eyJ..."})

Type:

dict of str to str

Examples

Using the token with httpx:

from py_oidc_auth_client import authenticate

token = authenticate(host="https://myapp.example.com")
headers = token["headers"]

import httpx
resp = httpx.get(
    "https://myapp.example.com/api/data",
    headers=headers,
)
access_token: str#
expires: int#
headers: Dict[str, str]#
refresh_expires: int#
refresh_token: str#
scope: str#
token_type: str#