@@ -1124,19 +1124,18 @@ async def handle_sse(scope: Scope, receive: Receive, send: Send): # pragma: no
11241124 # Set up auth if configured
11251125 if self .settings .auth :
11261126 required_scopes = self .settings .auth .required_scopes or []
1127-
1128- # Add auth middleware if token verifier is available
1129- if self ._token_verifier :
1130- middleware = [
1131- # extract auth info from request (but do not require it)
1132- Middleware (
1133- AuthenticationMiddleware ,
1134- backend = BearerAuthBackend (self ._token_verifier ),
1135- ),
1136- # Add the auth context middleware to store
1137- # authenticated user in a contextvar
1138- Middleware (AuthContextMiddleware ),
1139- ]
1127+ assert self ._token_verifier is not None
1128+
1129+ middleware = [
1130+ # extract auth info from request (but do not require it)
1131+ Middleware (
1132+ AuthenticationMiddleware ,
1133+ backend = BearerAuthBackend (self ._token_verifier ),
1134+ ),
1135+ # Add the auth context middleware to store
1136+ # authenticated user in a contextvar
1137+ Middleware (AuthContextMiddleware ),
1138+ ]
11401139
11411140 # Add auth endpoints if auth server provider is configured
11421141 if self ._auth_server_provider :
@@ -1154,7 +1153,7 @@ async def handle_sse(scope: Scope, receive: Receive, send: Send): # pragma: no
11541153 )
11551154
11561155 # When auth is configured, require authentication
1157- if self ._token_verifier :
1156+ if self .settings . auth :
11581157 # Determine resource metadata URL
11591158 resource_metadata_url = None
11601159 if self .settings .auth and self .settings .auth .resource_server_url :
0 commit comments