Skip to content

Commit c09d803

Browse files
Fix case where MRRT is disabled but we may have multiple token sets with one matching the audience
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
1 parent 2b0439d commit c09d803

1 file changed

Lines changed: 11 additions & 7 deletions

File tree

src/auth0_server_python/auth_server/server_client.py

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -615,13 +615,17 @@ async def get_access_token(
615615
if ts.get("audience") == audience and (not scope or ts.get("scope") == scope):
616616
token_set = ts
617617
break
618-
elif ts.get("audience") != audience and not self._use_mrrt:
619-
# We have a token but for a different audience but since MRRT is disabled,
620-
# we cannot use the RT to get a new AT for this audience
621-
raise AccessTokenError(
622-
AccessTokenErrorCode.INCORRECT_AUDIENCE,
623-
"The access token for the requested audience is not available and Multi-Resource Refresh Tokens are disabled."
624-
)
618+
if ts.get("audience") == audience and (not scope or ts.get("scope") == scope):
619+
token_set = ts
620+
break
621+
622+
# After loop: if no matching token found and MRRT disabled, check if we need to error
623+
if not token_set and not self._use_mrrt and state_data_dict.get("token_sets"):
624+
# We have tokens but none match, and we can't use RT to get a new one
625+
raise AccessTokenError(
626+
AccessTokenErrorCode.INCORRECT_AUDIENCE,
627+
"The access token for the requested audience is not available and Multi-Resource Refresh Tokens are disabled."
628+
)
625629

626630
# If token is valid, return it
627631
if token_set and token_set.get("expires_at", 0) > time.time():

0 commit comments

Comments
 (0)