Skip to content

Middleware

dagster_authkit.core.middleware

Authentication Middleware — Pure ASGI (not BaseHTTPMiddleware).

Why pure ASGI:

  • BaseHTTPMiddleware only handles scope["type"] == "http", so WebSocket connections (Dagster GraphQL subscriptions at /graphql) bypass auth entirely.

  • Pure ASGI intercepts both HTTP and WebSocket scopes.

  • Also solves the CORS ordering problem: as a pure ASGI middleware we sit at the right layer regardless of insert position.

DagsterAuthMiddleware

Pure ASGI authentication middleware.

Handles both HTTP and WebSocket connections. WebSocket GraphQL subscriptions at /graphql are authenticated via session cookie.

__init__

__init__(app)

Initialise the authentication middleware.

Parameters:

Name Type Description Default
app ASGIApp

Inner ASGI application (the Dagster webserver).

required

__call__ async

__call__(scope, receive, send)

ASGI entry point. Routes HTTP and WebSocket connections to the appropriate handler.

Parameters:

Name Type Description Default
scope Scope

ASGI connection scope.

required
receive Receive

ASGI receive callable.

required
send Send

ASGI send callable.

required