OpenID For Forms Authentication
Monday, 23 May 2011
OpenID For Forms Authentication: DotNetOpenId
OpenID For Forms Authentication: DotNetOpenId: "OpenId is a kind of protocol that describes how users can be authenticated in a in a decentralized manner. Today there are several OpenId Pr..."
DotNetOpenId
OpenId is a kind of protocol that describes how users can be authenticated in a in a decentralized manner. Today there are several OpenId Providers eg:- Google, Yahoo, Flicker,AOL and etc.
Here I am not going talking about the how implement openId in .net framework there are lot of tutorials for that , but I would like to talk about little problem with DotNetOpenId.
public ActionResult LogOn(string openid_identifier)
{
var openid = new OpenIdRelyingParty();
IAuthenticationRequest request = openid.CreateRequest(Identifier.Parse(openid_identifier));
var fields = new ClaimsRequest();
fields.Email = DemandLevel.Require;
fields.FullName = DemandLevel.Require;
request.AddExtension(fields);
return request.RedirectingResponse.AsActionResult();
}
Above code describes how we request Email address, Full name of user from the OpenID providers. But some of OpenId providers does not support above request. The best example is AOL. AOL does not support for above request.
var claim = response.GetExtension<ClaimsResponse>();
when we call above extention with AOL authentication , the value of claim is null because it does not support CliamResponse extention.
If you want to use AOL as an authentication provider u you can use following request
public ActionResult LogOn(string openid_identifier)
{
var openid = new OpenIdRelyingParty();
IAuthenticationRequest request = openid.CreateRequest(Identifier.Parse(openid_identifier));
var fetch = new FetchRequest();
fetch.Attributes.AddRequired(WellKnownAttributes.Contact.Email);
fetch.Attributes.AddRequired(WellKnownAttributes.Name.FullName);
request.AddExtension(fetch);
return request.RedirectingResponse.AsActionResult();
}
if (response != null && response.Status == AuthenticationStatus.Authenticated)
{
var claimUntrusted = response.GetUntrustedExtension<FetchResponse>();
var claim = response.GetExtension<FetchResponse>();
//var cliam=response.GetUntrustedExtension<>();
UserData userData = null;
if (claim != null)
{
userData = new UserData();
userData.Email = claim.GetAttributeValue(WellKnownAttributes.Contact.Email);
userData.FullName = claim.GetAttributeValue(WellKnownAttributes.Name.FullName);
}
if (claimUntrusted != null && userData == null)
{
userData = new UserData();
userData.Email = claim.GetAttributeValue(WellKnownAttributes.Contact.Email);
userData.FullName = claimUntrusted.GetAttributeValue(WellKnownAttributes.Name.FullName);
}
Then you can get authentication from AOL like openId providers.
Sometime you should have to add following configuration to web.config file to work correctly with some of providers, the best example is Google.
<configuration>
<configSections> <section name="dotNetOpenAuth" type="DotNetOpenAuth.Configuration.DotNetOpenAuthSection" requirePermission="false" allowLocation="true"/> </configSections>………………………..
<dotNetOpenAuth>
<openid> <relyingParty> <behaviors> <add type="DotNetOpenAuth.OpenId.Behaviors.AXFetchAsSregTransform, DotNetOpenAuth" />
</behaviors> </relyingParty> </openid> </dotNetOpenAuth>
Subscribe to:
Posts (Atom)