I have created a web api in .NET 5 and then I published it on Azure.
Here how I configured the web api in my startup:
public void ConfigureServices(IServiceCollection services)
{
services.AddMicrosoftIdentityWebApiAuthentication(Configuration, "AzureAd");
...
}
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
...
app.UseAuthentication();
app.UseAuthorization();
app.UseEndpoints(endpoints =>
{
endpoints
.MapControllers()
.RequireAuthorization();
});
}
And that is the appsettings.json:
"AzureAd": {
"Instance": "https://login.microsoftonline.com/",
"Domain": "***.com", //Domain name configured in Azure
"TenantId": "***", // Tenant Id configured in Azure
"ClientId": "***", // Client Id configured in Azure
"CallbackPath": "/signin-oidc"
}
Now I enabled Azure AD Authentication. Here the steps:
I configured the platform
Now, I open postman and I configure authentication for my test:
When I click on Get New Access Token, I get it correctly:
But now, if I call my API I get 401 Unauthorized error:
What is still wrong in my configuration? Any help please?
Thank you