Open
Conversation
|
|
||
| # Invoke resolver (supports both sync and async resolvers) | ||
| try: | ||
| result = self._allowed_domains(context) |
Check failure
Code scanning / CodeQL
Non-callable called Error
Show autofix suggestion
Hide autofix suggestion
Copilot Autofix
AI about 11 hours ago
General fix: Avoid reusing the same attribute for both a list of domains and a resolver function. Maintain separate attributes for the static list and for the callable resolver so that the callable one is never a list and vice versa.
Concrete approach for this file:
- In
__init__, introduce two instance attributes:self._allowed_domains– always a list of normalized domain strings (orNoneif not set).self._domains_resolver– always either a callable (sync or async) orNone.
- When
options.domainsis a list, normalize and store it inself._allowed_domains, leavingself._domains_resolver = None. - When
options.domainsis callable, store it inself._domains_resolverand setself._allowed_domains = None. - In the later logic (around lines 145–181), change:
- The
elif callable(self._allowed_domains):branch to instead test and callself._domains_resolver. - The invocation
self._allowed_domains(context)toself._domains_resolver(context).
- The
- Ensure that any earlier uses of
self._allowed_domains(as shown) are compatible—where it’s treated as a list, it will only ever be a list; where it’s treated as callable, use the newself._domains_resolver.
This retains existing functionality (still supports both static domain lists and dynamic resolvers) while making the types consistent and eliminating the potential non‑callable call that CodeQL flags.
Suggested changeset
1
src/auth0_api_python/api_client.py
| @@ -58,6 +58,10 @@ | ||
| if not options.audience: | ||
| raise MissingRequiredArgumentError("audience") | ||
|
|
||
| # Initialize domain configuration | ||
| self._allowed_domains: Optional[list[str]] = None | ||
| self._domains_resolver = None | ||
|
|
||
| # Validate domains parameter if provided | ||
| if options.domains is not None: | ||
| if isinstance(options.domains, list): | ||
| @@ -72,7 +76,7 @@ | ||
| self._allowed_domains = [normalize_domain(d) for d in options.domains] | ||
| elif callable(options.domains): | ||
| # Dynamic resolver - store the function | ||
| self._allowed_domains = options.domains | ||
| self._domains_resolver = options.domains | ||
| else: | ||
| raise ConfigurationError( | ||
| "domains must be either a list of domain strings or a callable resolver function" | ||
| @@ -142,7 +146,7 @@ | ||
| if isinstance(self._allowed_domains, list): | ||
| allowed_domains = self._allowed_domains | ||
| # Dynamic resolver mode | ||
| elif callable(self._allowed_domains): | ||
| elif self._domains_resolver is not None and callable(self._domains_resolver): | ||
| # Build resolver context | ||
| context = { | ||
| 'request_url': request_url, | ||
| @@ -152,7 +156,7 @@ | ||
|
|
||
| # Invoke resolver (supports both sync and async resolvers) | ||
| try: | ||
| result = self._allowed_domains(context) | ||
| result = self._domains_resolver(context) | ||
| if asyncio.iscoroutine(result) or asyncio.isfuture(result): | ||
| result = await result | ||
| except Exception as e: |
Copilot is powered by AI and may make mistakes. Always verify output.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
📋 Changes
This PR implements Multiple Custom Domain (MCD) support for auth0-api-python, enabling APIs to accept tokens from multiple Auth0 custom domains with static lists, dynamic resolvers, and hybrid mode for zero-downtime domain migrations.
✨ Features
domainsparameter (static list or callable resolver) onApiClientOptionsdomainanddomainstogether for migration scenarios —domaindrives client-initiated flows (token exchange, connection tokens),domainsdrives token verificationDomainsResolvercallable with request context (DomainsResolverContext)CacheAdapterABC allows custom backends (Redis, Memcached, etc.) with a defaultInMemoryCacheimplementation🔧 API Changes
ApiClientOptionswith MCD parameters:domains,cache_ttl_seconds,cache_max_entries,cache_adapterrequest_urlandrequest_headersparameters toverify_access_token()andverify_request()for resolver contextDomainsResolverContext(TypedDict),DomainsResolver(type alias)ConfigurationError(invalid SDK config, status 500),DomainsResolverError(resolver failure, status 500)CacheAdapter(ABC),InMemoryCache(default LRU cache with TTL)📖 Documentation
README.mdwith MCD feature callout and new section 7 (Multi-Custom Domain Support)docs/MultipleCustomDomain.md— configuration modes, resolver patterns, error handling, migration guidedocs/Caching.md— default behavior, custom adapters (Redis example), tuning recommendations🧪 Testing
Manual Integration Testing
Requires an Auth0 tenant with multiple custom domains configured and a machine-to-machine application with client credentials grant enabled.
Expected: All three domains succeed. Each token's
issmatches its issuing domain.Contributor Checklist