本文整理汇总了TypeScript中angular2-jwt/angular2-jwt.JwtHelper类的典型用法代码示例。如果您正苦于以下问题:TypeScript JwtHelper类的具体用法?TypeScript JwtHelper怎么用?TypeScript JwtHelper使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了JwtHelper类的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的TypeScript代码示例。
示例1: getCurrentUser
getCurrentUser(token: string):Observable<User>{
let jwtContent = this._jwtHelper.decodeToken(token);
return this._userService.getUser(jwtContent.uri).map( (user:User) => {
return user;
});
}
开发者ID:mducnguyen,项目名称:KlimaoptimierungSimulator,代码行数:7,代码来源:auth.service.ts
示例2: Error
.flatMap((res) => {
if (res.status == 200) {
let body = res.json();
let token = body.key;
let jwtContent = this.jwtHelper.decodeToken(token);
this.saveToken(token);
return this._userService.getUser(jwtContent.url).map((user:User) => {
this._authContext.setUser(user);
return user;
});
} else if (res.status == 401) {
// TODO: more meaningful error
throw new Error();
} else {
// TODO: more meaningful error
throw new Error();
}
});
开发者ID:mducnguyen,项目名称:TicklrClient,代码行数:25,代码来源:auth.service.ts
示例3: canActivate
canActivate(next: ActivatedRouteSnapshot, state: RouterStateSnapshot) {
if (window.localStorage.getItem('token') &&
!jwtHelper.isTokenExpired(window.localStorage.getItem('token')) &&
this.userService.isAdmin()) {
return true;
}
this.router.navigate(['login']);
return false;
}
开发者ID:Sirimangalo,项目名称:meditation-plus-angular,代码行数:10,代码来源:admin-guard.ts
示例4: if
.flatMap( (res) => {
if (res.status == 200) {
let body = res.json();
let token = body.token;
let jwtContent = this._jwtHelper.decodeToken(token);
this.saveToken(token);
return this._userService.getUser(jwtContent.uri).map( (user:User) => {
return {success:true, user:user};
});
} else if (res.status == 401){
} else if (res.status == 404) {
}
}
开发者ID:mducnguyen,项目名称:AccountAdmin,代码行数:17,代码来源:auth.service.ts
示例5: tryLogin
/**
* Try logging in using authentication token accessible to the app
* (through e.g localStorage, sessionStorage or other mechanisms)
*/
public tryLogin() {
if (!this._authContext.isLoggedIn()) {
let jwtToken = this.getToken();
if (jwtToken != null) {
let jwtContent = this.jwtHelper.decodeToken(jwtToken);
this._userService.getUser(jwtContent.url).subscribe(user => {
this._authContext.setUser(user);
}, error => {
});
} else {
this._authContext.setUser(null);
}
}
}
开发者ID:mducnguyen,项目名称:TicklrClient,代码行数:22,代码来源:auth.service.ts
示例6: isLogged
/**
* Checks if the user session is active
*
* @returns {boolean}
*/
public isLogged(): boolean {
let token: string = localStorage.getItem("id_token");
return token && !this.jwtHelper.isTokenExpired(token);
}
开发者ID:kelsos,项目名称:quote-frontend,代码行数:9,代码来源:app.component.ts
注:本文中的angular2-jwt/angular2-jwt.JwtHelper类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论