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 FormsAuthentication.SetAuthCookie()
, but I haven't found it.
Here's my thinking so far. Assuming I have to construct this myself, I see this inside CredentialsAuthProvider.TryAuthenticate
:
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 => (IOAuthTokens)x);
return true;
}
That seems to imply that I can do what's inside the block myself via a UserAuth
object from IUserAuthRepository.GetUserAuthByUserName()
. I don't think this is enough though, since the session isn't saved here. Working backwards, I found that TryAuthenticate
is called by Authenticate which then goes on to call OnAuthenticated
where other things happen including saving the session. Can I resolve an instance of CredentialsAuthProvider
and call OnAuthenticated myself?
Am I on the right track, or is this the completely wrong way of going about this?