本文整理汇总了TypeScript中angular2-jwt.JwtHelper.isTokenExpired方法的典型用法代码示例。如果您正苦于以下问题:TypeScript JwtHelper.isTokenExpired方法的具体用法?TypeScript JwtHelper.isTokenExpired怎么用?TypeScript JwtHelper.isTokenExpired使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类angular2-jwt.JwtHelper
的用法示例。
在下文中一共展示了JwtHelper.isTokenExpired方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: ngOnInit
// Checks for token expiration to display appropriate page
ngOnInit() {
var jwtHelper = new JwtHelper();
var token = localStorage.getItem('auth_token');
if (token) {
console.log(jwtHelper.isTokenExpired(token));
if (jwtHelper.isTokenExpired(token)) {
this.router.navigate(['/']);
} else {
this.router.navigate(['/home']);
}
} else {
this.router.navigate(['/']);
}
}
示例2:
tokenGetter: () => {
// Look in session storage for id_token, but fallback to local storage
let session = sessionStorage.getItem('id_token');
let local = localStorage.getItem('id_token');
let token = session || local;
if (typeof token !== 'string') { return ''; }
// Remove any quotations from the sides
token = token.split('"').join('');
// Check validity of jwt token
if (token.split('.').length !== 3) {
localStorage.removeItem('id_token');
sessionStorage.removeItem('id_token');
return '';
}
// Check if token is expired. If it is, delete and send user to login page
if (jwtHelper.isTokenExpired(token)) {
sessionStorage.removeItem('id_token');
localStorage.removeItem('id_token');
this.router.navigate(['/login']);
return '';
}
return token;
},
示例3: isTokenValid
isTokenValid(token: string): Boolean {
// auth0 = new auth0.WebAuth({
// clientID: AUTH_CONFIG.CLIENT_ID,
// domain: AUTH_CONFIG.CLIENT_DOMAIN
// });
const jwtHelper: JwtHelper = new JwtHelper();
return jwtHelper.isTokenExpired(token);
}
示例4: canActivate
canActivate(next: ActivatedRouteSnapshot, state: RouterStateSnapshot) {
if (window.localStorage.getItem('token') &&
!jwtHelper.isTokenExpired(window.localStorage.getItem('token'))) {
return true;
}
this.router.navigate(['login']);
return false;
}
示例5: isAuthenticated
isAuthenticated(): boolean {
let jwt = this.jwtStorage.getToken();
if (null === jwt) {
return false;
}
return !this.jwtHelper.isTokenExpired(jwt.token);
}
示例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: tokenNotExpired
public static tokenNotExpired(tokenName?: string, jwt?: string) {
var authToken: string = tokenName || 'id_token';
var token: string;
if (jwt) {
token = jwt;
} else {
token = localStorage.getItem(authToken);
}
var jwtHelper = new JwtHelper();
if (!token || jwtHelper.isTokenExpired(token, null)) {
return false;
} else {
return true;
}
}
示例8: canActivate
canActivate() {
// Look in session storage for id_token, but fallback to local storage
let session = sessionStorage.getItem('id_token');
let local = localStorage.getItem('id_token');
let token = session || local;
// If there is a token, then user is logged in, otherwise redirect to login page
if (token && !jwtHelper.isTokenExpired(token)) {
return true;
}
// Delete JWT from the client just in case it was simply expired
sessionStorage.removeItem('id_token');
localStorage.removeItem('id_token');
this.router.navigate(['/login']);
return false;
}
示例9: tokenExpired
tokenExpired() {
let token = localStorage.getItem('id_token');
return this.jwtHelper.isTokenExpired(token);
}
示例10: isLoggedIn
public isLoggedIn(): boolean {
let token = localStorage.getItem('auth_token')
let isLoggedIn = token && !this.jwtHelper.isTokenExpired(token);
return isLoggedIn;
}