Click here to Skip to main content
15,917,177 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
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)

C#
//both return null
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):

HTML
<configSections>
  <section name="dotNetOpenAuth" type="DotNetOpenAuth.Configuration.DotNetOpenAuthSection" requirePermission="false" allowLocation="true" /> 
</configSections>

  <!-- The following OPTIONAL behavior allows RPs to use SREG only, but be compatible
                        with OPs that use Attribute Exchange (in various formats). -->
  <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:
C#
//openid_identifier provides the identifier string depending on yahoo ("http://yahoo.com/"), google ("https://www.google.com/accounts/o8/id") or myopenid ("http://{identifier}.myopenid.com/")
private void Logon(string openid_identifier)
 {
     OpenIdRelyingParty oidrp = new OpenIdRelyingParty();
     IAuthenticationRequest request = oidrp.CreateRequest(Identifier.Parse(openid_identifier));

    //tried the FetchRequest solution as well, didn't work.

     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:
C#
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]
Posted
Updated 26-Mar-13 3:59am
v3

1 solution

This was not really straightforward.
Here's the basic solution:
C#
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)
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900