I can't get the email address returned in GetExtension
method, but it is included in the url that Google (the OP I'm testing with) sends back to me.
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;
}
}
}
}
Anyone knows what's wrong?
Try 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;
//...
}
None of the above worked for me (using PayPal Access as a identifier) in C#
The below 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();
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With