当前位置: 首页>>代码示例>>TypeScript>>正文


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

本文整理汇总了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;未经允许,请勿转载。