Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- services.AddAuthentication().AddJwtBearer(cfg =>
- {
- cfg.TokenValidationParameters = new Microsoft.IdentityModel.Tokens.TokenValidationParameters()
- {
- ValidIssuer = _config["Tokens:Issuer"],
- ValidAudience = _config["Tokens:Audience"],
- IssuerSigningKey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(_config["Tokens:Key"]))
- };
- });
- jwtHelper = new JwtHelperService();
- decodedToken: any;
- constructor(private http: HttpClient) { }
- login(userToLogin: UserLogin) {
- return this.http.post(this.baseURL + 'login', userToLogin)
- .pipe(
- map((response: any) => {
- const user = response;
- if (user) {
- localStorage.setItem('token', user.token);
- localStorage.setItem('user', JSON.stringify(user.loggedInUser))
- this.decodedToken = this.jwtHelper.decodeToken(user.token);
- this.currentUser = JSON.parse(localStorage.getItem('user'));
- }
- }));
- }
- export function tokenGetter() {
- return localStorage.getItem('token');
- }
- imports: [
- JwtModule.forRoot({
- config: {
- tokenGetter: tokenGetter,
- whitelistedDomains: ['localhost:44354/api/'],
- blacklistedRoutes: ['localhost:44354/api/account/']
- }
- }),
- ]
- [Authorize(AuthenticationSchemes=JwtBearerDefaults.AuthenticationScheme)]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement