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


TypeScript angular2-jwt.JwtHelper類代碼示例

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


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

示例1: getJwt

  public getJwt(): any {
    var jwtHelper = new JwtHelper();
    var encodedToken = window.localStorage.getItem('jwt');
    var jwt = jwtHelper.decodeToken(encodedToken);

    return jwt;
  }
開發者ID:smithandrewl,項目名稱:manytasks,代碼行數:7,代碼來源:authentication.service.ts

示例2: 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);
 }
開發者ID:riyan10dec,項目名稱:FlexerCMS2,代碼行數:8,代碼來源:jwt.service.ts

示例3: 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(['/']);
  }

  }
開發者ID:andela-jmwangi,項目名稱:Masdu,代碼行數:16,代碼來源:app.component.ts

示例4: 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;
		}
	}
開發者ID:mursch,項目名稱:sb-ui,代碼行數:19,代碼來源:AuthUtils.ts

示例5: constructor

 constructor(public router: Router, public http: Http, public authHttp: AuthHttp) {
   let timer = Observable.timer(2000, 1000);
   let jwtHelper: JwtHelper = new JwtHelper();
   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();
       }
     }
   });
 }
開發者ID:adrianobalani,項目名稱:gestaolivre-frontend,代碼行數:14,代碼來源:gestaolivre.ts

示例6: constructor

    constructor(private _httpClient: HttpClient,
                private _notificationService: NotificationService) {
        this.baseUrl = API_ENDPOINT.concat('/auth/local/');
		console.log(`baseurl : ${this.baseUrl}`)
        this.jwtHelper = new JwtHelper();
        //the user doesn't need to login as long as the token is valid
        if (tokenNotExpired()) {
            let idToken = localStorage.getItem('id_token');
            let token = this.jwtHelper.decodeToken(idToken);
            this.currentUser = new User();
            this.currentUser._id = token._id;
            this.currentUser.name = token.name;
            this.currentUser.role = token.role;
			console.log(`existing token - ${this.currentUser.name}`);	
        }

    }
開發者ID:z424brave,項目名稱:DKClient,代碼行數:17,代碼來源:auth-service.ts

示例7: constructor

 constructor(public router: Router, public http: Http, public authHttp: AuthHttp,
 public jwtHelper: JwtHelper, private userService: UserService) {
     this.jwt = localStorage.getItem('jwt');
     this.decodedJwt = this.jwt && this.jwtHelper.decodeToken(this.jwt);
     this.user = this.userService.getCurrentUser();
 }
開發者ID:michaelfemi81,項目名稱:Angular2-RxJS-Socket.io-chat-application,代碼行數:6,代碼來源:home.ts

示例8: 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;
  }
開發者ID:joeymalouf,項目名稱:GraduationGuideline,代碼行數:10,代碼來源:auth-gaurd.service.ts

示例9:

		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;
		},
開發者ID:michaelgira23,項目名稱:MyMICDS-v2-Angular,代碼行數:30,代碼來源:app.module.ts

示例10: Date

            .mergeMap((token) => {
                const decodedToken = this.jwtHelper.decodeToken(token);

                return Observable.interval(
                    new Date(0).setUTCSeconds(decodedToken.exp) - new Date(0).setUTCSeconds(decodedToken.iat)
                );
            })
開發者ID:Invis1ble,項目名稱:assistant-client,代碼行數:7,代碼來源:auth.service.ts

示例11:

 this.authProvider.authUser.subscribe(jwt => {
   if (jwt) {
     const decoded = this.jwtHelper.decodeToken(jwt);
     this.user = decoded.sub
   }
   else {
     this.user = null;
   }
 });
開發者ID:francasense,項目名稱:blog,代碼行數:9,代碼來源:home.ts

示例12: 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;
  }
開發者ID:Sirimangalo,項目名稱:meditation-plus-angular,代碼行數:9,代碼來源:auth-guard.ts

示例13: 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"
   }
 }
開發者ID:TypeScriptUserGroupDE,項目名稱:homepage,代碼行數:9,代碼來源:auth.service.ts

示例14: isAuthenticated

    isAuthenticated(): boolean {
        let jwt = this.jwtStorage.getToken();

        if (null === jwt) {
            return false;
        }

        return !this.jwtHelper.isTokenExpired(jwt.token);
    }
開發者ID:Invis1ble,項目名稱:assistant-client,代碼行數:9,代碼來源:auth.service.ts

示例15: 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();
     }
   }
 });
開發者ID:adrianobalani,項目名稱:gestaolivre-frontend,代碼行數:10,代碼來源:gestaolivre.ts


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