I've got a custom membership provider that I use both in SharePoint 2007 services and in .NET web apps. Now I'm trying to update the SharePoint platform to 2010 Foundation and my provider doesn't work. Below is two examples that both authenticate a user and sets a auth cookie with the same key.
MembershipProvider provider = Membership.Providers["Provider"];
//Alternative one using cookiename (ProviderUserKey from other source then provider)
if (provider.ValidateUser(user, passwd))
{
FormsAuthentication.SetAuthCookie(cookieName, false);
Response.Redirect("/");
}
else
{
ShowErrorMsg();
}
//Alternative two using provider to get ProviderUserKey same as cookieName above
if (provider.ValidateUser(user, passwd))
{
MembershipUser memberUser = provider.GetUser(user, false); //false or true doesnt matter in this provider
FormsAuthentication.SetAuthCookie(memberUser.ProviderUserKey.ToString(), false);
Response.Redirect("/");
}
else
{
ShowErrorMsg();
}
The problem is that SharePoint 2010 uses Claims-based identity and i did try the following but with no success.
MembershipProvider provider = Membership.Providers["Provider"];
if (provider.ValidateUser(user, passwd))
{
SPFormsAuthenticationProvider authProvider = IisSetting.FormsClaimsAuthenticationProvider;
SecurityToken token = SPFormsUserNameSecurityTokenHandler.CreateSecurityToken(authProvider.MembershipProvider, cookieName, passwd);
SPFederationAuthenticationModule.Current.SetPrincipalAndWriteSessionToken(token);
}
But this doesn't work for me. Does anyone know how to base a claims identity on another key then the provided username.