本文整理匯總了TypeScript中angular2-jwt/angular2-jwt.JwtHelper.decodeToken方法的典型用法代碼示例。如果您正苦於以下問題:TypeScript JwtHelper.decodeToken方法的具體用法?TypeScript JwtHelper.decodeToken怎麽用?TypeScript JwtHelper.decodeToken使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類angular2-jwt/angular2-jwt.JwtHelper
的用法示例。
在下文中一共展示了JwtHelper.decodeToken方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的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;
});
}
示例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();
}
});
示例3: 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) {
}
}
示例4: 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);
}
}
}