instead of returning hello it requires a sign in. I have tried to pass tokens etc. this works fine in the browser[cannot seem to replicate openID connect auth flow]
services.AddMicrosoftIdentityWebAppAuthentication(Configuration)
.EnableTokenAcquisitionToCallDownstreamApi()
.AddMicrosoftGraph(options =>
{
Configuration.Bind("AzureAd", options);
options.Scopes = AppSettings.GetScopes();
})
.AddInMemoryTokenCaches();
services.AddControllersWithViews(options =>
{
var policy = new AuthorizationPolicyBuilder()
.RequireAuthenticatedUser()
.Build();
options.Filters.Add(new AuthorizeFilter(policy));
});
app.UseAuthentication();
app.UseAuthorization();
above is the snippet of my start up, below is what I am trying to call
[Area("Technology")]
[ApiController]
[Route("api/tasks")]
[Authorize]
public class TaskController : Controller
{
[HttpGet("{message}")]
public ActionResult<string> GetMessage(string message)
{
_telemetry.TrackEvent($"Get Request ran with a message of {message}");
return message;
}
}
if I enter the URL in postman I just receive a html sign in page in the body. I have also tested this without the [Authorize]
2
Answers
You have marked your controller with the [Authorize] attribute.
This triggers the need to sign in to access the API.
2 reasons:
[Authorize]
attribute on your controllerAuthorizeFilter
with policy which requires authenticated userYou should remove both of them to allow non-authenticated users