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

TypeScript jwt-decode.default函数代码示例

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

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



在下文中一共展示了default函数的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的TypeScript代码示例。

示例1: async

export default async (ctx: Context, next: Function) => {
  const idToken = ctx.get('X-Id-Token');
  const entityId = ctx.get('X-Entity-Id');
  const entityType = ctx.get('X-Entity-Type');
  if (!idToken || !entityId || !entityType) {
    return reject(ctx);
  }
  try {
    const token: any = decodeJWT(idToken);
    const issuer = token.iss;
    const identityId = token.unique_name;
    if (!isKnownIssuer(issuer)) {
      return reject(ctx);
    }
    let path = config.permissionsEndpoint.coursePath;
    let data: any = { courseId: entityId };
    if (entityType === constants.entityTypes.learningPath) {
      path = config.permissionsEndpoint.learningPathPath;
      data = { learningpathId: entityId };
    }
    let response;
    if (issuer === 'localhost') {
      response = { body: { data: constants.accessTypes.academy } };
    } else {
      response = await httpRequestSender.post(`https://${issuer}${path}`, data, {
        Authorization: `Bearer ${idToken}`
      });
      if (!response || !response.body || response.statusCode !== 200) {
        return reject(ctx);
      }
    }
    ctx.entityId = entityId;
    ctx.entityType = entityType;
    ctx.identityId = identityId;
    ctx.identityAccessLevel = response.body.data;
  } catch (e) {
    return reject(ctx);
  }
  await next();
};
开发者ID:easygenerator,项目名称:lrs,代码行数:40,代码来源:idTokenAuth.ts


示例2: switch

export const auth: Reducer<AuthState> = (
  state = initialState,
  action: FromActions.LoginActions | FromActions.LogoutAction | FromActions.RegisterActions,
) => {
  let newToken = null;

  switch (action.type) {
    case FromActions.REGISTER_REQUEST:
    case FromActions.LOGIN_REQUEST:
      return {
        ...state,
        errorMessage: null,
        isAuthenticated: false,
        isFetching: true,
      };
    case FromActions.REGISTER_SUCCESS:
      newToken = jwtDecode<TokenDetails>(action.payload);
      return {
        ...state,
        email: newToken.email,
        organizationId: newToken.organization_id,
        errorMessage: null,
        isFetching: false,
      };
    case FromActions.LOGIN_SUCCESS:
      newToken = jwtDecode<TokenDetails>(action.payload);
      return {
        avatar: undefined,
        email: newToken.email,
        errorMessage: null,
        isAuthenticated: true,
        isFetching: false,
        organizationId: newToken.organization_id,
        role: newToken.role,
        token: action.payload,
      };
    case FromActions.REGISTER_FAILURE:
    case FromActions.LOGIN_FAILURE:
      return {
        avatar: undefined,
        email: null,
        errorMessage: action.payload,
        isAuthenticated: false,
        isFetching: false,
        organizationId: null,
        role: null,
        token: null,
      };
    case FromActions.LOGOUT:
      return {
        avatar: undefined,
        email: null,
        errorMessage: null,
        isAuthenticated: false,
        isFetching: false,
        organizationId: null,
        role: null,
        token: null,
      };
    default:
      return state;
  }
};
开发者ID:ofir123,项目名称:Michelin,代码行数:63,代码来源:auth.ts


示例3: constructor

 constructor(public router: Router) {
   var jwt = localStorage.getItem('jwt');
   if (jwt) {
   var decodedJwt = jwtDecode(jwt);
     this.isAdmin = decodedJwt._doc.admin;
   }
 }
开发者ID:WillBeebe,项目名称:angular2-docker-demo,代码行数:7,代码来源:logged-in-app.ts


示例4: isAuthenticated

  public isAuthenticated(): boolean {
    // get the token
    const token = this.getToken();
    if (token === null) { return false; }

    const dToken = decode(token);

    return (dToken.exp * 1000) > new Date().getTime();
  }
开发者ID:RomDuvi,项目名称:Wc360Angular,代码行数:9,代码来源:auth.service.ts


示例5: currentUser

 currentUser():User {
   const jwt = localStorage.getItem('jwt');
   if (!jwt) return;
   const decoded = jwtDecode(jwt);
   return {
     id: decoded.userId,
     email: decoded.sub,
   }
 }
开发者ID:windwang,项目名称:angular2-app,代码行数:9,代码来源:LoginService.ts


示例6: parseJWT

  parseJWT(jwt: string): any {
    var jwtDecoded = null;

    if (typeof jwt !== 'undefined' && jwt !== 'undefined' && jwt !== '') {
      var jwtDecode = require('jwt-decode');
      try { jwtDecoded = jwtDecode(jwt); } catch(e) { jwtDecoded = null; }
    }

    return jwtDecoded;
  }
开发者ID:BrooklynLabs,项目名称:angular2-webpack-login,代码行数:10,代码来源:local-jwt.ts


示例7: isTokenExpired

 isTokenExpired(token) {
     try {
         const decoded = decode(token)
         if (decoded.exp < Date.now() / 1000) { // Checking if token is expired. N
             return true
         }
         else
             return false
     }
     catch (err) {
         return false
     }
 }
开发者ID:bpolly,项目名称:sports-broadcast-store,代码行数:13,代码来源:AuthService.ts


示例8: canActivate

    canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot) {
        // this will be passed from the route config
        // on the data property
        const expectedRole = route.data.expectedRole;

        const token = localStorage.getItem('token');
        // decode the token to get its payload
        const tokenPayload = decode(token);

        if (this.auth.isAuthenticated()) {
            if (!isEmpty(route.data)) {
                if (tokenPayload.sub.role !== expectedRole) {                  
                    this.router.navigate(['/workschedule']);
                } else {
                    return true;
                }
            } else {
                return true;
            }
        } else {
            // not logged in so redirect to login page with the return url
            this.router.navigate(['/login'], { queryParams: { returnUrl: state.url }});
        }  
    }
开发者ID:mdenuil,项目名称:2.2-frontend,代码行数:24,代码来源:auth.guard.ts


示例9: constructor

 constructor(public type: string, public http: Http) {
     this.jwt = localStorage.getItem('jwt');
     this.decodedJwt = this.jwt && jwtDecode(this.jwt);
 }
开发者ID:WillBeebe,项目名称:angular2-docker-demo,代码行数:4,代码来源:api.service.ts


示例10: constructor

 constructor(public router: Router, public http: Http, public authHttp: AuthHttp) {
   this.jwt = localStorage.getItem('jwt');
   this.decodedJwt = this.jwt && jwtDecode(this.jwt);
 }
开发者ID:gustavobrian,项目名称:desa,代码行数:4,代码来源:home.ts



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
TypeScript jwt-simple.decode函数代码示例发布时间:2022-05-25
下一篇:
TypeScript bindVal.default函数代码示例发布时间:2022-05-25
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

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

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

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