@hemia/jwt-manager 0.0.3 → 0.0.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -5,7 +5,7 @@ import require$$1 from 'crypto';
|
|
|
5
5
|
|
|
6
6
|
var jwtConfig = {
|
|
7
7
|
expiresIn: '2h',
|
|
8
|
-
cleanCredentialSecret: '
|
|
8
|
+
cleanCredentialSecret: 'clean-credential-secret-key',
|
|
9
9
|
};
|
|
10
10
|
|
|
11
11
|
var Operatives;
|
|
@@ -2124,56 +2124,47 @@ const coerce$1 = (version, options) => {
|
|
|
2124
2124
|
};
|
|
2125
2125
|
var coerce_1 = coerce$1;
|
|
2126
2126
|
|
|
2127
|
-
|
|
2128
|
-
|
|
2129
|
-
|
|
2130
|
-
|
|
2131
|
-
|
|
2132
|
-
hasRequiredLrucache = 1;
|
|
2133
|
-
|
|
2134
|
-
class LRUCache {
|
|
2135
|
-
constructor () {
|
|
2136
|
-
this.max = 1000;
|
|
2137
|
-
this.map = new Map();
|
|
2138
|
-
}
|
|
2139
|
-
|
|
2140
|
-
get (key) {
|
|
2141
|
-
const value = this.map.get(key);
|
|
2142
|
-
if (value === undefined) {
|
|
2143
|
-
return undefined
|
|
2144
|
-
} else {
|
|
2145
|
-
// Remove the key from the map and add it to the end
|
|
2146
|
-
this.map.delete(key);
|
|
2147
|
-
this.map.set(key, value);
|
|
2148
|
-
return value
|
|
2149
|
-
}
|
|
2150
|
-
}
|
|
2127
|
+
class LRUCache {
|
|
2128
|
+
constructor () {
|
|
2129
|
+
this.max = 1000;
|
|
2130
|
+
this.map = new Map();
|
|
2131
|
+
}
|
|
2151
2132
|
|
|
2152
|
-
|
|
2153
|
-
|
|
2154
|
-
|
|
2133
|
+
get (key) {
|
|
2134
|
+
const value = this.map.get(key);
|
|
2135
|
+
if (value === undefined) {
|
|
2136
|
+
return undefined
|
|
2137
|
+
} else {
|
|
2138
|
+
// Remove the key from the map and add it to the end
|
|
2139
|
+
this.map.delete(key);
|
|
2140
|
+
this.map.set(key, value);
|
|
2141
|
+
return value
|
|
2142
|
+
}
|
|
2143
|
+
}
|
|
2155
2144
|
|
|
2156
|
-
|
|
2157
|
-
|
|
2145
|
+
delete (key) {
|
|
2146
|
+
return this.map.delete(key)
|
|
2147
|
+
}
|
|
2158
2148
|
|
|
2159
|
-
|
|
2160
|
-
|
|
2161
|
-
if (this.map.size >= this.max) {
|
|
2162
|
-
const firstKey = this.map.keys().next().value;
|
|
2163
|
-
this.delete(firstKey);
|
|
2164
|
-
}
|
|
2149
|
+
set (key, value) {
|
|
2150
|
+
const deleted = this.delete(key);
|
|
2165
2151
|
|
|
2166
|
-
|
|
2167
|
-
|
|
2152
|
+
if (!deleted && value !== undefined) {
|
|
2153
|
+
// If cache is full, delete the least recently used item
|
|
2154
|
+
if (this.map.size >= this.max) {
|
|
2155
|
+
const firstKey = this.map.keys().next().value;
|
|
2156
|
+
this.delete(firstKey);
|
|
2157
|
+
}
|
|
2168
2158
|
|
|
2169
|
-
|
|
2170
|
-
|
|
2171
|
-
}
|
|
2159
|
+
this.map.set(key, value);
|
|
2160
|
+
}
|
|
2172
2161
|
|
|
2173
|
-
|
|
2174
|
-
|
|
2162
|
+
return this
|
|
2163
|
+
}
|
|
2175
2164
|
}
|
|
2176
2165
|
|
|
2166
|
+
var lrucache = LRUCache;
|
|
2167
|
+
|
|
2177
2168
|
var range;
|
|
2178
2169
|
var hasRequiredRange;
|
|
2179
2170
|
|
|
@@ -2395,7 +2386,7 @@ function requireRange () {
|
|
|
2395
2386
|
|
|
2396
2387
|
range = Range;
|
|
2397
2388
|
|
|
2398
|
-
const LRU =
|
|
2389
|
+
const LRU = lrucache;
|
|
2399
2390
|
const cache = new LRU();
|
|
2400
2391
|
|
|
2401
2392
|
const parseOptions = parseOptions_1;
|
|
@@ -5918,8 +5909,8 @@ class JwtManager extends Mixin {
|
|
|
5918
5909
|
createTokenWithSecret(payload, secretKey, expiresIn, options) {
|
|
5919
5910
|
return this.createBasicToken(payload, secretKey, expiresIn || jwtConfig.expiresIn, Object.assign(Object.assign({}, options), { issuer: (options === null || options === void 0 ? void 0 : options.issuer) || this._issuer, audience: (options === null || options === void 0 ? void 0 : options.audience) || this._audience }));
|
|
5920
5911
|
}
|
|
5921
|
-
createCleanCredentialsToken(operative = Operatives.CATALOG, secretKey, expiresIn) {
|
|
5922
|
-
const payload = { accessType: operative };
|
|
5912
|
+
createCleanCredentialsToken(operative = Operatives.CATALOG, secretKey, expiresIn, customClaims) {
|
|
5913
|
+
const payload = Object.assign({ accessType: operative }, customClaims);
|
|
5923
5914
|
return this.createBasicToken(payload, secretKey || this._secretKey, expiresIn || jwtConfig.expiresIn);
|
|
5924
5915
|
}
|
|
5925
5916
|
getTokenWithoutKey(payload, secretKey, expiresIn, options) {
|
|
@@ -5931,31 +5922,19 @@ class JwtManager extends Mixin {
|
|
|
5931
5922
|
getTokenCleanCredentials(operative = Operatives.CATALOG, secretKey, expiresIn) {
|
|
5932
5923
|
return this.createCleanCredentialsToken(operative, secretKey, expiresIn);
|
|
5933
5924
|
}
|
|
5934
|
-
createIdToken(claims, secretKey, expiresIn) {
|
|
5925
|
+
createIdToken(claims, secretKey, expiresIn, customClaims) {
|
|
5935
5926
|
if (!claims.sub) {
|
|
5936
5927
|
throw new Error('sub (subject) claim is required for ID tokens');
|
|
5937
5928
|
}
|
|
5938
|
-
const payload = Object.assign(Object.assign({}, claims), {
|
|
5929
|
+
const payload = Object.assign(Object.assign(Object.assign({}, claims), { iat: Math.floor(Date.now() / 1000) }), customClaims);
|
|
5939
5930
|
return this.createBasicToken(payload, secretKey || this._secretKey, expiresIn || jwtConfig.expiresIn, { issuer: this._issuer, audience: this._audience });
|
|
5940
5931
|
}
|
|
5941
|
-
createAccessToken(sub, scopes, secretKey, expiresIn) {
|
|
5942
|
-
const payload = {
|
|
5943
|
-
sub,
|
|
5944
|
-
scope: scopes.join(' '),
|
|
5945
|
-
iss: this._issuer,
|
|
5946
|
-
aud: this._audience,
|
|
5947
|
-
iat: Math.floor(Date.now() / 1000),
|
|
5948
|
-
};
|
|
5932
|
+
createAccessToken(sub, scopes, secretKey, expiresIn, customClaims) {
|
|
5933
|
+
const payload = Object.assign({ sub, scope: scopes.join(' '), iat: Math.floor(Date.now() / 1000) }, customClaims);
|
|
5949
5934
|
return this.createBasicToken(payload, secretKey || this._secretKey, expiresIn || '15m', { issuer: this._issuer, audience: this._audience });
|
|
5950
5935
|
}
|
|
5951
|
-
createRefreshToken(sub, secretKey, expiresIn) {
|
|
5952
|
-
const payload = {
|
|
5953
|
-
sub,
|
|
5954
|
-
type: 'refresh',
|
|
5955
|
-
iss: this._issuer,
|
|
5956
|
-
aud: this._audience,
|
|
5957
|
-
iat: Math.floor(Date.now() / 1000),
|
|
5958
|
-
};
|
|
5936
|
+
createRefreshToken(sub, secretKey, expiresIn, customClaims) {
|
|
5937
|
+
const payload = Object.assign({ sub, type: 'refresh', iat: Math.floor(Date.now() / 1000) }, customClaims);
|
|
5959
5938
|
return this.createBasicToken(payload, secretKey || this._secretKey, expiresIn || '30d', {
|
|
5960
5939
|
issuer: this._issuer,
|
|
5961
5940
|
audience: this._audience,
|
|
@@ -7,7 +7,7 @@ var require$$1 = require('crypto');
|
|
|
7
7
|
|
|
8
8
|
var jwtConfig = {
|
|
9
9
|
expiresIn: '2h',
|
|
10
|
-
cleanCredentialSecret: '
|
|
10
|
+
cleanCredentialSecret: 'clean-credential-secret-key',
|
|
11
11
|
};
|
|
12
12
|
|
|
13
13
|
exports.Operatives = void 0;
|
|
@@ -2126,56 +2126,47 @@ const coerce$1 = (version, options) => {
|
|
|
2126
2126
|
};
|
|
2127
2127
|
var coerce_1 = coerce$1;
|
|
2128
2128
|
|
|
2129
|
-
|
|
2130
|
-
|
|
2131
|
-
|
|
2132
|
-
|
|
2133
|
-
|
|
2134
|
-
hasRequiredLrucache = 1;
|
|
2135
|
-
|
|
2136
|
-
class LRUCache {
|
|
2137
|
-
constructor () {
|
|
2138
|
-
this.max = 1000;
|
|
2139
|
-
this.map = new Map();
|
|
2140
|
-
}
|
|
2141
|
-
|
|
2142
|
-
get (key) {
|
|
2143
|
-
const value = this.map.get(key);
|
|
2144
|
-
if (value === undefined) {
|
|
2145
|
-
return undefined
|
|
2146
|
-
} else {
|
|
2147
|
-
// Remove the key from the map and add it to the end
|
|
2148
|
-
this.map.delete(key);
|
|
2149
|
-
this.map.set(key, value);
|
|
2150
|
-
return value
|
|
2151
|
-
}
|
|
2152
|
-
}
|
|
2129
|
+
class LRUCache {
|
|
2130
|
+
constructor () {
|
|
2131
|
+
this.max = 1000;
|
|
2132
|
+
this.map = new Map();
|
|
2133
|
+
}
|
|
2153
2134
|
|
|
2154
|
-
|
|
2155
|
-
|
|
2156
|
-
|
|
2135
|
+
get (key) {
|
|
2136
|
+
const value = this.map.get(key);
|
|
2137
|
+
if (value === undefined) {
|
|
2138
|
+
return undefined
|
|
2139
|
+
} else {
|
|
2140
|
+
// Remove the key from the map and add it to the end
|
|
2141
|
+
this.map.delete(key);
|
|
2142
|
+
this.map.set(key, value);
|
|
2143
|
+
return value
|
|
2144
|
+
}
|
|
2145
|
+
}
|
|
2157
2146
|
|
|
2158
|
-
|
|
2159
|
-
|
|
2147
|
+
delete (key) {
|
|
2148
|
+
return this.map.delete(key)
|
|
2149
|
+
}
|
|
2160
2150
|
|
|
2161
|
-
|
|
2162
|
-
|
|
2163
|
-
if (this.map.size >= this.max) {
|
|
2164
|
-
const firstKey = this.map.keys().next().value;
|
|
2165
|
-
this.delete(firstKey);
|
|
2166
|
-
}
|
|
2151
|
+
set (key, value) {
|
|
2152
|
+
const deleted = this.delete(key);
|
|
2167
2153
|
|
|
2168
|
-
|
|
2169
|
-
|
|
2154
|
+
if (!deleted && value !== undefined) {
|
|
2155
|
+
// If cache is full, delete the least recently used item
|
|
2156
|
+
if (this.map.size >= this.max) {
|
|
2157
|
+
const firstKey = this.map.keys().next().value;
|
|
2158
|
+
this.delete(firstKey);
|
|
2159
|
+
}
|
|
2170
2160
|
|
|
2171
|
-
|
|
2172
|
-
|
|
2173
|
-
}
|
|
2161
|
+
this.map.set(key, value);
|
|
2162
|
+
}
|
|
2174
2163
|
|
|
2175
|
-
|
|
2176
|
-
|
|
2164
|
+
return this
|
|
2165
|
+
}
|
|
2177
2166
|
}
|
|
2178
2167
|
|
|
2168
|
+
var lrucache = LRUCache;
|
|
2169
|
+
|
|
2179
2170
|
var range;
|
|
2180
2171
|
var hasRequiredRange;
|
|
2181
2172
|
|
|
@@ -2397,7 +2388,7 @@ function requireRange () {
|
|
|
2397
2388
|
|
|
2398
2389
|
range = Range;
|
|
2399
2390
|
|
|
2400
|
-
const LRU =
|
|
2391
|
+
const LRU = lrucache;
|
|
2401
2392
|
const cache = new LRU();
|
|
2402
2393
|
|
|
2403
2394
|
const parseOptions = parseOptions_1;
|
|
@@ -5920,8 +5911,8 @@ class JwtManager extends Mixin {
|
|
|
5920
5911
|
createTokenWithSecret(payload, secretKey, expiresIn, options) {
|
|
5921
5912
|
return this.createBasicToken(payload, secretKey, expiresIn || jwtConfig.expiresIn, Object.assign(Object.assign({}, options), { issuer: (options === null || options === void 0 ? void 0 : options.issuer) || this._issuer, audience: (options === null || options === void 0 ? void 0 : options.audience) || this._audience }));
|
|
5922
5913
|
}
|
|
5923
|
-
createCleanCredentialsToken(operative = exports.Operatives.CATALOG, secretKey, expiresIn) {
|
|
5924
|
-
const payload = { accessType: operative };
|
|
5914
|
+
createCleanCredentialsToken(operative = exports.Operatives.CATALOG, secretKey, expiresIn, customClaims) {
|
|
5915
|
+
const payload = Object.assign({ accessType: operative }, customClaims);
|
|
5925
5916
|
return this.createBasicToken(payload, secretKey || this._secretKey, expiresIn || jwtConfig.expiresIn);
|
|
5926
5917
|
}
|
|
5927
5918
|
getTokenWithoutKey(payload, secretKey, expiresIn, options) {
|
|
@@ -5933,31 +5924,19 @@ class JwtManager extends Mixin {
|
|
|
5933
5924
|
getTokenCleanCredentials(operative = exports.Operatives.CATALOG, secretKey, expiresIn) {
|
|
5934
5925
|
return this.createCleanCredentialsToken(operative, secretKey, expiresIn);
|
|
5935
5926
|
}
|
|
5936
|
-
createIdToken(claims, secretKey, expiresIn) {
|
|
5927
|
+
createIdToken(claims, secretKey, expiresIn, customClaims) {
|
|
5937
5928
|
if (!claims.sub) {
|
|
5938
5929
|
throw new Error('sub (subject) claim is required for ID tokens');
|
|
5939
5930
|
}
|
|
5940
|
-
const payload = Object.assign(Object.assign({}, claims), {
|
|
5931
|
+
const payload = Object.assign(Object.assign(Object.assign({}, claims), { iat: Math.floor(Date.now() / 1000) }), customClaims);
|
|
5941
5932
|
return this.createBasicToken(payload, secretKey || this._secretKey, expiresIn || jwtConfig.expiresIn, { issuer: this._issuer, audience: this._audience });
|
|
5942
5933
|
}
|
|
5943
|
-
createAccessToken(sub, scopes, secretKey, expiresIn) {
|
|
5944
|
-
const payload = {
|
|
5945
|
-
sub,
|
|
5946
|
-
scope: scopes.join(' '),
|
|
5947
|
-
iss: this._issuer,
|
|
5948
|
-
aud: this._audience,
|
|
5949
|
-
iat: Math.floor(Date.now() / 1000),
|
|
5950
|
-
};
|
|
5934
|
+
createAccessToken(sub, scopes, secretKey, expiresIn, customClaims) {
|
|
5935
|
+
const payload = Object.assign({ sub, scope: scopes.join(' '), iat: Math.floor(Date.now() / 1000) }, customClaims);
|
|
5951
5936
|
return this.createBasicToken(payload, secretKey || this._secretKey, expiresIn || '15m', { issuer: this._issuer, audience: this._audience });
|
|
5952
5937
|
}
|
|
5953
|
-
createRefreshToken(sub, secretKey, expiresIn) {
|
|
5954
|
-
const payload = {
|
|
5955
|
-
sub,
|
|
5956
|
-
type: 'refresh',
|
|
5957
|
-
iss: this._issuer,
|
|
5958
|
-
aud: this._audience,
|
|
5959
|
-
iat: Math.floor(Date.now() / 1000),
|
|
5960
|
-
};
|
|
5938
|
+
createRefreshToken(sub, secretKey, expiresIn, customClaims) {
|
|
5939
|
+
const payload = Object.assign({ sub, type: 'refresh', iat: Math.floor(Date.now() / 1000) }, customClaims);
|
|
5961
5940
|
return this.createBasicToken(payload, secretKey || this._secretKey, expiresIn || '30d', {
|
|
5962
5941
|
issuer: this._issuer,
|
|
5963
5942
|
audience: this._audience,
|
|
@@ -10,13 +10,13 @@ export declare class JwtManager extends Mixin {
|
|
|
10
10
|
constructor();
|
|
11
11
|
createToken(payload: object, secretKey?: string, expiresIn?: string | number, options?: SignOptions): string;
|
|
12
12
|
createTokenWithSecret(payload: object, secretKey: string, expiresIn?: string | number, options?: SignOptions): string;
|
|
13
|
-
createCleanCredentialsToken(operative?: Operatives, secretKey?: string, expiresIn?: string | number): string;
|
|
13
|
+
createCleanCredentialsToken(operative?: Operatives, secretKey?: string, expiresIn?: string | number, customClaims?: object): string;
|
|
14
14
|
getTokenWithoutKey(payload: object, secretKey?: string, expiresIn?: string | number, options?: SignOptions): string;
|
|
15
15
|
getTokenWithKey(payload: object, secretKey: string, expiresIn?: string | number, options?: SignOptions): string;
|
|
16
16
|
getTokenCleanCredentials(operative?: Operatives, secretKey?: string, expiresIn?: string | number): string;
|
|
17
|
-
createIdToken(claims: StandardClaims, secretKey?: string, expiresIn?: string | number): string;
|
|
18
|
-
createAccessToken(sub: string, scopes: string[], secretKey?: string, expiresIn?: string | number): string;
|
|
19
|
-
createRefreshToken(sub: string, secretKey?: string, expiresIn?: string | number): string;
|
|
17
|
+
createIdToken(claims: StandardClaims, secretKey?: string, expiresIn?: string | number, customClaims?: object): string;
|
|
18
|
+
createAccessToken(sub: string, scopes: string[], secretKey?: string, expiresIn?: string | number, customClaims?: object): string;
|
|
19
|
+
createRefreshToken(sub: string, secretKey?: string, expiresIn?: string | number, customClaims?: object): string;
|
|
20
20
|
verify(token: string, secretKey?: string, options?: VerifyOptions): JwtPayload | null;
|
|
21
21
|
verifyDetailed(token: string, secretKey?: string, options?: VerifyOptions): TokenValidationResult;
|
|
22
22
|
validateToken(token: string, secretKey?: string, options?: VerifyOptions): JwtPayload | null;
|
package/package.json
CHANGED