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


TypeScript angular2-jwt.JwtHelper類代碼示例

本文整理匯總了TypeScript中angular2-jwt/angular2-jwt.JwtHelper的典型用法代碼示例。如果您正苦於以下問題:TypeScript JwtHelper類的具體用法?TypeScript JwtHelper怎麽用?TypeScript JwtHelper使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


在下文中一共展示了JwtHelper類的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。

示例1: getCurrentUser

    getCurrentUser(token: string):Observable<User>{
        let jwtContent = this._jwtHelper.decodeToken(token);

        return this._userService.getUser(jwtContent.uri).map( (user:User) => {
            return user;
        });
    }
開發者ID:mducnguyen,項目名稱:KlimaoptimierungSimulator,代碼行數:7,代碼來源:auth.service.ts

示例2: Error

            .flatMap((res) => {

                if (res.status == 200) {

                    let body = res.json();
                    let token = body.key;
                    let jwtContent = this.jwtHelper.decodeToken(token);

                    this.saveToken(token);

                    return this._userService.getUser(jwtContent.url).map((user:User) => {
                        this._authContext.setUser(user);
                        return user;
                    });

                } else if (res.status == 401) {
                    // TODO: more meaningful error
                    throw new Error();

                } else {
                    // TODO: more meaningful error
                    throw new Error();
                }

            });
開發者ID:mducnguyen,項目名稱:TicklrClient,代碼行數:25,代碼來源:auth.service.ts

示例3: canActivate

  canActivate(next: ActivatedRouteSnapshot, state: RouterStateSnapshot) {
    if (window.localStorage.getItem('token') &&
      !jwtHelper.isTokenExpired(window.localStorage.getItem('token')) &&
      this.userService.isAdmin()) {
      return true;
    }

    this.router.navigate(['login']);
    return false;
  }
開發者ID:Sirimangalo,項目名稱:meditation-plus-angular,代碼行數:10,代碼來源:admin-guard.ts

示例4: if

            .flatMap( (res) => {
                    if (res.status == 200) {

                        let body = res.json();
                        let token = body.token;
                        let jwtContent = this._jwtHelper.decodeToken(token);

                        this.saveToken(token);

                        return this._userService.getUser(jwtContent.uri).map( (user:User) => {
                            return {success:true, user:user};
                        });

                    } else if (res.status == 401){
                    } else if (res.status == 404) {
                    }
                }
開發者ID:mducnguyen,項目名稱:AccountAdmin,代碼行數:17,代碼來源:auth.service.ts

示例5: tryLogin

    /**
     * Try logging in using authentication token accessible to the app
     * (through e.g localStorage, sessionStorage or other mechanisms)
     */
    public tryLogin() {

        if (!this._authContext.isLoggedIn()) {

            let jwtToken = this.getToken();

            if (jwtToken != null) {
                let jwtContent = this.jwtHelper.decodeToken(jwtToken);
                this._userService.getUser(jwtContent.url).subscribe(user => {
                    this._authContext.setUser(user);
                }, error => {
                });
            } else {
                this._authContext.setUser(null);
            }

        }
    }
開發者ID:mducnguyen,項目名稱:TicklrClient,代碼行數:22,代碼來源:auth.service.ts

示例6: isLogged

 /**
  * Checks if the user session is active
  *
  * @returns {boolean}
  */
 public isLogged(): boolean {
   let token: string = localStorage.getItem("id_token");
   return token && !this.jwtHelper.isTokenExpired(token);
 }
開發者ID:kelsos,項目名稱:quote-frontend,代碼行數:9,代碼來源:app.component.ts


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