bool VerifyUsername(IAuthenticationCallbackInfo info) { // no username is invalid if (string.IsNullOrEmpty(info.UserName)) { return(false); } // first do a lookup of the password - this might come from a database, file, etc string password = GetPasswordForUser(info.UserName); if (password == null) { return(false); } // determine the type BasicAuthInfo basic = info as BasicAuthInfo; if (basic != null) { // we're using basic auth return(basic.Password == password); } // it wasn't basic, so it must be digest DigestAuthInfo digest = info as DigestAuthInfo; return(digest.MatchCredentials(password)); }
private bool CheckUserWithServerCallback(BasicAuthInfo info) { try { return(ServerConfig.GetConfig().Authentication.AuthenticationCallback(info)); } catch { return(false); } }
private Task<AuthenticationTicket> AuthenticateCredential(BasicAuthInfo authInfo) { AuthenticationTicket ticket = null; if (authInfo.Credential.Username == "Test" && authInfo.Credential.Password == "Password") { ClaimsIdentity identity = new ClaimsIdentity(authInfo.AuthenticationScheme); identity.AddClaim(new Claim(ClaimTypes.Name, "Test")); identity.AddClaim(new Claim(ClaimTypes.NameIdentifier, "TestId")); ClaimsPrincipal principal = new ClaimsPrincipal(identity); ticket = new AuthenticationTicket(principal, authInfo.Properties, authInfo.AuthenticationScheme); } return Task.FromResult(ticket); }
public override bool AcceptCredentials(HttpContext context, string authentication) { bool auth = true; byte[] userpass = Convert.FromBase64String(authentication); string[] up = Encoding.UTF8.GetString(userpass, 0, userpass.Length).Split(separator); m_user = up[0]; string password = up[1]; if (String.IsNullOrEmpty(this.User)) { return(false); } var config = ServerConfig.GetConfig(); if (config.Authentication.AuthenticationCallback == null) { auth = CheckConfigUserList(this.User, password); } else { var info = new BasicAuthInfo { UserName = this.User, Password = password, Realm = config.Authentication.Realm, Uri = context.Request.Path, Method = context.Request.HttpMethod }; auth = CheckUserWithServerCallback(info); } // set the user info var id = new GenericIdentity(User, this.AuthenticationMethod.ToLower()); id.IsAuthenticated = auth; var principal = new GenericPrincipal(id); context.User = principal; return(auth); }