fastmcp.server.auth.redirect_validation

Utilities for validating client redirect URIs in OAuth flows.

Functions

matches_allowed_pattern

matches_allowed_pattern(uri: str, pattern: str) -> bool
Check if a URI matches an allowed pattern with wildcard support. Patterns support * wildcard matching: Args:
  • uri: The redirect URI to validate
  • pattern: The allowed pattern (may contain wildcards)
Returns:
  • True if the URI matches the pattern

validate_redirect_uri

validate_redirect_uri(redirect_uri: str | AnyUrl | None, allowed_patterns: list[str] | None) -> bool
Validate a redirect URI against allowed patterns. Args:
  • redirect_uri: The redirect URI to validate
  • allowed_patterns: List of allowed patterns. If None, defaults to localhost. If empty list, all URIs are allowed.
Returns:
  • True if the redirect URI is allowed