Member authorisation - custom 401
# help-with-umbraco
r
Hello! I'm trying to create a redirect back to the login page for users when using an
UmbracoAPIController
and the
UmbracoMemberAuthorize
attribute.
Copy code
public class MyController : UmbracoApiController
{
  // ...
  [HttpGet]
  [UmbracoMemberAuthorize]
  public async Task<IActionResult> MyFunction(string param1)
  {
    // Some code!
  }
}
The above gives me an empty 401 response code and I'm trying to redirect the user back to the login page. I could take the
[UmbracoMemberAuthorize]
attribute off and deal with auth myself, but feels like there should be a better solution that I don't understand. I've tried the solution here https://our.umbraco.com/forum/using-umbraco-and-getting-started/111100-umbraco-10-redirect-unauthenticated-user-challange-result-to-an-umbraco-page but this hasn't worked. Perhaps it's as I'm using OpenID, but
authorizeResult
is always giving a
Succeeded
. Any pointers on this would be really helpful!
d
Have you tried using a SurfaceController for this instead of an UmbracoApiController? UmbracoApiControllers are meant to be accessed asynchronously, so an empty 401 response would make sense. I'm not 100% sure, but I think the SurfaceController behaves differently if you add the authorization attribute onto it.
23 Views