@argos-js/auth 0.0.0-stage → 0.1.0
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.
- package/LICENSE +21 -0
- package/README.md +13 -2
- package/dist/certificates/cert-parser.d.ts +19 -0
- package/dist/certificates/cert-parser.d.ts.map +1 -0
- package/dist/certificates/cert-parser.js +192 -0
- package/dist/certificates/cert-parser.js.map +1 -0
- package/dist/certificates/cert.types.d.ts +60 -0
- package/dist/certificates/cert.types.d.ts.map +1 -0
- package/dist/certificates/cert.types.js +3 -0
- package/dist/certificates/cert.types.js.map +1 -0
- package/dist/certificates/index.d.ts +5 -0
- package/dist/certificates/index.d.ts.map +1 -0
- package/dist/certificates/index.js +21 -0
- package/dist/certificates/index.js.map +1 -0
- package/dist/certificates/jwks.d.ts +90 -0
- package/dist/certificates/jwks.d.ts.map +1 -0
- package/dist/certificates/jwks.js +180 -0
- package/dist/certificates/jwks.js.map +1 -0
- package/dist/certificates/mtls.guard.d.ts +10 -0
- package/dist/certificates/mtls.guard.d.ts.map +1 -0
- package/dist/certificates/mtls.guard.js +156 -0
- package/dist/certificates/mtls.guard.js.map +1 -0
- package/dist/config.d.ts +33 -0
- package/dist/config.d.ts.map +1 -0
- package/dist/config.js +10 -0
- package/dist/config.js.map +1 -0
- package/dist/guards/api-key.guard.d.ts +21 -0
- package/dist/guards/api-key.guard.d.ts.map +1 -0
- package/dist/guards/api-key.guard.js +106 -0
- package/dist/guards/api-key.guard.js.map +1 -0
- package/dist/guards/basic.d.ts +6 -0
- package/dist/guards/basic.d.ts.map +1 -0
- package/dist/guards/basic.guard.d.ts +26 -0
- package/dist/guards/basic.guard.d.ts.map +1 -0
- package/dist/guards/basic.guard.js +123 -0
- package/dist/guards/basic.guard.js.map +1 -0
- package/dist/guards/basic.js +42 -0
- package/dist/guards/basic.js.map +1 -0
- package/dist/guards/guard.interface.d.ts +21 -0
- package/dist/guards/guard.interface.d.ts.map +1 -0
- package/dist/guards/guard.interface.js +3 -0
- package/dist/guards/guard.interface.js.map +1 -0
- package/dist/guards/hmac.guard.d.ts +18 -0
- package/dist/guards/hmac.guard.d.ts.map +1 -0
- package/dist/guards/hmac.guard.js +111 -0
- package/dist/guards/hmac.guard.js.map +1 -0
- package/dist/guards/index.d.ts +8 -0
- package/dist/guards/index.d.ts.map +1 -0
- package/dist/guards/index.js +24 -0
- package/dist/guards/index.js.map +1 -0
- package/dist/guards/jwt.guard.d.ts +17 -0
- package/dist/guards/jwt.guard.d.ts.map +1 -0
- package/dist/guards/jwt.guard.js +92 -0
- package/dist/guards/jwt.guard.js.map +1 -0
- package/dist/hasher/argon2-hasher.d.ts +31 -0
- package/dist/hasher/argon2-hasher.d.ts.map +1 -0
- package/dist/hasher/argon2-hasher.js +114 -0
- package/dist/hasher/argon2-hasher.js.map +1 -0
- package/dist/hasher/hasher.interface.d.ts +22 -0
- package/dist/hasher/hasher.interface.d.ts.map +1 -0
- package/dist/hasher/hasher.interface.js +3 -0
- package/dist/hasher/hasher.interface.js.map +1 -0
- package/dist/hasher/index.d.ts +5 -0
- package/dist/hasher/index.d.ts.map +1 -0
- package/dist/hasher/index.js +21 -0
- package/dist/hasher/index.js.map +1 -0
- package/dist/hasher/password-manager.d.ts +52 -0
- package/dist/hasher/password-manager.d.ts.map +1 -0
- package/dist/hasher/password-manager.js +126 -0
- package/dist/hasher/password-manager.js.map +1 -0
- package/dist/hasher/scrypt-hasher.d.ts +30 -0
- package/dist/hasher/scrypt-hasher.d.ts.map +1 -0
- package/dist/hasher/scrypt-hasher.js +158 -0
- package/dist/hasher/scrypt-hasher.js.map +1 -0
- package/dist/index.d.ts +9 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +32 -0
- package/dist/index.js.map +1 -0
- package/dist/middleware/auth.middleware.d.ts +42 -0
- package/dist/middleware/auth.middleware.d.ts.map +1 -0
- package/dist/middleware/auth.middleware.js +142 -0
- package/dist/middleware/auth.middleware.js.map +1 -0
- package/dist/middleware/index.d.ts +2 -0
- package/dist/middleware/index.d.ts.map +1 -0
- package/dist/middleware/index.js +18 -0
- package/dist/middleware/index.js.map +1 -0
- package/dist/oauth/base.provider.d.ts +27 -0
- package/dist/oauth/base.provider.d.ts.map +1 -0
- package/dist/oauth/base.provider.js +139 -0
- package/dist/oauth/base.provider.js.map +1 -0
- package/dist/oauth/index.d.ts +6 -0
- package/dist/oauth/index.d.ts.map +1 -0
- package/dist/oauth/index.js +22 -0
- package/dist/oauth/index.js.map +1 -0
- package/dist/oauth/oauth-manager.d.ts +41 -0
- package/dist/oauth/oauth-manager.d.ts.map +1 -0
- package/dist/oauth/oauth-manager.js +58 -0
- package/dist/oauth/oauth-manager.js.map +1 -0
- package/dist/oauth/oauth.types.d.ts +55 -0
- package/dist/oauth/oauth.types.d.ts.map +1 -0
- package/dist/oauth/oauth.types.js +3 -0
- package/dist/oauth/oauth.types.js.map +1 -0
- package/dist/oauth/pkce.d.ts +26 -0
- package/dist/oauth/pkce.d.ts.map +1 -0
- package/dist/oauth/pkce.js +136 -0
- package/dist/oauth/pkce.js.map +1 -0
- package/dist/oauth/providers/generic-oidc.provider.d.ts +25 -0
- package/dist/oauth/providers/generic-oidc.provider.d.ts.map +1 -0
- package/dist/oauth/providers/generic-oidc.provider.js +43 -0
- package/dist/oauth/providers/generic-oidc.provider.js.map +1 -0
- package/dist/oauth/providers/github.provider.d.ts +15 -0
- package/dist/oauth/providers/github.provider.d.ts.map +1 -0
- package/dist/oauth/providers/github.provider.js +70 -0
- package/dist/oauth/providers/github.provider.js.map +1 -0
- package/dist/oauth/providers/google.provider.d.ts +12 -0
- package/dist/oauth/providers/google.provider.d.ts.map +1 -0
- package/dist/oauth/providers/google.provider.js +27 -0
- package/dist/oauth/providers/google.provider.js.map +1 -0
- package/dist/oauth/providers/index.d.ts +5 -0
- package/dist/oauth/providers/index.d.ts.map +1 -0
- package/dist/oauth/providers/index.js +21 -0
- package/dist/oauth/providers/index.js.map +1 -0
- package/dist/oauth/providers/microsoft.provider.d.ts +13 -0
- package/dist/oauth/providers/microsoft.provider.d.ts.map +1 -0
- package/dist/oauth/providers/microsoft.provider.js +28 -0
- package/dist/oauth/providers/microsoft.provider.js.map +1 -0
- package/dist/oauth2/client.d.ts +63 -0
- package/dist/oauth2/client.d.ts.map +1 -0
- package/dist/oauth2/client.js +150 -0
- package/dist/oauth2/client.js.map +1 -0
- package/dist/oauth2/index.d.ts +2 -0
- package/dist/oauth2/index.d.ts.map +1 -0
- package/dist/oauth2/index.js +18 -0
- package/dist/oauth2/index.js.map +1 -0
- package/dist/tokens/api-key.d.ts +26 -0
- package/dist/tokens/api-key.d.ts.map +1 -0
- package/dist/tokens/api-key.js +84 -0
- package/dist/tokens/api-key.js.map +1 -0
- package/dist/tokens/index.d.ts +3 -0
- package/dist/tokens/index.d.ts.map +1 -0
- package/dist/tokens/index.js +19 -0
- package/dist/tokens/index.js.map +1 -0
- package/dist/tokens/jwt.d.ts +93 -0
- package/dist/tokens/jwt.d.ts.map +1 -0
- package/dist/tokens/jwt.js +327 -0
- package/dist/tokens/jwt.js.map +1 -0
- package/package.json +38 -3
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.defaultPasswordManager = exports.PasswordManager = void 0;
|
|
4
|
+
exports.hashPassword = hashPassword;
|
|
5
|
+
exports.verifyPassword = verifyPassword;
|
|
6
|
+
exports.needsRehash = needsRehash;
|
|
7
|
+
const scrypt_hasher_1 = require("./scrypt-hasher");
|
|
8
|
+
const argon2_hasher_1 = require("./argon2-hasher");
|
|
9
|
+
/**
|
|
10
|
+
* Unified Password Manager coordinating multi-algorithm hashing and verification.
|
|
11
|
+
* Automatically inspects stored hash prefixes ($argon2id$, $scrypt$, etc.) to verify
|
|
12
|
+
* without requiring the caller to specify which algorithm was used.
|
|
13
|
+
*/
|
|
14
|
+
class PasswordManager {
|
|
15
|
+
hashers = new Map();
|
|
16
|
+
defaultAlgorithm;
|
|
17
|
+
constructor(options = {}) {
|
|
18
|
+
const scrypt = new scrypt_hasher_1.ScryptHasher(options.scrypt);
|
|
19
|
+
const argon2 = new argon2_hasher_1.Argon2Hasher(options.argon2);
|
|
20
|
+
this.register('scrypt', scrypt);
|
|
21
|
+
this.register('argon2id', argon2);
|
|
22
|
+
this.register('argon2', argon2);
|
|
23
|
+
if (options.default) {
|
|
24
|
+
this.defaultAlgorithm = options.default;
|
|
25
|
+
}
|
|
26
|
+
else if (argon2.isAvailable()) {
|
|
27
|
+
this.defaultAlgorithm = 'argon2';
|
|
28
|
+
}
|
|
29
|
+
else {
|
|
30
|
+
this.defaultAlgorithm = 'scrypt';
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Registers a custom hasher implementation.
|
|
35
|
+
*/
|
|
36
|
+
register(name, hasher) {
|
|
37
|
+
this.hashers.set(name.toLowerCase(), hasher);
|
|
38
|
+
return this;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Hashes a password using the default or specified algorithm.
|
|
42
|
+
*/
|
|
43
|
+
async hash(password, algorithm) {
|
|
44
|
+
const targetAlgo = (algorithm ?? this.defaultAlgorithm).toLowerCase();
|
|
45
|
+
const hasher = this.hashers.get(targetAlgo);
|
|
46
|
+
if (!hasher) {
|
|
47
|
+
throw new Error(`Password hasher for algorithm "${targetAlgo}" is not registered`);
|
|
48
|
+
}
|
|
49
|
+
return hasher.hash(password);
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Verifies a password against any supported stored hash format.
|
|
53
|
+
*/
|
|
54
|
+
async verify(password, hash) {
|
|
55
|
+
if (!password || !hash) {
|
|
56
|
+
return false;
|
|
57
|
+
}
|
|
58
|
+
const trimmed = hash.trim();
|
|
59
|
+
// Auto-detect algorithm based on PHC format prefix
|
|
60
|
+
if (trimmed.startsWith('$argon2')) {
|
|
61
|
+
const hasher = this.hashers.get('argon2') || this.hashers.get('argon2id');
|
|
62
|
+
if (hasher)
|
|
63
|
+
return hasher.verify(password, trimmed);
|
|
64
|
+
}
|
|
65
|
+
if (trimmed.startsWith('$scrypt$')) {
|
|
66
|
+
const hasher = this.hashers.get('scrypt');
|
|
67
|
+
if (hasher)
|
|
68
|
+
return hasher.verify(password, trimmed);
|
|
69
|
+
}
|
|
70
|
+
// Fallback: try default hasher
|
|
71
|
+
const defaultHasher = this.hashers.get(this.defaultAlgorithm);
|
|
72
|
+
if (defaultHasher) {
|
|
73
|
+
return defaultHasher.verify(password, trimmed);
|
|
74
|
+
}
|
|
75
|
+
return false;
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Checks if the stored hash should be upgraded (e.g. algorithm migrated or cost increased).
|
|
79
|
+
*/
|
|
80
|
+
needsRehash(hash) {
|
|
81
|
+
if (!hash)
|
|
82
|
+
return true;
|
|
83
|
+
const trimmed = hash.trim();
|
|
84
|
+
const defaultHasher = this.hashers.get(this.defaultAlgorithm);
|
|
85
|
+
if (!defaultHasher)
|
|
86
|
+
return true;
|
|
87
|
+
// Check if the hash matches the default algorithm
|
|
88
|
+
if (this.defaultAlgorithm === 'argon2' || this.defaultAlgorithm === 'argon2id') {
|
|
89
|
+
if (!trimmed.startsWith('$argon2'))
|
|
90
|
+
return true;
|
|
91
|
+
}
|
|
92
|
+
else if (this.defaultAlgorithm === 'scrypt') {
|
|
93
|
+
if (!trimmed.startsWith('$scrypt$'))
|
|
94
|
+
return true;
|
|
95
|
+
}
|
|
96
|
+
return defaultHasher.needsRehash(trimmed);
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* Returns the name of the current default algorithm.
|
|
100
|
+
*/
|
|
101
|
+
getDefaultAlgorithm() {
|
|
102
|
+
return this.defaultAlgorithm;
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
exports.PasswordManager = PasswordManager;
|
|
106
|
+
// Global default singleton
|
|
107
|
+
exports.defaultPasswordManager = new PasswordManager();
|
|
108
|
+
/**
|
|
109
|
+
* Convenience helper: Hashes password using the default enterprise hasher.
|
|
110
|
+
*/
|
|
111
|
+
function hashPassword(password, algorithm) {
|
|
112
|
+
return exports.defaultPasswordManager.hash(password, algorithm);
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* Convenience helper: Verifies password against stored hash.
|
|
116
|
+
*/
|
|
117
|
+
function verifyPassword(password, hash) {
|
|
118
|
+
return exports.defaultPasswordManager.verify(password, hash);
|
|
119
|
+
}
|
|
120
|
+
/**
|
|
121
|
+
* Convenience helper: Checks if hash needs re-hashing.
|
|
122
|
+
*/
|
|
123
|
+
function needsRehash(hash) {
|
|
124
|
+
return exports.defaultPasswordManager.needsRehash(hash);
|
|
125
|
+
}
|
|
126
|
+
//# sourceMappingURL=password-manager.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"password-manager.js","sourceRoot":"","sources":["../../src/hasher/password-manager.ts"],"names":[],"mappings":";;;AA0HA,oCAEC;AAKD,wCAEC;AAKD,kCAEC;AAzID,mDAAyE;AACzE,mDAAyE;AAQzE;;;;GAIG;AACH,MAAa,eAAe;IAClB,OAAO,GAAG,IAAI,GAAG,EAAkB,CAAC;IACpC,gBAAgB,CAAS;IAEjC,YAAY,UAAkC,EAAE;QAC9C,MAAM,MAAM,GAAG,IAAI,4BAAY,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC;QAChD,MAAM,MAAM,GAAG,IAAI,4BAAY,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC;QAEhD,IAAI,CAAC,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC,CAAC;QAChC,IAAI,CAAC,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC,CAAC;QAClC,IAAI,CAAC,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC,CAAC;QAEhC,IAAI,OAAO,CAAC,OAAO,EAAE,CAAC;YACpB,IAAI,CAAC,gBAAgB,GAAG,OAAO,CAAC,OAAO,CAAC;QAC1C,CAAC;a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C;IAC5C,CAAC;IAED;;OAEG;IACI,mBAAmB;QACxB,OAAO,IAAI,CAAC,gBAAgB,CAAC;IAC/B,CAAC;CACF;AAnGD,0CAmGC;AAED,2BAA2B;AACd,QAAA,sBAAsB,GAAG,IAAI,eAAe,EAAE,CAAC;AAE5D;;GAEG;AACH,SAAgB,YAAY,CAAC,QAAgB,EAAE,SAAkB;IAC/D,OAAO,8BAAsB,CAAC,IAAI,CAAC,QAAQ,EAAE,SAAS,CAAC,CAAC;AAC1D,CAAC;AAED;;GAEG;AACH,SAAgB,cAAc,CAAC,QAAgB,EAAE,IAAY;IAC3D,OAAO,8BAAsB,CAAC,MAAM,CAAC,QAAQ,EAAE,IAAI,CAAC,CAAC;AACvD,CAAC;AAED;;GAEG;AACH,SAAgB,WAAW,CAAC,IAAY;IACtC,OAAO,8BAAsB,CAAC,WAAW,CAAC,IAAI,CAAC,CAAC;AAClD,CAAC"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import type { Hasher } from './hasher.interface';
|
|
2
|
+
export interface ScryptHasherOptions {
|
|
3
|
+
cost?: number;
|
|
4
|
+
blockSize?: number;
|
|
5
|
+
parallelization?: number;
|
|
6
|
+
parallel?: number;
|
|
7
|
+
keyLength?: number;
|
|
8
|
+
saltLength?: number;
|
|
9
|
+
maxmem?: number;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Enterprise-grade Scrypt password hasher backed natively by node:crypto.
|
|
13
|
+
* Generates standard PHC formatted strings:
|
|
14
|
+
* `$scrypt$ln=<N_log2>,r=<r>,p=<p>$<salt_b64url>$<hash_b64url>`
|
|
15
|
+
*/
|
|
16
|
+
export declare class ScryptHasher implements Hasher {
|
|
17
|
+
readonly algorithm = "scrypt";
|
|
18
|
+
private readonly cost;
|
|
19
|
+
private readonly blockSize;
|
|
20
|
+
private readonly parallelization;
|
|
21
|
+
private readonly keyLength;
|
|
22
|
+
private readonly saltLength;
|
|
23
|
+
private readonly maxmem;
|
|
24
|
+
constructor(options?: ScryptHasherOptions);
|
|
25
|
+
hash(password: string, customOptions?: ScryptHasherOptions): Promise<string>;
|
|
26
|
+
verify(password: string, hash: string): Promise<boolean>;
|
|
27
|
+
needsRehash(hash: string, customOptions?: ScryptHasherOptions): boolean;
|
|
28
|
+
private deriveKey;
|
|
29
|
+
}
|
|
30
|
+
//# sourceMappingURL=scrypt-hasher.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"scrypt-hasher.d.ts","sourceRoot":"","sources":["../../src/hasher/scrypt-hasher.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAC;AAEjD,MAAM,WAAW,mBAAmB;IAClC,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AAED;;;;GAIG;AACH,qBAAa,YAAa,YAAW,MAAM;IACzC,SAAgB,SAAS,YAAY;IAErC,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAS;IAC9B,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAS;IACnC,OAAO,CAAC,QAAQ,CAAC,eAAe,CAAS;IACzC,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAS;IACnC,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAS;IACpC,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAS;gBAEpB,OAAO,GAAE,mBAAwB;IAShC,IAAI,CAAC,QAAQ,EAAE,MAAM,EAAE,aAAa,GAAE,mBAAwB,GAAG,OAAO,CAAC,MAAM,CAAC;IAkBhF,MAAM,CAAC,QAAQ,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;IAuD9D,WAAW,CAAC,IAAI,EAAE,MAAM,EAAE,aAAa,GAAE,mBAAwB,GAAG,OAAO;IA4BlF,OAAO,CAAC,SAAS;CA2BlB"}
|
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
exports.ScryptHasher = void 0;
|
|
37
|
+
const crypto = __importStar(require("node:crypto"));
|
|
38
|
+
/**
|
|
39
|
+
* Enterprise-grade Scrypt password hasher backed natively by node:crypto.
|
|
40
|
+
* Generates standard PHC formatted strings:
|
|
41
|
+
* `$scrypt$ln=<N_log2>,r=<r>,p=<p>$<salt_b64url>$<hash_b64url>`
|
|
42
|
+
*/
|
|
43
|
+
class ScryptHasher {
|
|
44
|
+
algorithm = 'scrypt';
|
|
45
|
+
cost;
|
|
46
|
+
blockSize;
|
|
47
|
+
parallelization;
|
|
48
|
+
keyLength;
|
|
49
|
+
saltLength;
|
|
50
|
+
maxmem;
|
|
51
|
+
constructor(options = {}) {
|
|
52
|
+
this.cost = options.cost ?? 16384;
|
|
53
|
+
this.blockSize = options.blockSize ?? 8;
|
|
54
|
+
this.parallelization = options.parallelization ?? options.parallel ?? 1;
|
|
55
|
+
this.keyLength = options.keyLength ?? 32;
|
|
56
|
+
this.saltLength = options.saltLength ?? 16;
|
|
57
|
+
this.maxmem = options.maxmem ?? 32 * 1024 * 1024;
|
|
58
|
+
}
|
|
59
|
+
async hash(password, customOptions = {}) {
|
|
60
|
+
const cost = customOptions.cost ?? this.cost;
|
|
61
|
+
const blockSize = customOptions.blockSize ?? this.blockSize;
|
|
62
|
+
const parallelization = customOptions.parallelization ?? this.parallelization;
|
|
63
|
+
const keyLength = customOptions.keyLength ?? this.keyLength;
|
|
64
|
+
const saltLength = customOptions.saltLength ?? this.saltLength;
|
|
65
|
+
const maxmem = customOptions.maxmem ?? this.maxmem;
|
|
66
|
+
const salt = crypto.randomBytes(saltLength);
|
|
67
|
+
const derivedKey = await this.deriveKey(password, salt, cost, blockSize, parallelization, keyLength, maxmem);
|
|
68
|
+
const log2Cost = Math.round(Math.log2(cost));
|
|
69
|
+
const saltB64 = salt.toString('base64url');
|
|
70
|
+
const hashB64 = derivedKey.toString('base64url');
|
|
71
|
+
return `$scrypt$ln=${log2Cost},r=${blockSize},p=${parallelization}$${saltB64}$${hashB64}`;
|
|
72
|
+
}
|
|
73
|
+
async verify(password, hash) {
|
|
74
|
+
if (!hash || !hash.startsWith('$scrypt$')) {
|
|
75
|
+
return false;
|
|
76
|
+
}
|
|
77
|
+
const parts = hash.split('$');
|
|
78
|
+
// parts[0] === ''
|
|
79
|
+
// parts[1] === 'scrypt'
|
|
80
|
+
// parts[2] === params (ln=14,r=8,p=1)
|
|
81
|
+
// parts[3] === saltB64
|
|
82
|
+
// parts[4] === hashB64
|
|
83
|
+
if (parts.length !== 5) {
|
|
84
|
+
return false;
|
|
85
|
+
}
|
|
86
|
+
const paramsStr = parts[2];
|
|
87
|
+
const saltB64 = parts[3];
|
|
88
|
+
const hashB64 = parts[4];
|
|
89
|
+
let ln = 14;
|
|
90
|
+
let r = 8;
|
|
91
|
+
let p = 1;
|
|
92
|
+
for (const param of paramsStr.split(',')) {
|
|
93
|
+
const [key, val] = param.split('=');
|
|
94
|
+
if (key === 'ln')
|
|
95
|
+
ln = parseInt(val, 10);
|
|
96
|
+
else if (key === 'r')
|
|
97
|
+
r = parseInt(val, 10);
|
|
98
|
+
else if (key === 'p')
|
|
99
|
+
p = parseInt(val, 10);
|
|
100
|
+
}
|
|
101
|
+
const cost = Math.pow(2, ln);
|
|
102
|
+
const salt = Buffer.from(saltB64, 'base64url');
|
|
103
|
+
const expectedHash = Buffer.from(hashB64, 'base64url');
|
|
104
|
+
try {
|
|
105
|
+
const derivedKey = await this.deriveKey(password, salt, cost, r, p, expectedHash.length, this.maxmem);
|
|
106
|
+
if (derivedKey.length !== expectedHash.length) {
|
|
107
|
+
return false;
|
|
108
|
+
}
|
|
109
|
+
return crypto.timingSafeEqual(derivedKey, expectedHash);
|
|
110
|
+
}
|
|
111
|
+
catch {
|
|
112
|
+
return false;
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
needsRehash(hash, customOptions = {}) {
|
|
116
|
+
if (!hash || !hash.startsWith('$scrypt$')) {
|
|
117
|
+
return true;
|
|
118
|
+
}
|
|
119
|
+
const targetCost = customOptions.cost ?? this.cost;
|
|
120
|
+
const targetBlockSize = customOptions.blockSize ?? this.blockSize;
|
|
121
|
+
const targetParallelization = customOptions.parallelization ?? this.parallelization;
|
|
122
|
+
const targetLog2Cost = Math.round(Math.log2(targetCost));
|
|
123
|
+
const parts = hash.split('$');
|
|
124
|
+
if (parts.length !== 5)
|
|
125
|
+
return true;
|
|
126
|
+
const paramsStr = parts[2];
|
|
127
|
+
let ln = 0;
|
|
128
|
+
let r = 0;
|
|
129
|
+
let p = 0;
|
|
130
|
+
for (const param of paramsStr.split(',')) {
|
|
131
|
+
const [key, val] = param.split('=');
|
|
132
|
+
if (key === 'ln')
|
|
133
|
+
ln = parseInt(val, 10);
|
|
134
|
+
else if (key === 'r')
|
|
135
|
+
r = parseInt(val, 10);
|
|
136
|
+
else if (key === 'p')
|
|
137
|
+
p = parseInt(val, 10);
|
|
138
|
+
}
|
|
139
|
+
return ln < targetLog2Cost || r < targetBlockSize || p < targetParallelization;
|
|
140
|
+
}
|
|
141
|
+
deriveKey(password, salt, cost, blockSize, parallelization, keyLength, maxmem) {
|
|
142
|
+
return new Promise((resolve, reject) => {
|
|
143
|
+
crypto.scrypt(password, salt, keyLength, {
|
|
144
|
+
N: cost,
|
|
145
|
+
r: blockSize,
|
|
146
|
+
p: parallelization,
|
|
147
|
+
maxmem,
|
|
148
|
+
}, (err, derivedKey) => {
|
|
149
|
+
if (err)
|
|
150
|
+
reject(err);
|
|
151
|
+
else
|
|
152
|
+
resolve(derivedKey);
|
|
153
|
+
});
|
|
154
|
+
});
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
exports.ScryptHasher = ScryptHasher;
|
|
158
|
+
//# sourceMappingURL=scrypt-hasher.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"scrypt-hasher.js","sourceRoot":"","sources":["../../src/hasher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AAS,CACf,QAAgB,EAChB,IAAY,EACZ,IAAY,EACZ,SAAiB,EACjB,eAAuB,EACvB,SAAiB,EACjB,MAAc;QAEd,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;YACrC,MAAM,CAAC,MAAM,CACX,QAAQ,EACR,IAAI,EACJ,SAAS,EACT;gBACE,CAAC,EAAE,IAAI;gBACP,CAAC,EAAE,SAAS;gBACZ,CAAC,EAAE,eAAe;gBAClB,MAAM;aACP,EACD,CAAC,GAAG,EAAE,UAAU,EAAE,EAAE;gBAClB,IAAI,GAAG;oBAAE,MAAM,CAAC,GAAG,CAAC,CAAC;;oBAChB,OAAO,CAAC,UAAU,CAAC,CAAC;YAC3B,CAAC,CACF,CAAC;QACJ,CAAC,CAAC,CAAC;IACL,CAAC;CACF;AAnJD,oCAmJC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export * from './config.js';
|
|
2
|
+
export * from './hasher/index.js';
|
|
3
|
+
export * from './tokens/index.js';
|
|
4
|
+
export * from './certificates/index.js';
|
|
5
|
+
export * from './oauth/index.js';
|
|
6
|
+
export * from './oauth2/index.js';
|
|
7
|
+
export * from './guards/index.js';
|
|
8
|
+
export * from './middleware/index.js';
|
|
9
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,cAAc,aAAa,CAAC;AAG5B,cAAc,mBAAmB,CAAC;AAGlC,cAAc,mBAAmB,CAAC;AAGlC,cAAc,yBAAyB,CAAC;AAGxC,cAAc,kBAAkB,CAAC;AACjC,cAAc,mBAAmB,CAAC;AAGlC,cAAc,mBAAmB,CAAC;AAGlC,cAAc,uBAAuB,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
// Config
|
|
18
|
+
__exportStar(require("./config.js"), exports);
|
|
19
|
+
// Hasher
|
|
20
|
+
__exportStar(require("./hasher/index.js"), exports);
|
|
21
|
+
// Tokens
|
|
22
|
+
__exportStar(require("./tokens/index.js"), exports);
|
|
23
|
+
// Certificates & mTLS / JWKS
|
|
24
|
+
__exportStar(require("./certificates/index.js"), exports);
|
|
25
|
+
// OAuth 2.1 / OIDC & PKCE
|
|
26
|
+
__exportStar(require("./oauth/index.js"), exports);
|
|
27
|
+
__exportStar(require("./oauth2/index.js"), exports);
|
|
28
|
+
// Guards
|
|
29
|
+
__exportStar(require("./guards/index.js"), exports);
|
|
30
|
+
// Middleware
|
|
31
|
+
__exportStar(require("./middleware/index.js"), exports);
|
|
32
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,SAAS;AACT,8CAA4B;AAE5B,SAAS;AACT,oDAAkC;AAElC,SAAS;AACT,oDAAkC;AAElC,6BAA6B;AAC7B,0DAAwC;AAExC,0BAA0B;AAC1B,mDAAiC;AACjC,oDAAkC;AAElC,SAAS;AACT,oDAAkC;AAElC,aAAa;AACb,wDAAsC"}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import type { ArgosContext } from '@argos-js/net';
|
|
2
|
+
import type { AuthGuard, AuthUser } from '../guards/guard.interface.js';
|
|
3
|
+
declare module '@argos-js/net' {
|
|
4
|
+
interface ArgosContext {
|
|
5
|
+
user?: AuthUser;
|
|
6
|
+
auth?: {
|
|
7
|
+
user: AuthUser;
|
|
8
|
+
guard: string;
|
|
9
|
+
};
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
export interface AuthMiddlewareOptions {
|
|
13
|
+
/**
|
|
14
|
+
* Scopes required to access this endpoint.
|
|
15
|
+
* If provided, returns 403 Forbidden if user does not possess all required scopes.
|
|
16
|
+
*/
|
|
17
|
+
scopes?: string[];
|
|
18
|
+
/**
|
|
19
|
+
* Roles required to access this endpoint.
|
|
20
|
+
* If provided, returns 403 Forbidden if user does not possess at least one required role.
|
|
21
|
+
*/
|
|
22
|
+
roles?: string[];
|
|
23
|
+
/**
|
|
24
|
+
* If true, allows unauthenticated requests to pass through with ctx.user = undefined.
|
|
25
|
+
*/
|
|
26
|
+
optional?: boolean;
|
|
27
|
+
}
|
|
28
|
+
export declare function registerGuard(guard: AuthGuard): void;
|
|
29
|
+
export declare function getGuard(name: string): AuthGuard | undefined;
|
|
30
|
+
export declare function clearGuards(): void;
|
|
31
|
+
export type GuardInput = string | AuthGuard;
|
|
32
|
+
/**
|
|
33
|
+
* Creates an Argos authentication middleware supporting single or multiple guards.
|
|
34
|
+
*
|
|
35
|
+
* Example:
|
|
36
|
+
* ```ts
|
|
37
|
+
* router.get('/profile', auth('jwt'), (ctx) => ctx.json(ctx.user));
|
|
38
|
+
* router.get('/api/data', auth(['jwt', 'api-key'], { scopes: ['read:data'] }), handler);
|
|
39
|
+
* ```
|
|
40
|
+
*/
|
|
41
|
+
export declare function auth(guards: GuardInput | GuardInput[], options?: AuthMiddlewareOptions): (ctx: ArgosContext, next: () => Promise<any>) => Promise<any>;
|
|
42
|
+
//# sourceMappingURL=auth.middleware.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"auth.middleware.d.ts","sourceRoot":"","sources":["../../src/middleware/auth.middleware.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAClD,OAAO,KAAK,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,8BAA8B,CAAC;AAGxE,OAAO,QAAQ,eAAe,CAAC;IAC7B,UAAU,YAAY;QACpB,IAAI,CAAC,EAAE,QAAQ,CAAC;QAChB,IAAI,CAAC,EAAE;YACL,IAAI,EAAE,QAAQ,CAAC;YACf,KAAK,EAAE,MAAM,CAAC;SACf,CAAC;KACH;CACF;AAED,MAAM,WAAW,qBAAqB;IACpC;;;OAGG;IACH,MAAM,CAAC,EAAE,MAAM,EAAE,CAAC;IAClB;;;OAGG;IACH,KAAK,CAAC,EAAE,MAAM,EAAE,CAAC;IACjB;;OAEG;IACH,QAAQ,CAAC,EAAE,OAAO,CAAC;CACpB;AAKD,wBAAgB,aAAa,CAAC,KAAK,EAAE,SAAS,GAAG,IAAI,CAEpD;AAED,wBAAgB,QAAQ,CAAC,IAAI,EAAE,MAAM,GAAG,SAAS,GAAG,SAAS,CAE5D;AAED,wBAAgB,WAAW,IAAI,IAAI,CAElC;AAED,MAAM,MAAM,UAAU,GAAG,MAAM,GAAG,SAAS,CAAC;AAE5C;;;;;;;;GAQG;AACH,wBAAgB,IAAI,CAClB,MAAM,EAAE,UAAU,GAAG,UAAU,EAAE,EACjC,OAAO,GAAE,qBAA0B,IAIE,KAAK,YAAY,EAAE,MAAM,MAAM,OAAO,CAAC,GAAG,CAAC,KAAG,OAAO,CAAC,GAAG,CAAC,CA+HhG"}
|
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.registerGuard = registerGuard;
|
|
4
|
+
exports.getGuard = getGuard;
|
|
5
|
+
exports.clearGuards = clearGuards;
|
|
6
|
+
exports.auth = auth;
|
|
7
|
+
// Global guard registry
|
|
8
|
+
const guardRegistry = new Map();
|
|
9
|
+
function registerGuard(guard) {
|
|
10
|
+
guardRegistry.set(guard.name, guard);
|
|
11
|
+
}
|
|
12
|
+
function getGuard(name) {
|
|
13
|
+
return guardRegistry.get(name);
|
|
14
|
+
}
|
|
15
|
+
function clearGuards() {
|
|
16
|
+
guardRegistry.clear();
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Creates an Argos authentication middleware supporting single or multiple guards.
|
|
20
|
+
*
|
|
21
|
+
* Example:
|
|
22
|
+
* ```ts
|
|
23
|
+
* router.get('/profile', auth('jwt'), (ctx) => ctx.json(ctx.user));
|
|
24
|
+
* router.get('/api/data', auth(['jwt', 'api-key'], { scopes: ['read:data'] }), handler);
|
|
25
|
+
* ```
|
|
26
|
+
*/
|
|
27
|
+
function auth(guards, options = {}) {
|
|
28
|
+
const guardList = Array.isArray(guards) ? guards : [guards];
|
|
29
|
+
return async function authMiddleware(ctx, next) {
|
|
30
|
+
let authenticatedUser;
|
|
31
|
+
let matchedGuardName;
|
|
32
|
+
let lastErrorMessage;
|
|
33
|
+
for (const item of guardList) {
|
|
34
|
+
let guard;
|
|
35
|
+
if (typeof item === 'string') {
|
|
36
|
+
guard = guardRegistry.get(item);
|
|
37
|
+
if (!guard) {
|
|
38
|
+
throw new Error(`Auth guard "${item}" is not registered. Register it with registerGuard() first.`);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
else {
|
|
42
|
+
guard = item;
|
|
43
|
+
}
|
|
44
|
+
try {
|
|
45
|
+
const result = await guard.authenticate(ctx);
|
|
46
|
+
if (result.authenticated && result.user) {
|
|
47
|
+
authenticatedUser = result.user;
|
|
48
|
+
matchedGuardName = result.guard || guard.name;
|
|
49
|
+
break;
|
|
50
|
+
}
|
|
51
|
+
else if (result.error) {
|
|
52
|
+
lastErrorMessage = result.error;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
catch (err) {
|
|
56
|
+
lastErrorMessage = err.message || 'Authentication error';
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
if (!authenticatedUser) {
|
|
60
|
+
if (options.optional) {
|
|
61
|
+
return next();
|
|
62
|
+
}
|
|
63
|
+
const status = 401;
|
|
64
|
+
const errorResponse = {
|
|
65
|
+
statusCode: status,
|
|
66
|
+
error: 'Unauthorized',
|
|
67
|
+
message: lastErrorMessage || 'Authentication required',
|
|
68
|
+
};
|
|
69
|
+
if (typeof ctx.json === 'function') {
|
|
70
|
+
return ctx.json(errorResponse, status);
|
|
71
|
+
}
|
|
72
|
+
return {
|
|
73
|
+
statusCode: status,
|
|
74
|
+
headers: { 'content-type': 'application/json' },
|
|
75
|
+
body: JSON.stringify(errorResponse),
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
// Check scopes if specified
|
|
79
|
+
if (options.scopes && options.scopes.length > 0) {
|
|
80
|
+
const userScopes = new Set([
|
|
81
|
+
...(authenticatedUser.scopes ?? []),
|
|
82
|
+
...(authenticatedUser.permissions ?? []),
|
|
83
|
+
]);
|
|
84
|
+
const missingScopes = options.scopes.filter((scope) => !userScopes.has(scope));
|
|
85
|
+
if (missingScopes.length > 0) {
|
|
86
|
+
const status = 403;
|
|
87
|
+
const errorResponse = {
|
|
88
|
+
statusCode: status,
|
|
89
|
+
error: 'Forbidden',
|
|
90
|
+
message: `Insufficient scopes. Missing: ${missingScopes.join(', ')}`,
|
|
91
|
+
requiredScopes: options.scopes,
|
|
92
|
+
};
|
|
93
|
+
if (typeof ctx.json === 'function') {
|
|
94
|
+
return ctx.json(errorResponse, status);
|
|
95
|
+
}
|
|
96
|
+
return {
|
|
97
|
+
statusCode: status,
|
|
98
|
+
headers: { 'content-type': 'application/json' },
|
|
99
|
+
body: JSON.stringify(errorResponse),
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
// Check roles if specified
|
|
104
|
+
if (options.roles && options.roles.length > 0) {
|
|
105
|
+
const userRoles = new Set(authenticatedUser.roles ?? []);
|
|
106
|
+
const hasAnyRole = options.roles.some((role) => userRoles.has(role));
|
|
107
|
+
if (!hasAnyRole) {
|
|
108
|
+
const status = 403;
|
|
109
|
+
const errorResponse = {
|
|
110
|
+
statusCode: status,
|
|
111
|
+
error: 'Forbidden',
|
|
112
|
+
message: `Forbidden: user lacks required roles (${options.roles.join(', ')})`,
|
|
113
|
+
requiredRoles: options.roles,
|
|
114
|
+
};
|
|
115
|
+
if (typeof ctx.json === 'function') {
|
|
116
|
+
return ctx.json(errorResponse, status);
|
|
117
|
+
}
|
|
118
|
+
return {
|
|
119
|
+
statusCode: status,
|
|
120
|
+
headers: { 'content-type': 'application/json' },
|
|
121
|
+
body: JSON.stringify(errorResponse),
|
|
122
|
+
};
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
// Attach user to context
|
|
126
|
+
ctx.user = authenticatedUser;
|
|
127
|
+
ctx.auth = {
|
|
128
|
+
user: authenticatedUser,
|
|
129
|
+
guard: matchedGuardName || 'unknown',
|
|
130
|
+
};
|
|
131
|
+
if (typeof ctx.set === 'function') {
|
|
132
|
+
ctx.set('user', authenticatedUser);
|
|
133
|
+
ctx.set('auth', ctx.auth);
|
|
134
|
+
}
|
|
135
|
+
const anyCtx = ctx;
|
|
136
|
+
if (anyCtx.req) {
|
|
137
|
+
anyCtx.req.user = authenticatedUser;
|
|
138
|
+
}
|
|
139
|
+
return next();
|
|
140
|
+
};
|
|
141
|
+
}
|
|
142
|
+
//# sourceMappingURL=auth.middleware.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"auth.middleware.js","sourceRoot":"","sources":["../../src/middleware/auth.middleware.ts"],"names":[],"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
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./auth.middleware.js"), exports);
|
|
18
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/middleware/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,uDAAqC"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import type { AuthorizationUrlResult, BaseOAuthProviderOptions, CreateAuthorizationUrlOptions, GetUserOptions, OAuthTokens, OAuthUser } from './oauth.types.js';
|
|
2
|
+
export declare abstract class BaseOAuthProvider {
|
|
3
|
+
protected options: BaseOAuthProviderOptions;
|
|
4
|
+
constructor(options: BaseOAuthProviderOptions);
|
|
5
|
+
get name(): string;
|
|
6
|
+
/**
|
|
7
|
+
* Generates the authorization URL with PKCE (S256) and CSRF protection.
|
|
8
|
+
*/
|
|
9
|
+
createAuthorizationUrl(options?: CreateAuthorizationUrlOptions): AuthorizationUrlResult;
|
|
10
|
+
/**
|
|
11
|
+
* Exchanges an authorization code for access and refresh tokens.
|
|
12
|
+
*/
|
|
13
|
+
exchangeCodeForTokens(code: string, codeVerifier?: string): Promise<OAuthTokens>;
|
|
14
|
+
/**
|
|
15
|
+
* Fetches the raw user profile from userinfo endpoint.
|
|
16
|
+
*/
|
|
17
|
+
fetchUserInfo(accessToken: string): Promise<Record<string, unknown>>;
|
|
18
|
+
/**
|
|
19
|
+
* Maps provider-specific raw JSON profile into standard OAuthUser format.
|
|
20
|
+
*/
|
|
21
|
+
abstract mapUser(rawProfile: Record<string, unknown>, tokens: OAuthTokens): Promise<OAuthUser> | OAuthUser;
|
|
22
|
+
/**
|
|
23
|
+
* High-level flow: validates CSRF state, exchanges code for tokens, and returns mapped user.
|
|
24
|
+
*/
|
|
25
|
+
getUser(options: GetUserOptions): Promise<OAuthUser>;
|
|
26
|
+
}
|
|
27
|
+
//# sourceMappingURL=base.provider.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"base.provider.d.ts","sourceRoot":"","sources":["../../src/oauth/base.provider.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,sBAAsB,EACtB,wBAAwB,EACxB,6BAA6B,EAC7B,cAAc,EACd,WAAW,EACX,SAAS,EACV,MAAM,kBAAkB,CAAC;AAG1B,8BAAsB,iBAAiB;IACrC,SAAS,CAAC,OAAO,EAAE,wBAAwB,CAAC;gBAEhC,OAAO,EAAE,wBAAwB;IAI7C,IAAW,IAAI,IAAI,MAAM,CAExB;IAED;;OAEG;IACI,sBAAsB,CAAC,OAAO,GAAE,6BAAkC,GAAG,sBAAsB;IAgDlG;;OAEG;IACU,qBAAqB,CAAC,IAAI,EAAE,MAAM,EAAE,YAAY,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,WAAW,CAAC;IAqD7F;;OAEG;IACU,aAAa,CAAC,WAAW,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAoBjF;;OAEG;aACa,OAAO,CAAC,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,MAAM,EAAE,WAAW,GAAG,OAAO,CAAC,SAAS,CAAC,GAAG,SAAS;IAEjH;;OAEG;IACU,OAAO,CAAC,OAAO,EAAE,cAAc,GAAG,OAAO,CAAC,SAAS,CAAC;CAalE"}
|