1515 OAuthServerConfig ,
1616 RemoteAuthConfig ,
1717 OAuthProxyConfig ,
18+ # Type aliases for dynamic redirect URI configuration
19+ RedirectPatternsProvider ,
20+ RedirectSchemesProvider ,
21+ RedirectUriValidator ,
1822)
1923from .factory import (
2024 create_auth_provider ,
5357 "OAuthServerConfig" ,
5458 "RemoteAuthConfig" ,
5559 "OAuthProxyConfig" ,
60+ # Type aliases for dynamic redirect URI configuration
61+ "RedirectPatternsProvider" ,
62+ "RedirectSchemesProvider" ,
63+ "RedirectUriValidator" ,
5664 # Factory functions
5765 "create_auth_provider" ,
5866 "create_simple_jwt_provider" ,
@@ -202,6 +210,13 @@ def configure_oauth_proxy(
202210 scopes_supported : list [str ] | None = None ,
203211 revocation_endpoint : str | None = None ,
204212 redirect_path : str = "/oauth/callback" ,
213+ # Static redirect URI configuration
214+ allowed_redirect_patterns : list [str ] | None = None ,
215+ allowed_redirect_schemes : list [str ] | None = None ,
216+ # Dynamic redirect URI configuration (callables for runtime evaluation)
217+ allowed_redirect_patterns_func : RedirectPatternsProvider | None = None ,
218+ allowed_redirect_schemes_func : RedirectSchemesProvider | None = None ,
219+ redirect_uri_validator : RedirectUriValidator | None = None ,
205220 ** env_vars : str ,
206221) -> None :
207222 """Configure OAuth proxy authentication for non-DCR providers.
@@ -210,6 +225,10 @@ def configure_oauth_proxy(
210225 For each parameter, you can provide the value directly or use the
211226 corresponding *_env_var parameter to specify an environment variable name.
212227
228+ Redirect URI validation supports both static and dynamic configuration:
229+ - Static: Use allowed_redirect_patterns and allowed_redirect_schemes lists
230+ - Dynamic: Use callable functions that are evaluated at runtime for each request
231+
213232 Examples:
214233 # Direct values (backward compatible)
215234 configure_oauth_proxy(
@@ -231,11 +250,32 @@ def configure_oauth_proxy(
231250 token_verifier_config=jwt_config,
232251 )
233252
234- # Mixed (direct values with env var overrides)
253+ # Dynamic redirect URI validation with feature flags
254+ def get_allowed_patterns():
255+ # Could fetch from Amplitude, LaunchDarkly, database, etc.
256+ if amplitude.is_enabled("new-redirect-uris"):
257+ return ["https://new-app.example.com/*"]
258+ return ["https://legacy-app.example.com/*"]
259+
260+ configure_oauth_proxy(
261+ authorization_endpoint="https://auth.example.com/authorize",
262+ token_endpoint="https://auth.example.com/token",
263+ client_id="my-client",
264+ client_secret="my-secret",
265+ base_url="https://myserver.com",
266+ token_verifier_config=jwt_config,
267+ allowed_redirect_patterns_func=get_allowed_patterns,
268+ )
269+
270+ # Custom redirect URI validator for complex logic
271+ def validate_redirect_uri(uri: str) -> bool:
272+ # Custom validation logic - check database, feature flags, etc.
273+ allowed = fetch_allowed_uris_from_database()
274+ return uri in allowed
275+
235276 configure_oauth_proxy(
236- authorization_endpoint="https://default.example.com/authorize",
237- authorization_endpoint_env_var="OAUTH_AUTH_ENDPOINT", # Overrides at runtime
238- # ...
277+ # ... other config ...
278+ redirect_uri_validator=validate_redirect_uri,
239279 )
240280
241281 Args:
@@ -248,13 +288,20 @@ def configure_oauth_proxy(
248288 scopes_supported: List of OAuth scopes this proxy supports
249289 revocation_endpoint: Optional token revocation endpoint
250290 redirect_path: OAuth callback path (default: "/oauth/callback")
291+ allowed_redirect_patterns: Static list of redirect URI patterns
292+ allowed_redirect_schemes: Static list of allowed URI schemes
293+ allowed_redirect_patterns_func: Callable returning patterns (evaluated per request)
294+ allowed_redirect_schemes_func: Callable returning schemes (evaluated per request)
295+ redirect_uri_validator: Custom validator function for redirect URIs
251296 **env_vars: Environment variable names for runtime configuration
252297 - authorization_endpoint_env_var: Env var for authorization endpoint
253298 - token_endpoint_env_var: Env var for token endpoint
254299 - client_id_env_var: Env var for client ID
255300 - client_secret_env_var: Env var for client secret
256301 - base_url_env_var: Env var for base URL
257302 - revocation_endpoint_env_var: Env var for revocation endpoint
303+ - allowed_redirect_patterns_env_var: Env var for redirect patterns
304+ - allowed_redirect_schemes_env_var: Env var for redirect schemes
258305
259306 Raises:
260307 ValueError: If token_verifier_config is not provided or invalid
@@ -281,6 +328,13 @@ def configure_oauth_proxy(
281328 redirect_path = redirect_path ,
282329 scopes_supported = scopes_supported ,
283330 token_verifier_config = token_verifier_config ,
331+ # Static redirect URI configuration
332+ allowed_redirect_patterns = allowed_redirect_patterns ,
333+ allowed_redirect_schemes = allowed_redirect_schemes ,
334+ # Dynamic redirect URI configuration
335+ allowed_redirect_patterns_func = allowed_redirect_patterns_func ,
336+ allowed_redirect_schemes_func = allowed_redirect_schemes_func ,
337+ redirect_uri_validator = redirect_uri_validator ,
284338 ** env_vars ,
285339 )
286340 configure_auth (config )
0 commit comments