• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

TypeScript angular2-jwt.JwtHelper类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了TypeScript中angular2-jwt.JwtHelper的典型用法代码示例。如果您正苦于以下问题:TypeScript JwtHelper类的具体用法?TypeScript JwtHelper怎么用?TypeScript JwtHelper使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



在下文中一共展示了JwtHelper类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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


示例16: saveToken

 private saveToken(data: any): boolean {
   if (data.status) {
     let decodedToken = this.jwtHelper.decodeToken(data.jwt);
     localStorage.setItem('profile', JSON.stringify(decodedToken));
     localStorage.setItem('id_token', data.jwt);
     return true;
   } else {
     return false;
   }
 }
开发者ID:GECOR,项目名称:gecor-generic-2016,代码行数:10,代码来源:auth.ts


示例17: currentUser

 get currentUser() {
     if (this._currentUser) {
         return Promise.resolve(this._currentUser);
     } else {
         let deserializedToken = jwtHelper.decodeToken(this._store.getString('authtoken'));
         let userId = deserializedToken.sub;
         return this.get(Number(userId)).then(user => {
             this._currentUser = user;
             return user;
         });
     }
 }
开发者ID:csgpro,项目名称:csgpro.com,代码行数:12,代码来源:user.service.ts


示例18: tokenDecode

    tokenDecode() {

        let token = localStorage.getItem('id_token');

        if (!token) {

            return "unathorized";
        } else {

            return this.jwtHelper.decodeToken(token);
        }
    }
开发者ID:ecos-codeaholics,项目名称:factory-of-procedures-front,代码行数:12,代码来源:jwt-helper.service.ts


示例19: User

 response => {
     var idToken = response.json().token;
     console.log(idToken);
     localStorage.setItem('id_token', idToken);
     let token = this.jwtHelper.decodeToken(idToken);
     console.log(token);						
     //TODO get the user from the response object;
     this.currentUser = new User();
     this.currentUser._id = token._id;
     this.currentUser.name = token.name;
     this.currentUser.role = token.role;
     observer.next('SUCCESS');
 },
开发者ID:z424brave,项目名称:DKClient,代码行数:13,代码来源:auth-service.ts


示例20:

	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;
	}
开发者ID:michaelgira23,项目名称:MyMICDS-Mobile,代码行数:19,代码来源:auth.guard.ts



注:本文中的angular2-jwt.JwtHelper类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
TypeScript angular2-jwt.tokenNotExpired函数代码示例发布时间:2022-05-28
下一篇:
TypeScript angular2-jwt.AuthHttp类代码示例发布时间:2022-05-28
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap