protected void Page_Load(object sender, EventArgs e) { if (Page.IsPostBack) { return; } if (!RegistrationSettings.Enabled) { Registration.Visible = false; OpenRegistration.Visible = false; return; } var unregistered = Request[ResultCodeKey] == "unregistered"; if (unregistered) { UnregisteredMessage.Visible = true; PageContent.Visible = false; Registration.Visible = false; } ConfirmMessage.Visible = Request[ResultCodeKey] == "confirm"; InactiveMessage.Visible = Request[ResultCodeKey] == "inactive"; InvalidMessage.Visible = Request[ResultCodeKey] == "invalid-invitation-code"; OpenRegistration.Visible = !RegistrationSettings.RequiresInvitation; // check if an invitation code is provided var invitation = Request[InvitationCodeKey]; InvitationCode.Text = invitation; var question = GetChallengeQuestion(invitation); if (!string.IsNullOrWhiteSpace(question)) { // go directly to the challenge question/answer EnableChallenge(question); } // pass on the sign-in post if it exists var fam = new CrmFederationAuthenticationModule(Context); if (fam.CanReadSignInResponse(Request, true)) { fam.AddSignInResponseParametersToForm(Context, Form); } else { const string continueMessage = "Continue to identity provider"; SubmitInvitationCodeButton.Text = continueMessage; SubmitChallengeAnswerButton.Text = continueMessage; SubmitOpenRegistrationButton.Text = continueMessage; } }
protected void SubmitChallengeAnswerButton_Click(object sender, EventArgs args) { if (!Page.IsValid) { return; } var invitation = InvitationCode.Text; var answer = ChallengeAnswer.Text; var returnUrl = Request[ReturnUrlKey]; var fam = new CrmFederationAuthenticationModule(Context); if (fam.CanReadSignInResponse(Request, true)) { // this is already a sign-in post, authenticate the user fam.TryHandleSignInResponse(Context, returnUrl, invitation, answer, RegistrationSettings); } else { // redirect to get the sign-in token fam.RedirectToSignIn(Context, returnUrl, invitation, answer, RegistrationSettings); } }
public virtual bool TryHandleImmediateAcsRedirect(HttpContext context) { var signInContext = new Dictionary <string, string> { { LiveIdTokenKey, context.Request["stoken"] }, { ReturnUrlKey, context.Request[ReturnUrlKey] }, }; var fam = new CrmFederationAuthenticationModule(context); var signInUrl = fam.GetSignInRequestUrl(signInContext); TraceInformation("TryHandleImmediateAcsRedirect", "signInUrl={0}", signInUrl); context.RedirectAndEndResponse(signInUrl); return(true); }
protected void InvitationCodeCustomValidator_ServerValidate(object sender, ServerValidateEventArgs args) { // check that the invitation code exists var invitationCode = InvitationCode.Text; var question = GetChallengeQuestion(invitationCode); if (!string.IsNullOrWhiteSpace(question)) { // display the challenge question EnableChallenge(question); args.IsValid = true; return; } if (!RegistrationSettings.RequiresChallengeAnswer) { // challenge answer is optional and this account does not have a question var returnUrl = Request[ReturnUrlKey]; var fam = new CrmFederationAuthenticationModule(Context); if (fam.CanReadSignInResponse(Request, true)) { // this is already a sign-in post, authenticate the user fam.TryHandleSignInResponse(Context, returnUrl, invitationCode, null, RegistrationSettings); } else { // redirect to get the sign-in token fam.RedirectToSignIn(Context, returnUrl, invitationCode, null, RegistrationSettings); } args.IsValid = true; return; } args.IsValid = false; }
protected void Page_Load(object sender, EventArgs e) { var settings = FederationCrmConfigurationManager.GetUserRegistrationSettings(); var invitationCodeKey = settings.InvitationCodeKey ?? "invitation"; var returnUrlKey = settings.ReturnUrlKey ?? "returnurl"; var liveIdTokenKey = settings.LiveIdTokenKey ?? "live-id-token"; var context = new Dictionary <string, string> { { returnUrlKey, Request[returnUrlKey] }, }; if (!string.IsNullOrWhiteSpace(Request[invitationCodeKey])) { context.Add(invitationCodeKey, Request[invitationCodeKey]); } if (!string.IsNullOrWhiteSpace(Request[liveIdTokenKey])) { context.Add(liveIdTokenKey, Request[liveIdTokenKey]); } var fam = new CrmFederationAuthenticationModule(Context); var manager = ScriptManager.GetCurrent(Page); if (manager == null) { return; } var script = new ScriptReference("~/js/acs.js"); manager.Scripts.Add(script); var reference = new ScriptReference(fam.GetHomeRealmDiscoveryMetadataFeedUrl(callback: "HandleSigninPage", context: context)); manager.Scripts.Add(reference); }
protected void SubmitOpenRegistrationButton_Click(object sender, EventArgs args) { if (!Page.IsValid) { return; } var attributes = new Dictionary <string, string> { { "firstname", ContentUtility.HtmlEncode(FirstName.Text) }, { "lastname", ContentUtility.HtmlEncode(LastName.Text) }, { "emailaddress1", ContentUtility.HtmlEncode(Email.Text) }, }; var returnUrl = Request[ReturnUrlKey]; if (!string.IsNullOrWhiteSpace(returnUrl)) { attributes.Add(ReturnUrlKey, returnUrl); } var fam = new CrmFederationAuthenticationModule(Context); if (fam.CanReadSignInResponse(Request, true)) { // this is already a sign-in post, authenticate the user fam.TryHandleSignInResponse(Context, attributes, RegistrationSettings); } else { // redirect to get the sign-in token fam.RedirectToSignIn(Context, attributes); } }