Commit | Line | Data |
---|---|---|
bbfd04e1 TO |
1 | (function(angular, $, _) { |
2 | angular.module('unvalidatedJwtDecode', CRM.angRequires('unvalidatedJwtDecode')); | |
3 | angular.module('unvalidatedJwtDecode').filter('unvalidatedJwtDecode', function() { | |
4 | return function(token) { | |
5 | if (!token) return null; | |
6 | var payload = token.split('.')[1]; | |
7 | var tokenData = url_base64_decode(payload); | |
8 | try { | |
9 | return JSON.parse(tokenData); | |
10 | } catch (e) { | |
11 | return tokenData; | |
12 | } | |
13 | }; | |
14 | }); | |
15 | ||
16 | function url_base64_decode(str) { | |
17 | var output = str.replace(/-/g, '+').replace(/_/g, '/'); | |
18 | switch (output.length % 4) { | |
19 | case 0: | |
20 | break; | |
21 | case 2: | |
22 | output += '=='; | |
23 | break; | |
24 | case 3: | |
25 | output += '='; | |
26 | break; | |
27 | default: | |
28 | throw 'Illegal base64url string!'; | |
29 | } | |
30 | return decodeURIComponent(window.escape(atob(output))); | |
31 | } | |
32 | })(angular, CRM.$, CRM._); |