當前位置: 首頁>>代碼示例>>TypeScript>>正文


TypeScript jwt-decode類代碼示例

本文整理匯總了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;
        });
開發者ID:vinga,項目名稱:challenger,代碼行數:28,代碼來源:accountReducers.ts

示例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};
    }
  }
}
開發者ID:hemadri1982,項目名稱:microservice-demo,代碼行數:12,代碼來源:auth.reducer.ts

示例3: ngOnInit

 ngOnInit() {
   this.projectList();
   if (AppSettings.AUTH_TOKEN) {
     let decodedJWT = JWT(AppSettings.AUTH_TOKEN);
     this.canDelete = decodedJWT.privilege.includes("delete");
   }
 }
開發者ID:rlilojr,項目名稱:skf-flask,代碼行數:7,代碼來源:project-list.component.ts

示例4: getClaims

 getClaims(): any {
   const token = this.tokenService.getToken();
   if (!token) {
     return {};
   }
   this.claims = this.claims || jwt_decode(token);
   return this.claims;
 }
開發者ID:brianpursley,項目名稱:timesheet-demo,代碼行數:8,代碼來源:claims.service.ts

示例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.'
        });

    },
開發者ID:elleryapp,項目名稱:ellery-frontend,代碼行數:10,代碼來源:auth.ts

示例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;
  }
開發者ID:Borntorun2018,項目名稱:FutureBank,代碼行數:12,代碼來源:token.storage.ts

示例7: jwtDecode

 .then(response => {
     try {
         let decoded = jwtDecode(response.token);
         dispatch(loginUserSuccess(response.token));
     } catch (e) {
         dispatch(loginUserFailure({
             response: {
                 status: 403,
                 statusText: 'Invalid token'
             }
         }));
     }
 })
開發者ID:myfiurevamp,項目名稱:frontend,代碼行數:13,代碼來源:actions.ts

示例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;
    }
開發者ID:urandom,項目名稱:readeef,代碼行數:15,代碼來源:auth.ts

示例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;
}
開發者ID:dianpeng,項目名稱:fly,代碼行數:17,代碼來源:index.ts

示例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
   }
 }
開發者ID:bkimminich,項目名稱:juice-shop,代碼行數:18,代碼來源:app.routing.ts


注:本文中的jwt-decode類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。