Im trying to log in using OpenID/Relying Party (Google, Yahoo!..). My login page is as follows.
What I want to do is simple:
Get the OpenID from an user, store it, and associate it with an user account. Every time that unique OpenID is returned from the provider, I would know that the user associated is now logged in. Simple.
The problem is that response.ClaimedIdentifier.OriginalString
that is what I THINK to be the OpenID is not unique. It's almost unique. Most of the time the value returned is the same, but sometimes, not always, for some reasons (specially changing browsers or computers), this value changes and I create another account for the user.
What am I doing wrong? What is the TRUE OpenID code that I must store that is unique regardless of browsers or computers?
public partial class Pages_User_LoginOpenID : LivrePage
{
OpenIdRelyingParty relyingParty = new OpenIdRelyingParty();
IAuthenticationResponse response = null;
protected void Page_Load(object sender, EventArgs e)
{
response = relyingParty.GetResponse();
if (response != null)
{
switch (response.Status)
{
case AuthenticationStatus.Authenticated:
// verifico se existe um usuário com este openid
OpenId openId = UserHelper.GetSession().CreateCriteria<OpenId>().Add(Expression.Eq("IdentifierString", response.ClaimedIdentifier.OriginalString)).UniqueResult<OpenId>();
if (openId == null)
{
openId = new OpenId();
openId.IdentifierString = response.ClaimedIdentifier.OriginalString;
// não existe usuário com este OpenId
User newUser = UserHelper.CreateUser(openId);
SecurityManager.Login(newUser.Id);
}
else
SecurityManager.Login(openId.User.Id);
Response.Redirect(UrlFactory.GetUrlForPage(UrlFactory.PageName.Home));
break;
default:
break;
}
}
}
// processes the login button click
protected void ButtonLogin_Click(object sender, EventArgs e)
{
if (response == null)
relyingParty.CreateRequest(TextBoxOpenID.Text).RedirectToProvider();
}
}