This question is a bit of a structural/design question as I'm having trouble working out the best way to perform the task.
In my MVC app, I am using DotNetOpenAuth (3.4) as my login information provider and just using the standard FormsAuthentication
for cookies etc.
The current user table in the DB has:
- UserId (PK, uniqueidentifier)
- OpenIdIdentifier (nvarchar(255))
- OpenIdDisplay (nvarchar(255))
- Displayname (nvarchar(50))
- Email (nvarchar(50))
- PhoneNumber (nvarchar(50))
As the UserId is the clear identifier for a user (they should be able to change their OpenId provider at a later date), it is the key that other tables link to (for a user).
This is the current code, that on a successfull authentication, creates a temporary user and redirects to Create Action.
switch (response.Status)
{
case AuthenticationStatus.Authenticated:
FormsAuthentication.SetAuthCookie(response.ClaimedIdentifier, false);
var users = new UserRepository();
if (!users.IsOpenIdAssociated(response.ClaimedIdentifier))
{
var newUser = new DueDate.Models.User();
newUser.OpenIdIdentifer = response.ClaimedIdentifier;
newUser.OpenIdDisplay = response.FriendlyIdentifierForDisplay;
TempData["newUser"] = newUser;
return this.RedirectToAction("Create");
}
And now for the crux of the question:
Is the
response.ClaimedIdentifier
the correct piece of information to be storing against a user?Is
FormAuthentication.SetAuthCookie
the preferred way to forms authentication? Or is there a better way?When I call SetAuthCookie, there is no data relating to the user except for the
ClaimedIdentifier
. If I'm consistently referring to theirUserId
, is a better idea to create the user, then store thatUserId
in the cookie instead of theClaimedIdentifier
?If I'm using that UserId in a number of places, how do I either retrieve it from the cookie, or store it somewhere else more logical/useful?
A bit long winded but I've been having trouble trying to work out the best way to do this/