I have a xamarin mobile app that users Azure ad to authenticate it's users.
I would like to use the the token that is stored on the app to access data on an api. I have this working on an old api but I have created an asp.net core api and i would like to use the same token as i slowly migrate the data access from one api to the other.
I have set up access in the asp.net core startup class as follows
services.AddAuthentication(sharedoptions =>
{
sharedoptions.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme;
sharedoptions.DefaultChallengeScheme = JwtBearerDefaults.AuthenticationScheme;
})
.AddJwtBearer(options =>
{
options.Authority = "https://login.microsoftonline.com/{ad name}.onmicrosoft.com";
options.Audience = "api://{app service guid}";
options.TokenValidationParameters = new `enter code here`Microsoft.IdentityModel.Tokens.TokenValidationParameters
{
ValidateIssuer = true,
ValidateAudience = true,
ValidAudiences = new List<String> { "{app service guid}" },
ValidIssuers = new List<string> { "[https://login.microsoftonline.com/{Azure AD guid}/v2.0/token"}
};
});
I test with post man and get unauthorised status on the asp.net core api, but an OK (authorised) status on the old api so i know the token is working.
Does my set up appear to be correct or am i missing some configuration?