Skip to content

Add async support to ResourceServerBackend for ASGI compatibility #75

@StephanMeijer

Description

@StephanMeijer

Problem

ResourceServerBackend.get_user_info_with_introspection() and related methods are synchronous, but perform blocking HTTP calls (token introspection to the authorization server).

When used from an async context (ASGI servers like uvicorn, or async frameworks like Django Bolt/Starlette), these blocking calls freeze the event loop and degrade throughput/latency.

Current workaround

Wrap calls with asgiref.sync.sync_to_async:

from asgiref.sync import sync_to_async

user_info = await sync_to_async(backend.get_user_info_with_introspection)(access_token)
user = await sync_to_async(backend.get_or_create_user)(access_token, None, user_info)

This works but adds thread pool overhead for every request.

Proposed solution

Add native async variants.

Context

We are considering migrating suitenumerique/find from Django REST Framework to Django Bolt (async-native). The OIDC authentication path would block the event loop on every authenticated request.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions