本文整理汇总了TypeScript中angular2-jwt.JwtHelper.decodeToken方法的典型用法代码示例。如果您正苦于以下问题:TypeScript JwtHelper.decodeToken方法的具体用法?TypeScript JwtHelper.decodeToken怎么用?TypeScript JwtHelper.decodeToken使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类angular2-jwt.JwtHelper
的用法示例。
在下文中一共展示了JwtHelper.decodeToken方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: Date
.mergeMap((token) => {
const decodedToken = this.jwtHelper.decodeToken(token);
return Observable.interval(
new Date(0).setUTCSeconds(decodedToken.exp) - new Date(0).setUTCSeconds(decodedToken.iat)
);
})
示例2: getJwt
public getJwt(): any {
var jwtHelper = new JwtHelper();
var encodedToken = window.localStorage.getItem('jwt');
var jwt = jwtHelper.decodeToken(encodedToken);
return jwt;
}
示例3: getUserName
getUserName(): string {
if (window.localStorage.getItem('token')) {
let token = window.localStorage.getItem('token');
let decoded = this.jwtHelper.decodeToken(token);
return decoded.login
} else {
return "not logged in"
}
}
示例4:
this.authProvider.authUser.subscribe(jwt => {
if (jwt) {
const decoded = this.jwtHelper.decodeToken(jwt);
this.user = decoded.sub
}
else {
this.user = null;
}
});
示例5: saveToken
private saveToken(data: any): boolean {
if (data.status) {
let decodedToken = this.jwtHelper.decodeToken(data.jwt);
localStorage.setItem('profile', JSON.stringify(decodedToken));
localStorage.setItem('id_token', data.jwt);
return true;
} else {
return false;
}
}
示例6: canActivate
canActivate() {
var token = localStorage.getItem("jwt");
if (token && !this.jwtHelper.isTokenExpired(token)){
console.log(this.jwtHelper.decodeToken(token));
return true;
}
this.router.navigate(["login"]);
return false;
}
示例7: Number
timer.subscribe(t => {
var token = jwtHelper.decodeToken(localStorage.getItem('id_token'));
if (token) {
this.tokenExpires = ((token.exp * 1000) - Number(new Date()));
this.tokenExpired = this.tokenExpires <= 0;
if (this.tokenExpires > -5000 && this.tokenExpires < 2000) {
this.refreshToken();
}
}
});
示例8: tokenDecode
tokenDecode() {
let token = localStorage.getItem('id_token');
if (!token) {
return "unathorized";
} else {
return this.jwtHelper.decodeToken(token);
}
}
示例9: currentUser
get currentUser() {
if (this._currentUser) {
return Promise.resolve(this._currentUser);
} else {
let deserializedToken = jwtHelper.decodeToken(this._store.getString('authtoken'));
let userId = deserializedToken.sub;
return this.get(Number(userId)).then(user => {
this._currentUser = user;
return user;
});
}
}
示例10: User
response => {
var idToken = response.json().token;
console.log(idToken);
localStorage.setItem('id_token', idToken);
let token = this.jwtHelper.decodeToken(idToken);
console.log(token);
//TODO get the user from the response object;
this.currentUser = new User();
this.currentUser._id = token._id;
this.currentUser.name = token.name;
this.currentUser.role = token.role;
observer.next('SUCCESS');
},