How to decode the JWT encoded token payload on client-side in angular 5?

后端 未结 5 1131
Happy的楠姐
Happy的楠姐 2020-12-23 09:30

I am getting one JWT encoded access token from my API in response. But I am not able to decode it and get it in JSON format. I tried using the angular2-jwt library for it, b

5条回答
  •  粉色の甜心
    2020-12-23 10:03

    Use @auth0/angular-jwt


    Step - 1 : Install using npm

    npm install @auth0/angular-jwt
    


    Step - 2 : Import the package

    import { JwtHelperService } from '@auth0/angular-jwt';
    


    Step - 3 : Create an instance and use

    const helper = new JwtHelperService();
    
    const decodedToken = helper.decodeToken(myRawToken);
    
    // Other functions
    const expirationDate = helper.getTokenExpirationDate(myRawToken);
    const isExpired = helper.isTokenExpired(myRawToken);
    

提交回复
热议问题