本文整理汇总了TypeScript中jwt-decode类的典型用法代码示例。如果您正苦于以下问题:TypeScript jwt-decode类的具体用法?TypeScript jwt-decode怎么用?TypeScript jwt-decode使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了jwt-decode类的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: jwtDecode
return state.map((u: AccountDTO) => {
if (u.login == action.login) {
console.log("update token " + u.primary + " " + baseWebCall.webToken + " " + action.jwtToken);
if (u.primary) {
baseWebCall.webToken = action.jwtToken;
}
var decodedToken: any = jwtDecode(action.jwtToken);
var iat: number = decodedToken.iat;
var exp: number = decodedToken.exp;
console.log("IAT " + new Date(iat * 1000).simpleFormatWithMinutes());
console.log("EXP " + new Date(exp * 1000).simpleFormatWithMinutes());
// co jak issued at bedzie
return Object.assign({}, u, {
id: jwtDecode(action.jwtToken).info.userId,
login: action.login,
jwtToken: action.jwtToken,
lastUpdated: Date.now(),
infoDescription: null,
inProgress: false,
tokenExpirationDate: new Date(exp * 1000)
});
} else
return u;
});
示例2: getAuthentication
function getAuthentication(token): Authentication {
if (token == null) {
return { token: null, claims: null, error: null };
} else {
const claims = jwt_decode(token);
if (claims['exp'] < new Date().getTime()/1000) {
return { token: null, claims: null, error: null };
} else {
return {token: token, claims: jwt_decode(token), error: null};
}
}
}
示例3: ngOnInit
ngOnInit() {
this.projectList();
if (AppSettings.AUTH_TOKEN) {
let decodedJWT = JWT(AppSettings.AUTH_TOKEN);
this.canDelete = decodedJWT.privilege.includes("delete");
}
}
示例4: getClaims
getClaims(): any {
const token = this.tokenService.getToken();
if (!token) {
return {};
}
this.claims = this.claims || jwt_decode(token);
return this.claims;
}
示例5: jwtDecode
'LOGIN_USER_SUCCESS': (state, payload) => {
return Object.assign({}, state, {
'isAuthenticating': false,
'isAuthenticated': true,
'token': payload.token,
'userName': jwtDecode(payload.token).userName,
'statusText': 'You have been successfully logged in.'
});
},
示例6: getTokenExpirationDate
private getTokenExpirationDate(token:string): Date {
var decoded=null;
try{
decoded = jwt_decode(token);
}catch(err){
return null;
}
if (decoded.exp === undefined) return null;
const date = new Date(0);
date.setUTCSeconds(decoded.exp);
return date;
}
示例7: jwtDecode
.then(response => {
try {
let decoded = jwtDecode(response.token);
dispatch(loginUserSuccess(response.token));
} catch (e) {
dispatch(loginUserFailure({
response: {
status: 403,
statusText: 'Invalid token'
}
}));
}
})
示例8: canActivate
canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot) : boolean {
var token = localStorage.getItem("token")
if (token) {
var res = jwt(token)
if (
(!res["exp"] || res["exp"] >= new Date().getTime() / 1000) &&
(!res["nbf"] || res["nbf"] < new Date().getTime() / 1000)
) {
return true;
}
}
this.router.navigate(['/login'], { queryParams: { returnUrl: state.url }});
return false;
}
示例9: getSession
function getSession(req: Request): {} | null {
const token = getAuthorizationToken(req);
// this just checks that a jwt is present and can be decoded. Validating
// the token against a pk would be good. Would also be good to validate the
// expiration.
if (token) {
try {
return jwt_decode(token);
} catch (err) {
console.warn("Error decoding token", err);
}
}
return null;
}
示例10: canActivate
canActivate () {
let payload: any
const token = localStorage.getItem('token')
if (token) {
payload = jwt_decode(token)
}
if (payload && payload.data && payload.data.isAdmin) {
return true
} else {
this.router.navigate(['403'], {
skipLocationChange: true,
queryParams: {
error: 'UNAUTHORIZED_PAGE_ACCESS_ERROR'
}
})
return false
}
}