What’s the secret to getting ClaimsResponse working with DotNetOpenId?
For example, in this bit of code (from Scott Hanselman’s blog) the ClaimsResponse object should have lots of nice little things like ‘nickname’ and ’email address’, but the ClaimsResponse object itself is ‘null’:
OpenIdRelyingParty openid = new OpenIdRelyingParty(); if (openid.Response != null) { // Stage 3: OpenID Provider sending assertion response switch (openid.Response.Status) { case AuthenticationStatus.Authenticated: ClaimsResponse fetch = openid.Response.GetExtension(typeof(ClaimsResponse)) as ClaimsResponse; string nick = fetch.Nickname; string homepage = openid.Response.ClaimedIdentifier; string email = fetch.Email; string comment = Session['pendingComment'] as string; string entryId = Session['pendingEntryId'] as string; if (String.IsNullOrEmpty(comment) == false && String.IsNullOrEmpty(entryId) == false) { AddNewComment(nick, email, homepage, comment, entryId, true); } break; } }
At first, I thought it was because I wasn’t redirecting to the provider with a ‘ClaimsRequest’ … but using this code to redirect to the OpenId provider still doesn’t help:
OpenIdRelyingParty openid = new OpenIdRelyingParty(); IAuthenticationRequest req = openid.CreateRequest(openid_identifier.Text); ClaimsRequest fetch = new ClaimsRequest(); fetch.Email = DemandLevel.Require; fetch.Nickname = DemandLevel.Require; req.AddExtension(fetch); req.RedirectToProvider();
What am I doing wrong? Or have other devs experienced the same pain?
Your code looks fine. But be aware that the sreg extension, which you are using, isn’t supported by all OPs. If the OP you’re authenticating with doesn’t support it, then the response extension will be null as you’re seeing. So a null check is always a good idea.
myopenid.com supports sreg, if you’re looking for an OP to test against.