public string GetFormHtml(int lcid) { var dynamicContents = new Dictionary <string, string>(_dynamicContents) { [Constants.DynamicContentLabels.markerPageIntroductionTitle] = GetPresentationResource(Constants.ResourceNames.PageIntroductionTitle, lcid), [Constants.DynamicContentLabels.markerPageIntroductionText] = GetPresentationResource(Constants.ResourceNames.PageIntroductionText, lcid), [Constants.DynamicContentLabels.markerPageTitle] = GetPageTitle(lcid), [Constants.DynamicContentLabels.markerSubmitButton] = GetPresentationResource(Constants.ResourceNames.SubmitButtonLabel, lcid), [Constants.DynamicContentLabels.markerLoginPagePasswordLabel] = string.Empty }; if (_ex != null) { dynamicContents[Constants.DynamicContentLabels.markerPageIntroductionText] = GetPresentationResource(Constants.ResourceNames.FailedLogin, lcid); } dynamicContents[Constants.DynamicContentLabels.markerLoginPageUsername] = _username; string authPageTemplate = ResourceHandler.GetResource(Constants.ResourceNames.AuthPageTemplate, lcid); return(Replace(authPageTemplate, dynamicContents)); }
public IAdapterPresentation TryEndAuthentication(IAuthenticationContext authContext, IProofData proofData, HttpListenerRequest request, out Claim[] outgoingClaims) { if (null == authContext) { throw new ArgumentNullException(nameof(authContext)); } outgoingClaims = new Claim[0]; if (proofData?.Properties == null || !proofData.Properties.ContainsKey(Constants.PropertyNames.Password)) { throw new ExternalAuthenticationException(ResourceHandler.GetResource(Constants.ResourceNames.ErrorNoAnswerProvided, authContext.Lcid), authContext); } if (!authContext.Data.ContainsKey(Constants.AuthContextKeys.Identity)) { Trace.TraceError(string.Format("TryEndAuthentication Context does not contains userID.")); throw new ArgumentOutOfRangeException(Constants.AuthContextKeys.Identity); } if (!authContext.Data.ContainsKey(Constants.AuthContextKeys.Identity)) { throw new ArgumentNullException(Constants.AuthContextKeys.Identity); } string username = (string)authContext.Data[Constants.AuthContextKeys.Identity]; string password = (string)proofData.Properties[Constants.PropertyNames.Password]; try { if (PasswordValidator.Validate(username, password)) { outgoingClaims = new Claim[] { new Claim(Constants.AuthenticationMethodClaimType, Constants.UsernamePasswordMfa) }; // null == authentication succeeded. return(null); } else { return(CreateAdapterPresentationOnError(username, new UsernamePasswordValidationException("Authentication failed", authContext))); } } catch (Exception ex) { throw new UsernamePasswordValidationException(string.Format("UsernamePasswordSecondFactor password validation failed due to exception {0} failed to validate password {0}", ex), ex, authContext); } }
public IAdapterPresentation BeginAuthentication(Claim identityClaim, HttpListenerRequest request, IAuthenticationContext authContext) { if (null == identityClaim) { throw new ArgumentNullException(nameof(identityClaim)); } if (null == authContext) { throw new ArgumentNullException(nameof(authContext)); } if (String.IsNullOrEmpty(identityClaim.Value)) { throw new InvalidDataException(ResourceHandler.GetResource(Constants.ResourceNames.ErrorNoUserIdentity, authContext.Lcid)); } // save the current user ID in the encrypted blob. authContext.Data.Add(Constants.AuthContextKeys.Identity, identityClaim.Value); return(CreateAdapterPresentation(identityClaim.Value)); }
protected string GetMetadataResource(string resourceName, int lcid) { return(ResourceHandler.GetResource(resourceName, lcid)); }
protected string GetPresentationResource(string resourceName, int lcid) { return(ResourceHandler.GetResource(resourceName, lcid)); }