I built an Angular application following this example: https://github.com/microsoftgraph/msgraph-training-angularspa
I'm able to login and even authenticate to MS Graph from the Angular app.
I'm trying to pass the token to an API service that I have created as well. However I keep getting the below error:
WWW-Authenticate: Bearer error="invalid_token", error_description="The signature is invalid"
I've tried everything possible so far was no luck. I continue to get this error. I've tried the AzureADBearer
library:
services.AddAuthentication(AzureADDefaults.BearerAuthenticationScheme)
.AddAzureADBearer(options => Configuration.Bind("AzureAd", options));
services.Configure<JwtBearerOptions>(AzureADDefaults.JwtBearerAuthenticationScheme, options =>
{
options.Authority += "/v2.0";
options.TokenValidationParameters.ValidAudiences = new string[]
{
options.Audience, $"api://{options.Audience}"
};
options.TokenValidationParameters.ValidateIssuer = false;
options.TokenValidationParameters.IssuerValidator = AadIssuerValidator.GetIssuerValidator(options.Authority).Validate;
});
I've also tried the Microsoft.Identity.Web
library but I'm getting the same error:
services.AddProtectedWebApi(Configuration);
I've been searching for few days now, I've found others with the same problem but so far no clear solution. Any help would be appreciated.
EDIT
I'm trying to build an application for my organization that uses our AzureAD for authentication. The application has Angular frontend with aspnetcore webapi as backend. I'm not too particular on how to get this achieved. Just looking for away to get it done.
https://sts.windows.net/guid
. You can inspect the token at e.g. jwt.ms. – juunas