public void SetRequiredFieldsFromRequest(ClaimsRequest requestFields) { if (requestFields.PolicyUrl != null) { privacyLink.NavigateUrl = requestFields.PolicyUrl.AbsoluteUri; } else { privacyLink.Visible = false; } dobRequiredLabel.Visible = (requestFields.BirthDate == DemandLevel.Require); countryRequiredLabel.Visible = (requestFields.Country == DemandLevel.Require); emailRequiredLabel.Visible = (requestFields.Email == DemandLevel.Require); fullnameRequiredLabel.Visible = (requestFields.FullName == DemandLevel.Require); genderRequiredLabel.Visible = (requestFields.Gender == DemandLevel.Require); languageRequiredLabel.Visible = (requestFields.Language == DemandLevel.Require); nicknameRequiredLabel.Visible = (requestFields.Nickname == DemandLevel.Require); postcodeRequiredLabel.Visible = (requestFields.PostalCode == DemandLevel.Require); timezoneRequiredLabel.Visible = (requestFields.TimeZone == DemandLevel.Require); dateOfBirthRow.Visible = !(requestFields.BirthDate == DemandLevel.NoRequest); countryRow.Visible = !(requestFields.Country == DemandLevel.NoRequest); emailRow.Visible = !(requestFields.Email == DemandLevel.NoRequest); fullnameRow.Visible = !(requestFields.FullName == DemandLevel.NoRequest); genderRow.Visible = !(requestFields.Gender == DemandLevel.NoRequest); languageRow.Visible = !(requestFields.Language == DemandLevel.NoRequest); nicknameRow.Visible = !(requestFields.Nickname == DemandLevel.NoRequest); postcodeRow.Visible = !(requestFields.PostalCode == DemandLevel.NoRequest); timezoneRow.Visible = !(requestFields.TimeZone == DemandLevel.NoRequest); }
public void Partial() { var request = new ClaimsRequest(); request.FullName = DemandLevel.Request; request.Email = DemandLevel.Require; var response = ParameterizedTest<ClaimsResponse>( TestSupport.Scenarios.ExtensionPartialCooperation, Version, request); Assert.IsNull(response.FullName); Assert.AreEqual("*****@*****.**", response.Email); }
public ClaimsResponse GetOpenIdProfileFields(ClaimsRequest request) { if (request == null) throw new ArgumentNullException("request"); ClaimsResponse fields = request.CreateResponse(); fields.BirthDate = DateOfBirth; fields.Country = countryDropdownList.SelectedValue; fields.Email = emailTextBox.Text; fields.FullName = fullnameTextBox.Text; fields.Gender = Gender; fields.Language = languageDropdownList.SelectedValue; fields.Nickname = nicknameTextBox.Text; fields.PostalCode = postcodeTextBox.Text; fields.TimeZone = timezoneDropdownList.SelectedValue; return fields; }
public ActionResult Authenticate() { var openid = new OpenIdRelyingParty(); if (openid.Response == null) { try { var req = openid.CreateRequest(Request.Form["openid_identifier"]); var fields = new ClaimsRequest { Email = DemandLevel.Require, Nickname = DemandLevel.Require }; req.AddExtension(fields); req.RedirectToProvider(); } catch (ThreadAbortException) { } catch (Exception e) { ViewData["Message"] = e.Message; } return View("Login"); } switch (openid.Response.Status) { case AuthenticationStatus.Authenticated: var fields = openid.Response.GetExtension(typeof(ClaimsResponse)) as ClaimsResponse; if (fields != null) { TempData["Email"] = fields.Email; TempData["Nickname"] = fields.Nickname; } FormsAuthentication.RedirectFromLoginPage(openid.Response.ClaimedIdentifier, true); break; case AuthenticationStatus.Canceled: ViewData["Message"] = "Canceled at provider"; return View("Login"); case AuthenticationStatus.Failed: ViewData["Message"] = openid.Response.Exception.Message; return View("Login"); } // need this rather than returning an ActionResult. return null; }
/// <summary> /// Tests equality between two <see cref="ClaimsRequest"/> structs. /// </summary> public override bool Equals(object obj) { ClaimsRequest other = obj as ClaimsRequest; if (other == null) { return(false); } return (safeEquals(this.BirthDate, other.BirthDate) && safeEquals(this.Country, other.Country) && safeEquals(this.Language, other.Language) && safeEquals(this.Email, other.Email) && safeEquals(this.FullName, other.FullName) && safeEquals(this.Gender, other.Gender) && safeEquals(this.Nickname, other.Nickname) && safeEquals(this.PostalCode, other.PostalCode) && safeEquals(this.TimeZone, other.TimeZone) && safeEquals(this.PolicyUrl, other.PolicyUrl)); }
void parameterizedPreserveVersionFromRequest(string versionTypeUri) { Dictionary<string, string> fields = new Dictionary<string, string>{ {"optional", "nickname"}, }; var req = new ClaimsRequest(); Assert.IsTrue(((IExtensionRequest)req).Deserialize(fields, null, versionTypeUri)); Assert.AreEqual(DemandLevel.Request, req.Nickname); ClaimsResponse resp = req.CreateResponse(); Assert.AreEqual(versionTypeUri, ((IExtensionResponse)resp).TypeUri); }
public AuthenticationResult Authenticate(string userIdentifier) { var openid = new OpenIdRelyingParty(); if (openid.Response == null) { // Redirect the user to the provider party. They will login, and be redirected // back here. try { var claims = new ClaimsRequest(); claims.Nickname = DemandLevel.Require; claims.FullName = DemandLevel.Require; claims.Email = DemandLevel.Require; claims.PostalCode = DemandLevel.Request; var id = Identifier.Parse(userIdentifier); var request = openid.CreateRequest(userIdentifier); request.AddExtension(claims); request.RedirectToProvider(); } catch (OpenIdException ex) { // The user may have entered an incorrectly formatted URI, the server is offline, etc. return new AuthenticationResult() { Cancelled = false, Error = ex, Success = false, Username = userIdentifier }; } } else { // The OpenID provider has processed the user's request and redirected them back here. switch (openid.Response.Status) { case AuthenticationStatus.Authenticated: // Update the member information return new AuthenticationResult() {Cancelled = false, Error = null, Success = true, Username = userIdentifier}; case AuthenticationStatus.Canceled: return new AuthenticationResult() {Cancelled = true, Error = null, Success = false, Username = userIdentifier}; case AuthenticationStatus.Failed: return new AuthenticationResult() {Cancelled = false, Error = null, Success = false, Username = userIdentifier}; } } return null; }
protected void openid_identifier_LoggingIn(object sender, OpenIdEventArgs e) { ClaimsRequest fetch = new ClaimsRequest(); fetch.Email = DemandLevel.Require; fetch.Nickname = DemandLevel.Require; fetch.FullName = DemandLevel.Request; e.Request.AddExtension(fetch); }