Authentication Mixin

Server-side authentication via BasicAuthMixin.

BasicAuthMixin

Authentication mixin for AsgiServer.

Provides server.authenticate(scope) as the single extension point for auth. The whole backend logic (bearer, basic, JWT) lives in authentication.AuthCore; this mixin binds it to the server class and adds the local identity source.

When the server carries a user_store (server(users=True)), both credential paths consult the store FIRST, then fall back to the config basic dict (bootstrap/legacy compat). The store’s tags enter the auth result exactly where the config tags do, so /_server/login and Basic-auth requests both work with store users unchanged. AuthCore itself stays config-only: it is also used standalone by AuthMiddleware, which has no store.

Usage:
class MyServer(BasicAuthMixin, RoutingClass):
def __init__(self):

BasicAuthMixin.__init__(self, bearer={…}, basic={…}) …

# In middleware or dispatcher: auth = server.authenticate(scope)

class genro_asgi.server.auth_mixin.BasicAuthMixin(**entries)[source]

Bases: AuthCore

Server-side auth mixin: bearer, basic, JWT, plus the local user store.

Backend configuration and verification are inherited from AuthCore. The two basic paths (the login helper and the Authorization-header dispatch) are extended here so a user_store user authenticates as well, checked before the config dict.

verify_credentials(username, password)[source]

Verify username/password against the user store first, then config.

Parameters:
  • username (str) – The username to verify.

  • password (str) – The password to verify.

Return type:

dict[str, Any] | None

Returns:

Auth dict {"identity": ..., "tags": ...} if valid, None otherwise.