dasiths / NEasyAuthMiddleware

Azure App Service Authentication (EasyAuth) middleware for ASP.NET CORE with fully customizable components and support for local debugging
MIT License
12 stars 6 forks source link

[Authorize(Roles = "Resource.Read")] #1

Closed AidanTfL closed 5 years ago

AidanTfL commented 5 years ago

image

I have an ASP.NET Core React Project. It has 1 controller that is the C# backend API to my React frontend. This project is deployed in to an Azure App Service with EasyAuth enabled.

I've been using the NEasyAuthMiddleware package without the Authorize attribute and it has worked great. NEasyAuthMiddleware has been fantastic for allowing us to mock EasyAuth when dev'ing locally/ running tests, and fetch the /auth/.me in an intuitive way through enabling the use of HttpContext.User.Identity.Name. Great work - thanks for this.

The issue I am experiencing is to do with caching. When the token expires, the browser still attempts to make calls to the backend API from a cached version. All these calls return a 302 redirect. This shows as a CORS error from Microsoft Login Server.

To resolve this, I thought it'd be wise to add in the [Authorize] attribute above my backend API controller class. When I do this, it doesn't seem to integrate with EasyAuth.

Instead, it displays a login popup. Is this behavior as expected?

dasiths commented 5 years ago
function refreshTokens() {
  let refreshUrl = "/.auth/refresh";
  $.ajax(refreshUrl) .done(function() {
    console.log("Token refresh completed successfully.");
  }) .fail(function() {
    console.log("Token refresh failed. See application logs for details.");
  });
}