How to use the jwt-decode.default function in jwt-decode

To help you get started, we’ve selected a few jwt-decode examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github DSpace / dspace-angular / src / app / core / auth / models / auth-token-info.model.ts View on Github external
constructor(token: string) {
    this.accessToken = token.replace('Bearer ', '');
    try {
      const tokenClaims = decode(this.accessToken);
      // exp claim is in seconds, convert it se to milliseconds
      this.expires = tokenClaims.exp * 1000;
    } catch (err) {
      this.expires = 0;
    }
  }
}
github mrellipse / toucan / src / ui / app / common / token-helper.ts View on Github external
public static parseUserToken(token: string): IUser {

        let user: IUser = { authenticated: false, cultureName: null, displayName: null, email: null, name: null, username: null, roles: [], verified: false };

        if (token) {

            let decodedToken: IJwtToken = jwtDecode(token);

            if (!user.authenticated)
                user.authenticated = true;

            let name = decodedToken['http://schemas.xmlsoap.org/ws/2005/05/identity/claims/name'];
            let roles = decodedToken['http://schemas.microsoft.com/ws/2008/06/identity/claims/role'];
            let sid = decodedToken['http://schemas.xmlsoap.org/ws/2005/05/identity/claims/sid'];
            let timeZoneId = decodedToken['TimeZoneId'];

            user.cultureName = decodedToken['CultureName'];
            user.displayName = name ? name[1] : null;
            user.email = decodedToken['http://schemas.xmlsoap.org/ws/2005/05/identity/claims/emailaddress'] || null;
            user.name = user.email;
            user.roles = Array.isArray(roles) ? roles : [roles];
            user.verified = decodedToken['Verified'] === 'true' ? true : false;
            user.exp = new Date(decodedToken.exp * 1000);

jwt-decode

Decode JWT tokens, mostly useful for browser applications.

MIT
Latest version published 1 year ago

Package Health Score

78 / 100
Full package analysis

Popular jwt-decode functions