Validation¶
validation
¶
Input validation utilities for OAuth endpoints.
validate_client_id
¶
Validate client_id format to prevent injection attacks.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
client_id
|
str
|
The client identifier to validate |
required |
Returns:
| Type | Description |
|---|---|
bool
|
True if valid, False otherwise |
Valid client IDs must: - Contain only alphanumeric characters, hyphens, and underscores - Be between 1 and 256 characters long
Source code in mcp_authflow/validation.py
parse_json_field
¶
Parse a JSON string field into a list of strings.
Accepts a JSON-encoded array string, a list of strings, or None. Non-list results (e.g. a JSON object or scalar) return the default.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
value
|
str | list[str] | None
|
The value to parse (JSON string, list, or None) |
required |
default
|
list[str]
|
Default value to return if parsing fails or value is falsy |
required |
Returns:
| Type | Description |
|---|---|
list[str]
|
Parsed list or default |
Source code in mcp_authflow/validation.py
parse_scope_field
¶
Parse OAuth scope field into a space-separated string.
Handles multiple formats: - List of strings: ["read", "write"] -> "read write" - JSON string array: '["read", "write"]' -> "read write" - Space-separated string: "read write" -> "read write"
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
scopes
|
str | list[str] | None
|
Scope value in any supported format |
required |
Returns:
| Type | Description |
|---|---|
str
|
Space-separated scope string |