skip to Main Content

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


  1. You have marked your controller with the [Authorize] attribute.

    This triggers the need to sign in to access the API.

    Login or Signup to reply.
  2. 2 reasons:

    • [Authorize] attribute on your controller
    • AuthorizeFilter with policy which requires authenticated user

    You should remove both of them to allow non-authenticated users

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search