Advertisement
Guest User

Untitled

a guest
Jan 29th, 2020
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. static decodeJWT(token: string): any {
  2.         const base64Url = token.split('.')[1];
  3.         const base64 = base64Url.replace('-', '+').replace('_', '/');
  4.         return JSON.parse(this.b64DecodeUnicode(base64));
  5.     }
  6.  
  7.     static b64DecodeUnicode(str): string {
  8.         // Going backwards: from bytestream, to percent-encoding, to original string.
  9.         return decodeURIComponent(
  10.             atob(str)
  11.                 .split('')
  12.                 .map(c => {
  13.                     return (
  14.                         '%' + ('00' + c.charCodeAt(0).toString(16)).slice(-2)
  15.                     );
  16.                 })
  17.                 .join('')
  18.         );
  19.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement