I have integrated MembershipReboot with a Breeze SPA application and the login and authorisztion work as expected. In the BreezeController.cs I have added the code below to capture an authorization failure.
[AttributeUsageAttribute(AttributeTargets.Class | AttributeTargets.Method, Inherited = true, AllowMultiple = true)]
public class AuthorizeAttribute : System.Web.Http.Filters.AuthorizationFilterAttribute
{
public override void OnAuthorization(System.Web.Http.Controllers.HttpActionContext actionContext)
{
base.OnAuthorization(actionContext);
////check authentication and return if not authorized
if (actionContext != null)
{
if (!actionContext.RequestContext.Principal.Identity.IsAuthenticated)
{
actionContext.Response = actionContext.ControllerContext.Request.CreateResponse(System.Net.HttpStatusCode.Redirect);
System.Web.HttpContext.Current.Server.ClearError();
System.Web.HttpContext.Current.Response.Redirect("/UserAccount/Home",true);
//***********
//REDIRECT BEING CAUGHT BY ANGULAR ERROR HANDLER!!!
//**********
System.Web.HttpContext.Current.ApplicationInstance.CompleteRequest();
}
}
}
}
The lack of Authorization is caught when the code below is called:
[System.Web.Http.HttpGet]
[ValidateAntiForgeryToken]
[Authorize]
public string Metadata()
{
return _repository.Metadata;
}
However the redirect code is being loaded into the Toast error handler and displayed as an error and the redirect is not working.
Any ideas how I can get the code to run as opposed to being loaded into the error screen?
Handle the failed promise and examine the error object. You should find the status code in there that tells you this is an authorization failure. Now redirect as appropriate for your app rather than reporting the error to screen.
I think I'd put this "interceptor" inside my "DataService"/"DataContext" abstraction so that all Breeze calls make use of it. Who know, you might extend the EntityManager with it. Haven't thought about it much.
You might want to share this "interceptor" with all of us when you get it working. The community loves contributions. :-)