private ActionResult ValidateCredential(HttpContextBase httpContext, CredentialPrincipal principal, ICredentialValidator validator) { //获取凭证提供者服务 var credentialProvider = this.CredentialProvider; if(credentialProvider == null) throw new MissingMemberException(this.GetType().FullName, "CredentialProvider"); //如果指定的主体为空,或对应的凭证编号不存在,或对应的凭证已过期则返回未验证结果 if(principal == null || principal.Identity == null || !credentialProvider.Validate(principal.Identity.CredentialId)) return new HttpUnauthorizedResult(); //使用凭证验证器对指定的凭证进行验证,如果验证失败 if(validator != null && !validator.Validate(principal.Identity.Credential)) { //如果当前请求的路径是主页,并且是从登录页面跳转而来的返回特定的结果 if(httpContext.Request.Path == "/" && httpContext.Request.UrlReferrer != null && string.Equals(httpContext.Request.UrlReferrer.LocalPath, AuthenticationUtility.GetLoginUrl(), StringComparison.OrdinalIgnoreCase)) return new HttpStatusCodeResult(444, "Invalid Credential"); return new HttpStatusCodeResult(System.Net.HttpStatusCode.Forbidden); } //返回空,表示成功 return null; }
public CredentialRegisterEventArgs(CredentialPrincipal principal, bool renewal = false) { this.IsRenewal = renewal; this.Principal = principal ?? throw new ArgumentNullException(nameof(principal)); }