Get an email address from an OpenID provider using DotNetOpenAuth

I cannot get the email address returned in the GetExtension method, but it is included in the URL that Google sends me (the OP I'm testing with).

 if (Page.IsPostBack) { using (var openid = new OpenIdRelyingParty()) { var request = openid.CreateRequest(Request.Form["openid_identifier"]); var fetch = new FetchRequest(); fetch.Attributes.Add(new AttributeRequest(WellKnownAttributes.Contact.Email, true)); request.AddExtension(fetch); request.RedirectToProvider(); } } else { using (var openid = new OpenIdRelyingParty()) { var response = openid.GetResponse(); if (response != null) { switch (response.Status) { case AuthenticationStatus.Authenticated: var claimsResponse = response.GetExtension<FetchRequest>(); break; case AuthenticationStatus.Canceled: //this.loginCanceledLabel.Visible = true; break; case AuthenticationStatus.SetupRequired: //this.loginFailedLabel.Visible = true; break; // We don't need to handle SetupRequired because we're not setting // IAuthenticationRequest.Mode to immediate mode. ////case AuthenticationStatus.SetupRequired: //// break; } } } } 

Does anyone know what is wrong?

+6
source share
2 answers

Try using the following code:

 switch (response.Status) { case AuthenticationStatus.Authenticated: var fetch = response.GetExtension<FetchResponse>(); string email = String.Empty; if (fetch != null) { email = fetch.GetAttributeValue(WellKnownAttributes.Contact.Email); } break; //... } 
+6
source

None of the above worked for me (using PayPal Access as an identifier) ​​in C #

Below I worked for me:

  OpenIdRelyingParty openid = new OpenIdRelyingParty(); protected void Page_Load(object sender, EventArgs e) { var response = openid.GetResponse(); if (response != null) { switch (response.Status) { case AuthenticationStatus.Authenticated: if (this.Request.Params["openid.ext1.value.alias1"] != null) { Response.Write(this.Request.Params["openid.ext1.value.alias1"]); Response.Write(this.Request.Params["openid.ext1.value.alias2"]); } else { Response.Write("Alias wrong"); } break; } } } protected void loginButton_Click(object sender, EventArgs e) { var openidRequest = openid.CreateRequest(openIdBox.Text); var fetch = new FetchRequest(); fetch.Attributes.AddRequired(WellKnownAttributes.Contact.Email); fetch.Attributes.AddRequired(WellKnownAttributes.Name.FullName); openidRequest.AddExtension(fetch); openidRequest.RedirectToProvider(); } 
+2
source

Source: https://habr.com/ru/post/886850/


All Articles