private void contextAuthenticateRequest(object sender, EventArgs e) { HttpApplication app = ((HttpApplication)(sender)); ApplicationServices appServices = new ApplicationServices(); string authorization = app.Request.Headers["Authorization"]; if (!(String.IsNullOrEmpty(authorization))) { // validate auth header if (authorization.StartsWith("Basic", StringComparison.CurrentCultureIgnoreCase)) { ValidateUserIdentity(app, authorization); } else if (authorization.StartsWith("Bearer ", StringComparison.CurrentCultureIgnoreCase)) { ValidateUserToken(app, authorization.Substring(7)); } } else { if (!(appServices.RequiresAuthentication(app.Context.Request))) { return; } if (appServices.AuthenticateRequest(app.Context)) { return; } RequestAuthentication(app); } }
private void contextAuthenticateRequest(object sender, EventArgs e) { HttpApplication app = ((HttpApplication)(sender)); ApplicationServices appServices = new ApplicationServices(); if (!(appServices.RequiresAuthentication(app.Context.Request))) { return; } if (appServices.AuthenticateRequest(app.Context)) { return; } HttpCookie c = app.Request.Cookies[FormsAuthentication.FormsCookieName]; if (c != null) { FormsAuthenticationTicket t = FormsAuthentication.Decrypt(c.Value); if (!(String.IsNullOrEmpty(t.Name))) { return; } } string authorization = app.Request.Headers["Authorization"]; if (String.IsNullOrEmpty(authorization)) { RequestAuthentication(app); } else if (authorization.StartsWith("Basic", StringComparison.CurrentCultureIgnoreCase)) { ValidateUserIdentity(app, authorization); } else { RequestAuthentication(app); } }