Skip to content

Instantly share code, notes, and snippets.

@FacileTechnolab
Last active April 30, 2017 12:15
Show Gist options
  • Save FacileTechnolab/0e325195e389d071b89edbc83d3a9aae to your computer and use it in GitHub Desktop.
Save FacileTechnolab/0e325195e389d071b89edbc83d3a9aae to your computer and use it in GitHub Desktop.
//AppHost.cs, Configure method
AuthFeature authFeature = new AuthFeature(() => new UserSession(), new IAuthProvider[] {
container.Resolve<IAuthProvider>(),
new JwtAuthProvider(AppSettings) //=> use DI to register
{
AuthKeyBase64 = ConfigurationManager.AppSettings["jwt.AuthKeyBase64"],
RequireSecureConnection = false, //dev configuration
EncryptPayload = false, //dev configuration
HashAlgorithm = "HS256"
}
});
//Add two properties in your custom session class
public class UserSession
{
//...
public string BearerToken { get; set; }
public string RefreshToken { get;set; }
}
//in OnAuthenticated method, appSession is UserSession object
JwtAuthProvider tokenProvider = new JwtAuthProvider(); //=> use DI to resolve
appSession.BearerToken = tokenProvider.CreateJwtBearerToken(session, appSession.Roles);
appSession.RefreshToken = tokenProvider.CreateJwtRefreshToken(appSession.UserAuthId);
authService.SaveSession(appSession);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment