Oauth scopes handling

From RedHatProductSecurity/prodsec-skills · View interactive version

Oauth scopes handling is an AI agent skill from the GitHub repository RedHatProductSecurity/prodsec-skills. Handle OAuth scopes in MCP clients according to the WWW-Authenticate header and Protected Resource Metadata discovery flow. Use when building or reviewing MCP client authorization flows, scope negotiation, or permission handling.

How to use this skill

Skill file

OAuth Scopes Handling in MCP Clients

Security Requirement

MCP clients MUST discover and use OAuth scopes from the WWW-Authenticate header or Protected Resource Metadata when authenticating to MCP servers. Scopes define the permissions the client is requesting and MUST be handled as follows:

Scope Discovery Priority

  1. WWW-Authenticate header: If the MCP client receives a scope parameter in the WWW-Authenticate header of a 401 response, it MUST use those scopes.
  2. Protected Resource Metadata: If no scope is provided in the 401 response, check scopes_supported in the Protected Resource Metadata (PRM) document.

Flow

1. MCP client attempts to access MCP server resource
2. MCP server returns 401 Unauthorized with:
   WWW-Authenticate: Bearer realm="mcp", scope="tools:read tools:execute"
3. MCP client extracts scope from WWW-Authenticate header
   → If scope present: use those scopes for authorization request
   → If scope absent: fetch PRM and use scopes_supported
4. MCP client requests authorization with the discovered scopes

Example: WWW-Authenticate with Scope

HTTP/1.1 401 Unauthorized
WWW-Authenticate: Bearer realm="mcp-server",
  scope="tools:read tools:execute resources:read"

The client should request exactly these scopes (or a subset) from the authorization server.

Implementation Checklist

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.