Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
a2fc284
Add error handling logic for token revocation.
aavasthy Jan 5, 2026
819c0fb
Merge branch 'master' into users/aavasthy/tokenrevocation
aavasthy Jan 6, 2026
dcbf04f
Update code and only implement AAD token revocation with claim challe…
aavasthy Jan 8, 2026
de886f3
merge with master
aavasthy Jan 8, 2026
0b87410
Merge branch 'master' into users/aavasthy/tokenrevocation
aavasthy Jan 8, 2026
ea91852
Merge with master
aavasthy Mar 17, 2026
b0c8e97
Update test
aavasthy Mar 17, 2026
2eeeee0
Fix spacing
aavasthy Mar 17, 2026
9235f12
Updated AAD CAE
aavasthy Apr 2, 2026
c046697
Merge with master
aavasthy Apr 2, 2026
ec5719b
Update token reset logic
aavasthy Apr 7, 2026
bf5018d
Merge branch 'master' into users/aavasthy/tokenrevocation
aavasthy Apr 7, 2026
e0007ee
Merge branch 'master' into users/aavasthy/tokenrevocation
aavasthy Apr 7, 2026
e4e07ae
Fix tests
aavasthy Apr 9, 2026
471d390
Merge with master
aavasthy Apr 9, 2026
1b890ff
Merge branch 'master' into users/aavasthy/tokenrevocation
aavasthy Apr 9, 2026
144f4de
Update file name
aavasthy Apr 10, 2026
9f0da6e
Merge with master
aavasthy Apr 10, 2026
5f4623a
Update tests
aavasthy May 18, 2026
ae85890
Resolve merge conflicts
aavasthy May 18, 2026
ce81a8a
Test fixes and code cleanup
aavasthy May 19, 2026
f9bf653
Merge branch 'main' into users/aavasthy/tokenrevocation
aavasthy May 19, 2026
48bab64
Update chnagelog
aavasthy May 19, 2026
533e120
Update based off review comments.
aavasthy May 20, 2026
9f49175
Merge with main
aavasthy May 20, 2026
1c9bbc4
Fix format
aavasthy May 20, 2026
ea8f31c
Resolve merge conflicts
aavasthy Jun 4, 2026
20f9455
Resolve merge conflicts with main
aavasthy Jun 11, 2026
7514cfd
Merge branch 'main' into users/aavasthy/tokenrevocation
aavasthy Jun 11, 2026
1eca662
Merge branch 'main' into users/aavasthy/tokenrevocation
aavasthy Jun 12, 2026
cbd5104
Merge branch 'main' into users/aavasthy/tokenrevocation
aavasthy Jun 17, 2026
0301653
Resolve merge conflicts.
aavasthy Jun 18, 2026
2ced50e
Resolve merge conflicts.
aavasthy Jun 18, 2026
45fb7d9
Code clean up
aavasthy Jun 18, 2026
2d10ba2
Fixed for review comment for parsing
aavasthy Jun 18, 2026
64959e3
Merge branch 'main' into users/aavasthy/tokenrevocation
aavasthy Jun 18, 2026
af0df56
Merge branch 'main' into users/aavasthy/tokenrevocation
aavasthy Jun 18, 2026
b73b994
Merge branch 'main' into users/aavasthy/tokenrevocation
aavasthy Jun 18, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ namespace Microsoft.Azure.Cosmos
{
using System;
using System.Globalization;
using System.Net;
using System.Threading.Tasks;
using global::Azure.Core;
using Microsoft.Azure.Cosmos.Core.Trace;
Expand All @@ -18,7 +19,7 @@ internal sealed class AuthorizationTokenProviderTokenCredential : AuthorizationT
private const string InferenceTokenPrefix = "Bearer ";
internal readonly TokenCredentialCache tokenCredentialCache;
private bool isDisposed = false;

internal readonly TokenCredential tokenCredential;

public AuthorizationTokenProviderTokenCredential(
Expand Down Expand Up @@ -116,5 +117,78 @@ public override void Dispose()
this.tokenCredentialCache.Dispose();
}
}

/// <summary>
/// Attempts to handle CAE (Continuous Access Evaluation) token revocation.
/// Extracts claims challenge from WWW-Authenticate header and resets cache for retry.
/// </summary>
/// <param name="statusCode">HTTP status code from the response</param>
/// <param name="headers">Response headers containing WWW-Authenticate</param>
/// <returns>True if CAE revocation detected and request should be retried; false otherwise</returns>
internal bool TryHandleCaeRevocation(
HttpStatusCode statusCode,
INameValueCollection headers)
{
if (statusCode != HttpStatusCode.Unauthorized || headers == null)
{
return false;
}

string wwwAuth = headers[HttpConstants.HttpHeaders.WwwAuthenticate];
if (string.IsNullOrEmpty(wwwAuth))
{
return false;
}

// Check for CAE claims challenge indicators
bool hasCaeIndicators = wwwAuth.IndexOf("insufficient_claims", StringComparison.OrdinalIgnoreCase) >= 0
|| wwwAuth.IndexOf("claims=", StringComparison.OrdinalIgnoreCase) >= 0;

if (!hasCaeIndicators)
{
return false;
}

string claimsChallenge = AuthorizationTokenProviderTokenCredential.ExtractClaimsFromWwwAuthenticate(wwwAuth);

// Reset cache with claims challenge for next token request
this.tokenCredentialCache.ResetCachedToken(claimsChallenge);

DefaultTrace.TraceInformation(
"AAD CAE revocation detected. Token cache reset with claims challenge. " +
"Request will be retried with fresh token including claims. HasClaims={0}",
claimsChallenge != null);

return true;
}

/// <summary>
/// Extracts the claims challenge from the WWW-Authenticate header value.
/// </summary>
/// <param name="wwwAuthenticateHeader">WWW-Authenticate header value</param>
/// <returns>Base64-encoded claims string, or null if not present</returns>
private static string ExtractClaimsFromWwwAuthenticate(string wwwAuthenticateHeader)
{
if (string.IsNullOrEmpty(wwwAuthenticateHeader))
{
return null;
}

const string claimsPrefix = "claims=\"";
int claimsIndex = wwwAuthenticateHeader.IndexOf(claimsPrefix, StringComparison.OrdinalIgnoreCase);
if (claimsIndex < 0)
{
return null;
}

int startIndex = claimsIndex + claimsPrefix.Length;
int endIndex = wwwAuthenticateHeader.IndexOf("\"", startIndex, StringComparison.Ordinal);
if (endIndex < 0)
{
return null;
}

return wwwAuthenticateHeader.Substring(startIndex, endIndex - startIndex);
}
}
}
Loading
Loading