title: How do I create an authenticated session in ServiceStack?
body: <p>I have a situation where I'm using Credentials auth successfully, but I sometimes need to be able to simply create an authenticated session from inside a service using nothing but the user's email address. How can I do that? I suppose I'm looking for something similar in intent to <code>FormsAuthentication.SetAuthCookie()</code>, but I haven't found it. </p>
  
  <p>Here's my thinking so far. Assuming I have to construct this myself, I see this inside <code>CredentialsAuthProvider.TryAuthenticate</code>:</p>
  
  <pre><code>if (authRepo.TryAuthenticate(userName, password, out userAuth))
  {
      session.PopulateWith(userAuth);
      session.IsAuthenticated = true;
      session.UserAuthId = userAuth.Id.ToString(CultureInfo.InvariantCulture);
      session.ProviderOAuthAccess = authRepo.GetUserOAuthProviders(session.UserAuthId)
          .ConvertAll(x =&gt; (IOAuthTokens)x);
  
      return true;
  }
  </code></pre>
  
  <p>That seems to imply that I can do what's inside the block myself via a <code>UserAuth</code> object from <code>IUserAuthRepository.GetUserAuthByUserName()</code>. I don't think this is enough though, since the session isn't saved here. Working backwards, I found that <code>TryAuthenticate</code> is called by Authenticate which then goes on to call <code>OnAuthenticated</code> where other things happen including saving the session. Can I resolve an instance of <code>CredentialsAuthProvider</code> and call OnAuthenticated myself? </p>
  
  <p>Am I on the right track, or is this the completely wrong way of going about this?</p>