CORS¶
cors
¶
CORS origin validation for MCP OAuth endpoints.
parse_allowed_origins
¶
Parse allowed CORS origins from a comma-separated environment variable.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
env_var
|
str
|
Name of the environment variable to read. |
'ALLOWED_MCP_ORIGINS'
|
Returns:
| Type | Description |
|---|---|
list[str]
|
List of allowed origin strings, stripped of whitespace. |
Source code in mcp_authflow/cors.py
get_cors_origin
¶
Get CORS origin header value based on request origin.
Only returns the origin if it's in the allowed list, otherwise returns empty string to deny CORS access.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
request
|
Request
|
The incoming request. |
required |
allowed_origins
|
list[str]
|
List of allowed origin strings. |
required |
Returns:
| Type | Description |
|---|---|
str
|
Origin value for Access-Control-Allow-Origin header. |
Source code in mcp_authflow/cors.py
build_cors_headers
¶
Build standard CORS headers for OAuth discovery endpoints.
Only includes Access-Control-Allow-Origin when the request origin is in the allowlist. Omits it entirely for disallowed origins per the CORS specification.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
request
|
Request
|
The incoming request. |
required |
allowed_origins
|
list[str]
|
List of allowed origin strings. |
required |
Returns:
| Type | Description |
|---|---|
dict[str, str]
|
Dict of CORS headers. |