Description
When creating an NAA token the generated token cannot be validated as a valid JWT using the keys from https://login.microsoftonline.com/common/discovery/keys
Your Environment
- Platform: OWA (at least)
- Host: Outlook
Expected behavior
A validatable token (where the signing key being produced is correct) to be generated. We are migrating from legacy tokens to NAA. We only use the tokens as an SSO exchange on our platform, we have no need to use the tokens with Graph or other MS products.
Current behavior
We get quite different JWTs depending on the scopes requested (we do not need to call Graph so would prefer only the openid
and profile
scopes)
No Graph (scope ['openid', 'profile']
)
The token generated is for audience https://outlook.office.com. I cannot successfully validate (server-side .net) the token, with error message Microsoft.IdentityModel.Tokens.SecurityTokenInvalidSignatureException: IDX10511: Signature validation failed. Keys tried: 'Microsoft.IdentityModel.Tokens.X509SecurityKey, KeyId: '3PaK4EfyBNQu3CtjYsa3YmhQ5E0', InternalId: '3PaK4EfyBNQu3CtjYsa3YmhQ5E0'. , KeyId: 3PaK4EfyBNQu3CtjYsa3YmhQ5E0
Graph (scope ['User.Read', 'openid', 'profile']
)
The token generated is for audience 00000003-0000-0000-c000-000000000000
, but I still cannot validate it, with the same error above.
I saw some references to validating Graph-bound tokens at AzureAD/azure-activedirectory-identitymodel-extensions-for-dotnet#609 (comment) but have not investigated whether this is the same problem I'm seeing yet.
The C# code for validation is:
JwtSecurityTokenHandler _jwtSecurityTokenHandler = new()
{
MapInboundClaims = false,
};
var validationParameters = await GetTokenValidationParametersAsync();
var result = _jwtSecurityTokenHandler.ValidateToken(userToken, validationParameters, out _);
private async Task<TokenValidationParameters> GetTokenValidationParametersAsync()
{
var configManager = new ConfigurationManager<OpenIdConnectConfiguration>(
"https://login.microsoftonline.com/common/.well-known/openid-configuration",
new OpenIdConnectConfigurationRetriever());
var openidConfiguration = await configManager.GetConfigurationAsync();
return new TokenValidationParameters
{
// We do not validate the issuer as it is specific to each tenant and we are a multi-tenant app so
// cannot validate in much of a meaningful way (or at least, we cannot use a static list easily).
ValidateIssuer = false,
ValidateAudience = true,
ValidAudience = "https://outlook.office.com",
ValidateTokenReplay = true,
IssuerSigningKeys = openidConfiguration.SigningKeys,
};
}
Steps to reproduce
- Use sample from https://learn.microsoft.com/en-gb/office/dev/add-ins/develop/enable-nested-app-authentication-in-your-add-in
- Configure token request scopes as described above
- Attempt to validate the generated token
Thank you for taking the time to report an issue. Our triage team will respond to you in less than 72 hours. Normally, response time is <10 hours Monday through Friday. We do not triage on weekends.
Activity