1
This commit is contained in:
23
node_modules/jwt-decode/build/cjs/index.d.ts
generated
vendored
Normal file
23
node_modules/jwt-decode/build/cjs/index.d.ts
generated
vendored
Normal file
@@ -0,0 +1,23 @@
|
||||
export interface JwtDecodeOptions {
|
||||
header?: boolean;
|
||||
}
|
||||
export interface JwtHeader {
|
||||
typ?: string;
|
||||
alg?: string;
|
||||
kid?: string;
|
||||
}
|
||||
export interface JwtPayload {
|
||||
iss?: string;
|
||||
sub?: string;
|
||||
aud?: string[] | string;
|
||||
exp?: number;
|
||||
nbf?: number;
|
||||
iat?: number;
|
||||
jti?: string;
|
||||
}
|
||||
export declare class InvalidTokenError extends Error {
|
||||
}
|
||||
export declare function jwtDecode<T = JwtHeader>(token: string, options: JwtDecodeOptions & {
|
||||
header: true;
|
||||
}): T;
|
||||
export declare function jwtDecode<T = JwtPayload>(token: string, options?: JwtDecodeOptions): T;
|
||||
62
node_modules/jwt-decode/build/cjs/index.js
generated
vendored
Normal file
62
node_modules/jwt-decode/build/cjs/index.js
generated
vendored
Normal file
@@ -0,0 +1,62 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.jwtDecode = exports.InvalidTokenError = void 0;
|
||||
class InvalidTokenError extends Error {
|
||||
}
|
||||
exports.InvalidTokenError = InvalidTokenError;
|
||||
InvalidTokenError.prototype.name = "InvalidTokenError";
|
||||
function b64DecodeUnicode(str) {
|
||||
return decodeURIComponent(atob(str).replace(/(.)/g, (m, p) => {
|
||||
let code = p.charCodeAt(0).toString(16).toUpperCase();
|
||||
if (code.length < 2) {
|
||||
code = "0" + code;
|
||||
}
|
||||
return "%" + code;
|
||||
}));
|
||||
}
|
||||
function base64UrlDecode(str) {
|
||||
let output = str.replace(/-/g, "+").replace(/_/g, "/");
|
||||
switch (output.length % 4) {
|
||||
case 0:
|
||||
break;
|
||||
case 2:
|
||||
output += "==";
|
||||
break;
|
||||
case 3:
|
||||
output += "=";
|
||||
break;
|
||||
default:
|
||||
throw new Error("base64 string is not of the correct length");
|
||||
}
|
||||
try {
|
||||
return b64DecodeUnicode(output);
|
||||
}
|
||||
catch (err) {
|
||||
return atob(output);
|
||||
}
|
||||
}
|
||||
function jwtDecode(token, options) {
|
||||
if (typeof token !== "string") {
|
||||
throw new InvalidTokenError("Invalid token specified: must be a string");
|
||||
}
|
||||
options || (options = {});
|
||||
const pos = options.header === true ? 0 : 1;
|
||||
const part = token.split(".")[pos];
|
||||
if (typeof part !== "string") {
|
||||
throw new InvalidTokenError(`Invalid token specified: missing part #${pos + 1}`);
|
||||
}
|
||||
let decoded;
|
||||
try {
|
||||
decoded = base64UrlDecode(part);
|
||||
}
|
||||
catch (e) {
|
||||
throw new InvalidTokenError(`Invalid token specified: invalid base64 for part #${pos + 1} (${e.message})`);
|
||||
}
|
||||
try {
|
||||
return JSON.parse(decoded);
|
||||
}
|
||||
catch (e) {
|
||||
throw new InvalidTokenError(`Invalid token specified: invalid json for part #${pos + 1} (${e.message})`);
|
||||
}
|
||||
}
|
||||
exports.jwtDecode = jwtDecode;
|
||||
1
node_modules/jwt-decode/build/cjs/package.json
generated
vendored
Normal file
1
node_modules/jwt-decode/build/cjs/package.json
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
{"type": "commonjs"}
|
||||
23
node_modules/jwt-decode/build/esm/index.d.ts
generated
vendored
Normal file
23
node_modules/jwt-decode/build/esm/index.d.ts
generated
vendored
Normal file
@@ -0,0 +1,23 @@
|
||||
export interface JwtDecodeOptions {
|
||||
header?: boolean;
|
||||
}
|
||||
export interface JwtHeader {
|
||||
typ?: string;
|
||||
alg?: string;
|
||||
kid?: string;
|
||||
}
|
||||
export interface JwtPayload {
|
||||
iss?: string;
|
||||
sub?: string;
|
||||
aud?: string[] | string;
|
||||
exp?: number;
|
||||
nbf?: number;
|
||||
iat?: number;
|
||||
jti?: string;
|
||||
}
|
||||
export declare class InvalidTokenError extends Error {
|
||||
}
|
||||
export declare function jwtDecode<T = JwtHeader>(token: string, options: JwtDecodeOptions & {
|
||||
header: true;
|
||||
}): T;
|
||||
export declare function jwtDecode<T = JwtPayload>(token: string, options?: JwtDecodeOptions): T;
|
||||
57
node_modules/jwt-decode/build/esm/index.js
generated
vendored
Normal file
57
node_modules/jwt-decode/build/esm/index.js
generated
vendored
Normal file
@@ -0,0 +1,57 @@
|
||||
export class InvalidTokenError extends Error {
|
||||
}
|
||||
InvalidTokenError.prototype.name = "InvalidTokenError";
|
||||
function b64DecodeUnicode(str) {
|
||||
return decodeURIComponent(atob(str).replace(/(.)/g, (m, p) => {
|
||||
let code = p.charCodeAt(0).toString(16).toUpperCase();
|
||||
if (code.length < 2) {
|
||||
code = "0" + code;
|
||||
}
|
||||
return "%" + code;
|
||||
}));
|
||||
}
|
||||
function base64UrlDecode(str) {
|
||||
let output = str.replace(/-/g, "+").replace(/_/g, "/");
|
||||
switch (output.length % 4) {
|
||||
case 0:
|
||||
break;
|
||||
case 2:
|
||||
output += "==";
|
||||
break;
|
||||
case 3:
|
||||
output += "=";
|
||||
break;
|
||||
default:
|
||||
throw new Error("base64 string is not of the correct length");
|
||||
}
|
||||
try {
|
||||
return b64DecodeUnicode(output);
|
||||
}
|
||||
catch (err) {
|
||||
return atob(output);
|
||||
}
|
||||
}
|
||||
export function jwtDecode(token, options) {
|
||||
if (typeof token !== "string") {
|
||||
throw new InvalidTokenError("Invalid token specified: must be a string");
|
||||
}
|
||||
options || (options = {});
|
||||
const pos = options.header === true ? 0 : 1;
|
||||
const part = token.split(".")[pos];
|
||||
if (typeof part !== "string") {
|
||||
throw new InvalidTokenError(`Invalid token specified: missing part #${pos + 1}`);
|
||||
}
|
||||
let decoded;
|
||||
try {
|
||||
decoded = base64UrlDecode(part);
|
||||
}
|
||||
catch (e) {
|
||||
throw new InvalidTokenError(`Invalid token specified: invalid base64 for part #${pos + 1} (${e.message})`);
|
||||
}
|
||||
try {
|
||||
return JSON.parse(decoded);
|
||||
}
|
||||
catch (e) {
|
||||
throw new InvalidTokenError(`Invalid token specified: invalid json for part #${pos + 1} (${e.message})`);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user