Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- static decodeJWT(token: string): any {
- const base64Url = token.split('.')[1];
- const base64 = base64Url.replace('-', '+').replace('_', '/');
- return JSON.parse(this.b64DecodeUnicode(base64));
- }
- static b64DecodeUnicode(str): string {
- // Going backwards: from bytestream, to percent-encoding, to original string.
- return decodeURIComponent(
- atob(str)
- .split('')
- .map(c => {
- return (
- '%' + ('00' + c.charCodeAt(0).toString(16)).slice(-2)
- );
- })
- .join('')
- );
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement