jwt-decode
Advanced tools
Comparing version 3.0.0-beta.1 to 3.0.0-beta.2
@@ -1,2 +0,108 @@ | ||
"use strict";function e(e){this.message=e}e.prototype=new Error,e.prototype.name="InvalidCharacterError";var r="undefined"!=typeof window&&window.atob&&window.atob.bind(window)||function(r){var t=String(r).replace(/=+$/,"");if(t.length%4==1)throw new e("'atob' failed: The string to be decoded is not correctly encoded.");for(var n,o,a=0,i=0,c="";o=t.charAt(i++);~o&&(n=a%4?64*n+o:o,a++%4)?c+=String.fromCharCode(255&n>>(-2*a&6)):0)o="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=".indexOf(o);return c};function t(e){var t=e.replace(/-/g,"+").replace(/_/g,"/");switch(t.length%4){case 0:break;case 2:t+="==";break;case 3:t+="=";break;default:throw"Illegal base64url string!"}try{return function(e){return decodeURIComponent(r(e).replace(/(.)/g,(function(e,r){var t=r.charCodeAt(0).toString(16).toUpperCase();return t.length<2&&(t="0"+t),"%"+t})))}(t)}catch(e){return r(t)}}function n(e){this.message=e}n.prototype=new Error,n.prototype.name="InvalidTokenError";const o=function(e,r){if("string"!=typeof e)throw new n("Invalid token specified");var o=!0===(r=r||{}).header?0:1;try{return JSON.parse(t(e.split(".")[o]))}catch(e){throw new n("Invalid token specified: "+e.message)}};o.InvalidTokenError=n,module.exports=o; | ||
'use strict'; | ||
/** | ||
* The code was extracted from: | ||
* https://github.com/davidchambers/Base64.js | ||
*/ | ||
var chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/="; | ||
function InvalidCharacterError(message) { | ||
this.message = message; | ||
} | ||
InvalidCharacterError.prototype = new Error(); | ||
InvalidCharacterError.prototype.name = "InvalidCharacterError"; | ||
function polyfill(input) { | ||
var str = String(input).replace(/=+$/, ""); | ||
if (str.length % 4 == 1) { | ||
throw new InvalidCharacterError( | ||
"'atob' failed: The string to be decoded is not correctly encoded." | ||
); | ||
} | ||
for ( | ||
// initialize result and counters | ||
var bc = 0, bs, buffer, idx = 0, output = ""; | ||
// get next character | ||
(buffer = str.charAt(idx++)); | ||
// character found in table? initialize bit storage and add its ascii value; | ||
~buffer && | ||
((bs = bc % 4 ? bs * 64 + buffer : buffer), | ||
// and if not first of each 4 characters, | ||
// convert the first 8 bits to one ascii character | ||
bc++ % 4) ? | ||
(output += String.fromCharCode(255 & (bs >> ((-2 * bc) & 6)))) : | ||
0 | ||
) { | ||
// try to find character in table (0-63, not found => -1) | ||
buffer = chars.indexOf(buffer); | ||
} | ||
return output; | ||
} | ||
var atob = (typeof window !== "undefined" && | ||
window.atob && | ||
window.atob.bind(window)) || | ||
polyfill; | ||
function b64DecodeUnicode(str) { | ||
return decodeURIComponent( | ||
atob(str).replace(/(.)/g, function(m, p) { | ||
var code = p.charCodeAt(0).toString(16).toUpperCase(); | ||
if (code.length < 2) { | ||
code = "0" + code; | ||
} | ||
return "%" + code; | ||
}) | ||
); | ||
} | ||
function base64_url_decode(str) { | ||
var output = str.replace(/-/g, "+").replace(/_/g, "/"); | ||
switch (output.length % 4) { | ||
case 0: | ||
break; | ||
case 2: | ||
output += "=="; | ||
break; | ||
case 3: | ||
output += "="; | ||
break; | ||
default: | ||
throw "Illegal base64url string!"; | ||
} | ||
try { | ||
return b64DecodeUnicode(output); | ||
} catch (err) { | ||
return atob(output); | ||
} | ||
} | ||
function InvalidTokenError(message) { | ||
this.message = message; | ||
} | ||
InvalidTokenError.prototype = new Error(); | ||
InvalidTokenError.prototype.name = "InvalidTokenError"; | ||
function jwtDecode(token, options) { | ||
if (typeof token !== "string") { | ||
throw new InvalidTokenError("Invalid token specified"); | ||
} | ||
options = options || {}; | ||
var pos = options.header === true ? 0 : 1; | ||
try { | ||
return JSON.parse(base64_url_decode(token.split(".")[pos])); | ||
} catch (e) { | ||
throw new InvalidTokenError("Invalid token specified: " + e.message); | ||
} | ||
} | ||
const wrapper = jwtDecode; | ||
wrapper.InvalidTokenError = InvalidTokenError; | ||
module.exports = wrapper; | ||
//# sourceMappingURL=jwt-decode.cjs.js.map |
@@ -1,2 +0,104 @@ | ||
function e(e){this.message=e}e.prototype=new Error,e.prototype.name="InvalidCharacterError";var r="undefined"!=typeof window&&window.atob&&window.atob.bind(window)||function(r){var t=String(r).replace(/=+$/,"");if(t.length%4==1)throw new e("'atob' failed: The string to be decoded is not correctly encoded.");for(var n,o,a=0,i=0,c="";o=t.charAt(i++);~o&&(n=a%4?64*n+o:o,a++%4)?c+=String.fromCharCode(255&n>>(-2*a&6)):0)o="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=".indexOf(o);return c};function t(e){var t=e.replace(/-/g,"+").replace(/_/g,"/");switch(t.length%4){case 0:break;case 2:t+="==";break;case 3:t+="=";break;default:throw"Illegal base64url string!"}try{return function(e){return decodeURIComponent(r(e).replace(/(.)/g,(function(e,r){var t=r.charCodeAt(0).toString(16).toUpperCase();return t.length<2&&(t="0"+t),"%"+t})))}(t)}catch(e){return r(t)}}function n(e){this.message=e}function o(e,r){if("string"!=typeof e)throw new n("Invalid token specified");var o=!0===(r=r||{}).header?0:1;try{return JSON.parse(t(e.split(".")[o]))}catch(e){throw new n("Invalid token specified: "+e.message)}}n.prototype=new Error,n.prototype.name="InvalidTokenError";export default o;export{n as InvalidTokenError}; | ||
/** | ||
* The code was extracted from: | ||
* https://github.com/davidchambers/Base64.js | ||
*/ | ||
var chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/="; | ||
function InvalidCharacterError(message) { | ||
this.message = message; | ||
} | ||
InvalidCharacterError.prototype = new Error(); | ||
InvalidCharacterError.prototype.name = "InvalidCharacterError"; | ||
function polyfill(input) { | ||
var str = String(input).replace(/=+$/, ""); | ||
if (str.length % 4 == 1) { | ||
throw new InvalidCharacterError( | ||
"'atob' failed: The string to be decoded is not correctly encoded." | ||
); | ||
} | ||
for ( | ||
// initialize result and counters | ||
var bc = 0, bs, buffer, idx = 0, output = ""; | ||
// get next character | ||
(buffer = str.charAt(idx++)); | ||
// character found in table? initialize bit storage and add its ascii value; | ||
~buffer && | ||
((bs = bc % 4 ? bs * 64 + buffer : buffer), | ||
// and if not first of each 4 characters, | ||
// convert the first 8 bits to one ascii character | ||
bc++ % 4) ? | ||
(output += String.fromCharCode(255 & (bs >> ((-2 * bc) & 6)))) : | ||
0 | ||
) { | ||
// try to find character in table (0-63, not found => -1) | ||
buffer = chars.indexOf(buffer); | ||
} | ||
return output; | ||
} | ||
var atob = (typeof window !== "undefined" && | ||
window.atob && | ||
window.atob.bind(window)) || | ||
polyfill; | ||
function b64DecodeUnicode(str) { | ||
return decodeURIComponent( | ||
atob(str).replace(/(.)/g, function(m, p) { | ||
var code = p.charCodeAt(0).toString(16).toUpperCase(); | ||
if (code.length < 2) { | ||
code = "0" + code; | ||
} | ||
return "%" + code; | ||
}) | ||
); | ||
} | ||
function base64_url_decode(str) { | ||
var output = str.replace(/-/g, "+").replace(/_/g, "/"); | ||
switch (output.length % 4) { | ||
case 0: | ||
break; | ||
case 2: | ||
output += "=="; | ||
break; | ||
case 3: | ||
output += "="; | ||
break; | ||
default: | ||
throw "Illegal base64url string!"; | ||
} | ||
try { | ||
return b64DecodeUnicode(output); | ||
} catch (err) { | ||
return atob(output); | ||
} | ||
} | ||
function InvalidTokenError(message) { | ||
this.message = message; | ||
} | ||
InvalidTokenError.prototype = new Error(); | ||
InvalidTokenError.prototype.name = "InvalidTokenError"; | ||
function index(token, options) { | ||
if (typeof token !== "string") { | ||
throw new InvalidTokenError("Invalid token specified"); | ||
} | ||
options = options || {}; | ||
var pos = options.header === true ? 0 : 1; | ||
try { | ||
return JSON.parse(base64_url_decode(token.split(".")[pos])); | ||
} catch (e) { | ||
throw new InvalidTokenError("Invalid token specified: " + e.message); | ||
} | ||
} | ||
export default index; | ||
export { InvalidTokenError }; | ||
//# sourceMappingURL=jwt-decode.esm.js.map |
{ | ||
"name": "jwt-decode", | ||
"version": "3.0.0-beta.1", | ||
"version": "3.0.0-beta.2", | ||
"description": "Decode JWT tokens, mostly useful for browser applications.", | ||
"main": "dist/jwt-decode.cjs.js", | ||
"module": "dist/jwt-decode.esm.js", | ||
"main": "build/jwt-decode.cjs.js", | ||
"module": "build/jwt-decode.esm.js", | ||
"keywords": [ | ||
@@ -8,0 +8,0 @@ "jwt", |
@@ -39,6 +39,14 @@ **jwt-decode** is a small browser library that helps decoding JWTs token which are Base64Url encoded. | ||
## Older verion | ||
## Include with a script tag | ||
If you want to use the library trough Bower, an HTML import or include it through a `<script>` tag, use [version `v2.2.0`](https://github.com/auth0/jwt-decode/tree/v2.2.0). It has the same functionality. | ||
Copy the file `jwt-decode.js` from the `build/` folder to your project somewhere, then include like so: | ||
```html | ||
<script src="jwt-decode.js"></script> | ||
``` | ||
## Older verions | ||
If you want to use the library trough Bower, an HTML import, use [version `v2.2.0`](https://github.com/auth0/jwt-decode/tree/v2.2.0). It has the same functionality. | ||
## Develop | ||
@@ -45,0 +53,0 @@ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
33068
291
66