Last active
April 30, 2017 12:15
-
-
Save FacileTechnolab/0e325195e389d071b89edbc83d3a9aae to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//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