I downloaded and tried the code from
here[
^]. it works.
So I tried the same thing in ASP.Net and sure enough,
I get authenticated, but the ClaimsResponse object is always null. (I tried yahoo, google and myopenid)
var claimUntrusted = response.GetUntrustedExtension<ClaimsResponse>();
var claim = response.GetExtension<ClaimsResponse>();
I tried to solve this and found various forums mostly StackOverFlow, claiming I should change the web.config file to something like this (tried different variations based on the different responses on the forums):
<configSections>
<section name="dotNetOpenAuth" type="DotNetOpenAuth.Configuration.DotNetOpenAuthSection" requirePermission="false" allowLocation="true" />
</configSections>
<!--
<dotNetOpenAuth>
<openid>
<relyingParty>
<behaviors>
<add type="DotNetOpenAuth.OpenId.RelyingParty.Behaviors.AXFetchAsSregTransform, DotNetOpenAuth" />
</behaviors>
</relyingParty>
</openid>
</dotNetOpenAuth>
I compared my solution to the dotnetopenauth website itself:
http://www.dotnetopenauth.net/developers/help/programmatic-openid-relying-party/[
^], but to no avail.
this is the logon button event handler:
private void Logon(string openid_identifier)
{
OpenIdRelyingParty oidrp = new OpenIdRelyingParty();
IAuthenticationRequest request = oidrp.CreateRequest(Identifier.Parse(openid_identifier));
ClaimsRequest cr = new ClaimsRequest();
cr.Email = DemandLevel.Require;
cr.FullName = DemandLevel.Require;
cr.Country = DemandLevel.Require;
request.AddExtension(cr);
request.RedirectToProvider();
}
Hope someone has an idea.
thanks.
[UPDATE]
It is working with myopenid. Google and yahoo still return null.
[/UPDATE]
[UPDATE #2]
This was not really straightforward.
Here's the basic solution:
private void Logon(string openid_identifier, PROVIDER provider)
{
Session["provider"] = provider;
IAuthenticationRequest request = openid.CreateRequest(Identifier.Parse(openid_identifier));
if (provider == PROVIDER.myopenid) {
ClaimsRequest cr = new ClaimsRequest();
cr.Email = DemandLevel.Require;
cr.FullName = DemandLevel.Require;
cr.Country = DemandLevel.Request;
cr.BirthDate = DemandLevel.Request;
cr.Gender = DemandLevel.Request;
cr.Language = DemandLevel.Request;
cr.Nickname = DemandLevel.Request;
cr.PostalCode = DemandLevel.Request;
cr.TimeZone = DemandLevel.Request;
request.AddExtension(cr);
}
else {
FetchRequest fr = new FetchRequest();
fr.Attributes.AddRequired(WellKnownAttributes.Contact.Email);
fr.Attributes.AddRequired(WellKnownAttributes.Name.FullName);
fr.Attributes.AddRequired(WellKnownAttributes.Contact.HomeAddress.Country);
fr.Attributes.AddRequired(WellKnownAttributes.BirthDate.WholeBirthDate);
fr.Attributes.AddRequired(WellKnownAttributes.Preferences.Language);
fr.Attributes.AddRequired(WellKnownAttributes.Person.Gender);
fr.Attributes.AddRequired(WellKnownAttributes.Name.Alias);
fr.Attributes.AddRequired(WellKnownAttributes.Preferences.TimeZone);
fr.Attributes.AddRequired(WellKnownAttributes.Contact.HomeAddress.PostalCode);
request.AddExtension(fr);
}
request.RedirectToProvider();
}
that's right, this is dependent on the provider you want to talk to. Moreover you need to add "using DotNetOpenAuth.OpenId.Extensions.AttributeExchange;" on TOP of the page. If you want to use DotNetOpenAuth.OpenId.Extensions.AttributeExchange.FetchRequest fr = new DotNetOpenAuth.OpenId.Extensions.AttributeExchange.FetchRequest(); you don't get the AddRequired method in intellisense.
I keep the provider option in sesion so when the login comes back I know what object to talk too. (ClaimsResponse or FetchResponse)
[/UPDATE #2]