OAuth 2.0 protected resource for HTTP transport. Serves Protected Resource Metadata (RFC 9728) pointing at the Flagsmith authorization server and returns 401 + `WWW-Authenticate` when a request carries no credential, so MCP clients can discover and complete the OAuth flow. Any `Auth
| 38 | |
| 39 | |
| 40 | class FlagsmithResourceAuth(RemoteAuthProvider): |
| 41 | """OAuth 2.0 protected resource for HTTP transport. |
| 42 | |
| 43 | Serves Protected Resource Metadata (RFC 9728) pointing at the Flagsmith |
| 44 | authorization server and returns 401 + `WWW-Authenticate` when a request |
| 45 | carries no credential, so MCP clients can discover and complete the OAuth |
| 46 | flow. Any `Authorization` header is accepted and passed through — the API |
| 47 | validates it (no introspection here). |
| 48 | """ |
| 49 | |
| 50 | def __init__(self, *, resource_url: str, authorization_server: str) -> None: |
| 51 | token_verifier = TokenVerifier( |
| 52 | required_scopes=[] |
| 53 | ) # never consulted — introspection done by Core API. |
| 54 | super().__init__( |
| 55 | token_verifier=token_verifier, |
| 56 | authorization_servers=[AnyHttpUrl(authorization_server)], |
| 57 | base_url=resource_url, |
| 58 | scopes_supported=OAUTH_SCOPES, |
| 59 | ) |
| 60 | |
| 61 | def _get_resource_url(self, path: str | None = None) -> AnyHttpUrl | None: |
| 62 | # Advertise the server origin as the protected resource |
| 63 | # to enable client registration for both the root path and the /mcp path |
| 64 | return super()._get_resource_url(None) |
| 65 | |
| 66 | def get_middleware(self) -> list[Middleware]: |
| 67 | return [ |
| 68 | Middleware(AuthenticationMiddleware, backend=_AnySchemeBackend()), |
| 69 | Middleware(AuthContextMiddleware), |
| 70 | ] |
no outgoing calls
no test coverage detected
searching dependent graphs…