I know this is an older thread, but it may still be appropriate, because by September 2012 it had not significantly improved in terms of accessibility of the ServiceStack documentation, clarity of examples or even comments in the code. ( @mythz: It would be very helpful if you guys could add meaningful summaries for all your classes and methods.)
I struggled with the same dilemma until I looked at the actual CredentialsAuthProvider code (which, in general, is pretty much the only way to understand how everything works in ServiceStack). OnAuthenticated is called immediately after TryAuthenticate inside the Authenticate method, so I figured it wasnβt necessary to make all your database calls in OnAuthenticated, as @mythz suggests in my examples. Instead, I put the code that populates the IAuthSession object directly in my TryAuthenticate implementation, for example:
public override bool TryAuthenticate(IServiceBase authService, string userName, string password) { try {
However, you still have to override OnAuthenticated to save the cookie in the HTTP response (which I believe is required for subsequent requests from the same browser that needs to be authenticated), since the base implementation only sets the cookie if it finds IUserAuthRepository in the IOC container which in my case will not happen because I use my own repository. So my implementation now looks like this:
public override void OnAuthenticated(IServiceBase authService, IAuthSession session, IOAuthTokens tokens, Dictionary<string, string> authInfo) { try {
@mythz: Please let me know if this makes sense or not.
source share