Note that there are some explanatory texts on larger screens.

plurals
  1. POStoring DotNetOpenAuth information and user info retrieval
    text
    copied!<p>This question is a bit of a structural/design question as I'm having trouble working out the best way to perform the task.</p> <p>In my MVC app, I am using DotNetOpenAuth (3.4) as my login information provider and just using the standard <code>FormsAuthentication</code> for cookies etc.</p> <p>The current user table in the DB has:</p> <ul> <li>UserId (PK, uniqueidentifier)</li> <li>OpenIdIdentifier (nvarchar(255))</li> <li>OpenIdDisplay (nvarchar(255))</li> <li>Displayname (nvarchar(50))</li> <li>Email (nvarchar(50))</li> <li>PhoneNumber (nvarchar(50))</li> </ul> <p>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).</p> <p>This is the current code, that on a successfull authentication, creates a temporary user and redirects to Create Action.</p> <pre><code> 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"); } </code></pre> <p>And now for the crux of the question:</p> <ol> <li><p>Is the <code>response.ClaimedIdentifier</code> the correct piece of information to be storing against a user?</p></li> <li><p>Is <code>FormAuthentication.SetAuthCookie</code> the preferred way to forms authentication? Or is there a better way?</p></li> <li><p>When I call SetAuthCookie, there is no data relating to the user except for the <code>ClaimedIdentifier</code>. If I'm consistently referring to their <code>UserId</code>, is a better idea to create the user, then store that <code>UserId</code> in the cookie instead of the <code>ClaimedIdentifier</code>?</p></li> <li><p>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?</p></li> </ol> <p>A bit long winded but I've been having trouble trying to work out the best way to do this/</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload