Non interactive environments#

In batch jobs and remote sessions, a browser based login might not be possible. The client detects common job environments and can use the device flow.

Why TokenStore is important here#

In non-interactive environments, the storage layer is often the difference between a smooth unattended run and an authentication failure. A persisted refresh token lets the client renew access without forcing a fresh browser-based login every time.

Device flow manual steps#

For advanced usage, use py_oidc_auth_client.DeviceFlow directly.

import asyncio
from py_oidc_auth_client import Config, DeviceFlow

async def main() -> None:
    flow = DeviceFlow(config=Config(host="https://auth.example.org"))
    device = await flow.get_device_code()
    print(device["uri"])
    print(device["user_code"])
    token = await flow.poll(device.device_code, device.interval)
    print(token["headers"])

asyncio.run(main())

Manual code flow#

Browser based code flow can be realised by using the py_oidc_auth_client.CodeFlow class.

import asyncio
from py_oidc_auth_client import CodeFlow, Config

async def main() -> None:
    flow = CodeFlow(config=Config(host="https://auth.example.org"))
    token = await flow.authenticate()
    print(token["headers"])

asyncio.run(main())