protected override Task <HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken) { BasicAuthIdentity identity = null; switch (ServiceConfig.GetAuthenticationMode()) { case ServiceConfig.AuthenticationMode.ActiveDirectory: identity = ServiceConfig.ParseAuthorizationHeader(request); break; case ServiceConfig.AuthenticationMode.ActiveDirectorySingleUser: case ServiceConfig.AuthenticationMode.ThirdPartyProvider: identity = ServiceConfig.ParseUserCredential(); break; } if (identity == null || !ServiceConfig.OnAuthorizeUser(identity)) { return(Task.Factory.StartNew(() => { return request.CreateErrorResponse(HttpStatusCode.Unauthorized, "Missing or invalid authentication credential"); })); } Thread.CurrentPrincipal = new GenericPrincipal(identity, null); return(base.SendAsync(request, cancellationToken)); }
public static bool OnAuthorizeUser(BasicAuthIdentity identity) { if (string.IsNullOrEmpty(identity.Domain) || string.IsNullOrEmpty(identity.Name) || identity.Password.Length == 0) { return(false); } return(true); }