/// <summary> /// Override to Web API filter method to handle Basic Auth check /// </summary> /// <param name="actionContext"></param> public override void OnAuthorization(HttpActionContext actionContext) { if (_active) { var credentials = ParseAuthorizationHeader(actionContext); if (credentials == null) { Challenge(actionContext); return; } var userService = _serviceFactory.CreateUserService(); var user = userService.GetUser(credentials.Item1, credentials.Item2); if (user == null) { Challenge(actionContext); return; } var identity = new MyIdentity(user.Username, true, "Basic", user.Id); var principal = new MyPrincipal(identity); Thread.CurrentPrincipal = principal; if (HttpContext.Current != null) { HttpContext.Current.User = principal; } base.OnAuthorization(actionContext); } }
public MyPrincipal(MyIdentity identity) { Identity = identity; }