Token to Session

How can I convert a token to a user session (with cookie). We have an identity server that is creating a token (uses the jwt cookie) and redirecting back to the site:

site.com?token=123

The token can be used easily in the jsonclient but I also want to create a cookie session from that token so authenticte the user before even serving the page. Something like client.SetTokenCookie(jwtToken); but we don’t have a client in this case. Is there a helper to do this in a filter?

The only thing in ServiceStack that’s converting a token to a UserSession is the JWT AuthProvider which encapsulates the entire UserSession in a JWT Token. The code that extracts the UserSession is in JwtAuthProviderReader.PreAuthenticate() which validates and creates the UserSession from info embedded in the JWT Token that it uses to populate req.Items[Keywords.Session] with which sets the Authenticated UserSession for that request.

You’ll need to do something similar to handle your token, you can use a Global Request Filter instead of a Custom Auth Provider which can be easier.