[AAD token revocation]: Adds logic for handling emergency token revocation and CAE token revocation.#5549
Draft
[AAD token revocation]: Adds logic for handling emergency token revocation and CAE token revocation.#5549
Conversation
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.
Pull Request Template
Description
AAD CAE Token Revocation and Emergency Token Revocation:
When a request fails with a 401 Unauthorized status, the SDK examines the WWW-Authenticate response header for a claims challenge indicator (such as "insufficient_claims" or "claims="). If detected, it extracts the base64-encoded claims string and merges it with the client capability "cp1" (indicating CAE support). The SDK then requests a new token from Azure AD using this merged claims object and automatically retries the original request with the refreshed token. To prevent infinite retry loops, a retry threshold of one attempt is enforced, meaning the SDK will retry once after token refresh but fail if the second attempt also returns 401. The service can signal token revocation in two ways: CAE (Continuous Access Evaluation) revocation or emergency token revocation, but the SDK handles both scenarios identically by extracting claims, requesting a new token, and retrying the request.
Where revocation is enforced
Revocation rules are evaluated by the routing gateway (compute gateway) on every HTTP request it receives. Any call that goes over HTTP to the gateway endpoint can get a 401/5013 + WWW-Authenticate
response.
RNTBD (direct TCP to replicas) does NOT go through the routing gateway — so direct-mode document CRUD is not subject to revocation at the gateway level.
Gateway Mode
CreateItemAsync,ReadItemAsync,QueryItemsAsyncGatewayStoreModel→GatewayStoreClientClientRetryPolicy.HandleUnauthorizedResponseCreateDatabaseAsync,DeleteContainerAsyncGatewayStoreModel(always gateway)ClientRetryPolicyGET /)GatewayAccountReadercatch when TryHandleRevocationExceptionGET /colls/)ClientCollectionCache→GatewayStoreModelTaskHelper+ClientRetryPolicyGET /pkranges)PartitionKeyRangeCache→GatewayStoreModelClientRetryPolicyDirect Mode
CreateItemAsyncCreateDatabaseAsyncClientRetryPolicyGET /)GatewayAccountReaderretryGET /addresses/)GatewayAddressCachecatch whenretryGET /colls/)ClientCollectionCache+ClientRetryPolicyGET /pkranges)ClientRetryPolicyRetry Flow (all 9 steps verified in code)
WWW-Authenticate: Bearer error="insufficient_claims", claims="<base64>"ClientRetryPolicy.ShouldRetryInternalAsyncchecks for 401 + substatus 5013 OR presence ofWWW-AuthenticateheaderExtractClaimsFromWwwAuthenticateparsesclaims="<base64>"from the headerTokenCredentialCache.ResetCachedToken(claims)clears cached token and stores the claims challengeMergeClaimsWithClientCapabilitiesmerges the server'snbfclaim with the SDK'sxms_cc/cp1capabilitytokenCredential.GetTokenAsync(new TokenRequestContext(claims: mergedClaims))sent to EntraMaxCaeRevocationRetryCount = 1— if the retry also gets 401, the SDK throws to the callerPlease delete options that are not relevant.
Closing issues
To automatically close an issue: closes #IssueNumber