public class CustomAuthorize : AuthorizeAttribute { public override void OnAuthorization(HttpActionContext actionContext) { base.OnAuthorization(actionContext); if (actionContext.Request.Headers.Authorization != null) { // get value from header string authenticationToken = Convert.ToString(actionContext.Request.Headers.Authorization); //authenticationTokenPersistant // it is saved in some data store // i will compare the authenticationToken sent by client with // authenticationToken persist in database against specific user, and act accordingly string authenticationTokenPersistant = null; if (authenticationTokenPersistant != authenticationToken) { HttpContext.Current.Response.AddHeader("authenticationToken", authenticationToken); HttpContext.Current.Response.AddHeader("AuthenticationStatus", "NotAuthorized"); actionContext.Response = actionContext.Request.CreateResponse(HttpStatusCode.Forbidden); return; } HttpContext.Current.Response.AddHeader("authenticationToken", authenticationToken); HttpContext.Current.Response.AddHeader("AuthenticationStatus", "Authorized"); return; } actionContext.Response = actionContext.Request.CreateResponse(HttpStatusCode.ExpectationFailed); actionContext.Response.ReasonPhrase = "Please provide valid inputs"; } }
Some important link
Authentication 1. http://adamalbrecht.com/2014/09/22/authorization-with-angular-and-ui-router/ 2. http://weblog.west-wind.com/posts/2013/Apr/18/A-WebAPI-Basic-Authentication-Authorization-Filter 3. https://msdn.microsoft.com/en-us/library/ff649096.aspx 4. http://codeidol.com/community/dotnet/example-adding-users-to-roles/16971/ 5. https://medium.com/opinionated-angularjs/techniques-for-authentication-in-angularjs-applications-7bbf0346acec Authentication Important 0. https://github.com/MikeWasson/LocalAccountsApp 1. http://stackoverflow.com/questions/11775594/how-to-secure-an-asp-net-web-api/21634723#21634723 2. http://blog.novanet.no/anti-forgery-tokens-using-mvc-web-api-and-angularjs/ 3. http://www.toptal.com/web/cookie-free-authentication-with-json-web-tokens-an-example-in-laravel-and-angularjs 4. https://curah.microsoft.com/202661/angularjs-authentication-resources 5. http://stackoverflow.com/questions/5507234/how-to-use-basic-auth-and-jquery-and-ajax
0 Comments