Skip to content

Built-in authenticators

Reference for the async-aware DRF parity authenticators. See the Built-in authenticators guide for behavioural notes and worked examples.

BaseAuthentication

Bases: BaseAuthentication

All authentication classes should extend BaseAuthentication. Adds an async aauthenticate hook that defaults to running the sync authenticate in a thread.

aauthenticate async

aauthenticate(request)

Returns a (user, auth) tuple or None for the given request.

BasicAuthentication

Bases: BaseAuthentication, BasicAuthentication

HTTP Basic authentication against username and password. Adds an async surface that resolves credentials via django.contrib.auth.aauthenticate.

aauthenticate async

aauthenticate(request)

Returns a (user, None) tuple after validating the Basic credentials, or None when no header is present.

aauthenticate_credentials async

aauthenticate_credentials(userid, password, request=None)

Authenticates the user./ and password using the configured authentication backends.

SessionAuthentication

Bases: BaseAuthentication, SessionAuthentication

Use Django's session framework for authentication. Adds an async surface that prefers request._request.auser when available and runs the CSRF check off the event loop.

aauthenticate async

aauthenticate(request)

Returns a (user, None) tuple from the session, or None when no active user is present.

TokenAuthentication

Bases: BaseAuthentication, TokenAuthentication

Simple token based authentication. Clients should authenticate by passing the token key in the "Authorization" HTTP header, prepended with the string "Token ". Adds an async surface that resolves the token via async ORM.

aauthenticate async

aauthenticate(request)

Returns a (user, token) tuple after validating the Authorization header, or None when no token is supplied.

aauthenticate_credentials async

aauthenticate_credentials(key)

Returns a (user, token) tuple for the given token key using async ORM.

RemoteUserAuthentication

Bases: BaseAuthentication, RemoteUserAuthentication

REMOTE_USER authentication. Maps the value at request.META[header] to a User via the configured Django auth backend. Adds an async surface using django.contrib.auth.aauthenticate.

aauthenticate async

aauthenticate(request)

Returns a (user, None) tuple from the configured remote-user header, or None when no active user is resolved.