After upgrading my projects to 1.1.0 I'm experiencing authentication errors now against my azure AD open ID authentication.
Fiddler is showing the error as:
WWW-Authenticate: Bearer error="invalid_request", error_codes="[90010]", error_description="AADSTS90010: JWT tokens cannot be used with the UserInfo endpoint.%0d%0aTrace.
This correlates to a 400 error, BadRequest, and the user cannot login.
app.UseOpenIdConnectAuthentication(new OpenIdConnectOptions
{
AutomaticAuthenticate = true,
AutomaticChallenge = true,
ClientId = Configuration["Authentication:AzureAd:ClientId"],
Authority = Configuration["Authentication:AzureAd:AADInstance"] + Configuration["Authentication:AzureAd:TenantId"],
ClientSecret = Configuration["Authentication:AzureAd:ClientSecret"],
CallbackPath = Configuration["Authentication:AzureAd:CallbackPath"],
ResponseType = OpenIdConnectResponseType.CodeIdToken,
GetClaimsFromUserInfoEndpoint = true,
Events = new OpenIdConnectEvents
{
OnAuthenticationFailed = OnAuthenticationFailed,
OnAuthorizationCodeReceived = OnAuthorizationCodeReceived,
OnMessageReceived = OnMessageReceived,
OnTicketReceived = OnTicketRecieved,
OnTokenValidated = OnTokenValidated,
OnUserInformationReceived = OnUserInformationReceived,
OnTokenResponseReceived = OnTokenResponseRecieved,
OnRemoteFailure = OnRemoteFailure
}
private async Task OnAuthorizationCodeReceived(AuthorizationCodeReceivedContext context)
{
var aadInstance = "https://login.microsoftonline.com/";
var graphResourceId = "https://graph.windows.net";
string userObjectId = (context.Ticket.Principal.FindFirst("http://schemas.microsoft.com/identity/claims/objectidentifier"))?.Value;
ClientCredential clientCred = new ClientCredential(clientId, clientSecret);
AuthenticationContext authContext = new AuthenticationContext(aadInstance + tenant);
AuthenticationResult authResult = await authContext.AcquireTokenByAuthorizationCodeAsync(
context.ProtocolMessage.Code, new Uri(context.Properties.Items[OpenIdConnectDefaults.RedirectUriForCodePropertiesKey]), clientCred, graphResourceId);
context.HandleCodeRedemption(authResult.AccessToken, authResult.IdToken);
}
Do I need to handle the user claims differently now since i'm using a CodeIdToken and trying to use the GetClaimsFromuserInfoEndpoint option?
edit: If I comment out GetClaimsFromUserInfoEndpoint this works fine