本文整理匯總了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');
},