@fluojs/passport 1.0.0-beta.1
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.ko.md +179 -0
- package/README.md +179 -0
- package/dist/account/account-linking.d.ts +91 -0
- package/dist/account/account-linking.d.ts.map +1 -0
- package/dist/account/account-linking.js +145 -0
- package/dist/adapters/passport-js.d.ts +77 -0
- package/dist/adapters/passport-js.d.ts.map +1 -0
- package/dist/adapters/passport-js.js +230 -0
- package/dist/cookie/cookie-auth-module.d.ts +65 -0
- package/dist/cookie/cookie-auth-module.d.ts.map +1 -0
- package/dist/cookie/cookie-auth-module.js +84 -0
- package/dist/cookie/cookie-auth.d.ts +40 -0
- package/dist/cookie/cookie-auth.d.ts.map +1 -0
- package/dist/cookie/cookie-auth.js +101 -0
- package/dist/cookie/cookie-manager.d.ts +34 -0
- package/dist/cookie/cookie-manager.d.ts.map +1 -0
- package/dist/cookie/cookie-manager.js +93 -0
- package/dist/decorators.d.ts +42 -0
- package/dist/decorators.d.ts.map +1 -0
- package/dist/decorators.js +95 -0
- package/dist/errors.d.ts +26 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/errors.js +48 -0
- package/dist/guard.d.ts +39 -0
- package/dist/guard.d.ts.map +1 -0
- package/dist/guard.js +124 -0
- package/dist/index.d.ts +15 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +14 -0
- package/dist/internal-tokens.d.ts +3 -0
- package/dist/internal-tokens.d.ts.map +1 -0
- package/dist/internal-tokens.js +4 -0
- package/dist/metadata.d.ts +6 -0
- package/dist/metadata.d.ts.map +1 -0
- package/dist/metadata.js +105 -0
- package/dist/module.d.ts +36 -0
- package/dist/module.d.ts.map +1 -0
- package/dist/module.js +63 -0
- package/dist/refresh/jwt-refresh-token-adapter.d.ts +30 -0
- package/dist/refresh/jwt-refresh-token-adapter.d.ts.map +1 -0
- package/dist/refresh/jwt-refresh-token-adapter.js +103 -0
- package/dist/refresh/refresh-token.d.ts +96 -0
- package/dist/refresh/refresh-token.d.ts.map +1 -0
- package/dist/refresh/refresh-token.js +178 -0
- package/dist/scope.d.ts +5 -0
- package/dist/scope.d.ts.map +1 -0
- package/dist/scope.js +44 -0
- package/dist/status.d.ts +36 -0
- package/dist/status.d.ts.map +1 -0
- package/dist/status.js +173 -0
- package/dist/types.d.ts +36 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +1 -0
- package/package.json +55 -0
package/dist/status.js
ADDED
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
/** Snapshot payload describing passport readiness, health, ownership, and diagnostic details. */
|
|
2
|
+
|
|
3
|
+
/** Input contract for deriving passport platform health and readiness diagnostics. */
|
|
4
|
+
|
|
5
|
+
function hasRegisteredStrategies(input) {
|
|
6
|
+
return input.registeredStrategies.length > 0;
|
|
7
|
+
}
|
|
8
|
+
function hasDefaultStrategyMismatch(input) {
|
|
9
|
+
if (!input.defaultStrategy) {
|
|
10
|
+
return false;
|
|
11
|
+
}
|
|
12
|
+
return !input.registeredStrategies.includes(input.defaultStrategy);
|
|
13
|
+
}
|
|
14
|
+
function isCookiePresetReady(input) {
|
|
15
|
+
if (!input.cookiePresetEnabled) {
|
|
16
|
+
return true;
|
|
17
|
+
}
|
|
18
|
+
return input.cookiePresetReady ?? true;
|
|
19
|
+
}
|
|
20
|
+
function isRefreshTokenStoreReady(input) {
|
|
21
|
+
if (!input.refreshTokenEnabled) {
|
|
22
|
+
return true;
|
|
23
|
+
}
|
|
24
|
+
return input.refreshTokenStoreReady ?? true;
|
|
25
|
+
}
|
|
26
|
+
function collectReadinessReasons(input) {
|
|
27
|
+
const reasons = [];
|
|
28
|
+
if (!hasRegisteredStrategies(input)) {
|
|
29
|
+
reasons.push('No auth strategies are registered.');
|
|
30
|
+
}
|
|
31
|
+
if (hasDefaultStrategyMismatch(input)) {
|
|
32
|
+
reasons.push(`Default strategy "${input.defaultStrategy}" is not registered.`);
|
|
33
|
+
}
|
|
34
|
+
if (!isCookiePresetReady(input)) {
|
|
35
|
+
reasons.push('Cookie auth preset is enabled but not ready.');
|
|
36
|
+
}
|
|
37
|
+
if (!isRefreshTokenStoreReady(input)) {
|
|
38
|
+
reasons.push(input.refreshTokenStoreReason ?? 'Refresh token backing store is unavailable.');
|
|
39
|
+
}
|
|
40
|
+
return reasons;
|
|
41
|
+
}
|
|
42
|
+
function createReadiness(input) {
|
|
43
|
+
const critical = input.readinessCritical ?? false;
|
|
44
|
+
const reasons = collectReadinessReasons(input);
|
|
45
|
+
if (reasons.length === 0) {
|
|
46
|
+
return {
|
|
47
|
+
critical,
|
|
48
|
+
status: 'ready'
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
return {
|
|
52
|
+
critical,
|
|
53
|
+
reason: reasons.join(' '),
|
|
54
|
+
status: critical ? 'not-ready' : 'degraded'
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
function createHealth(input) {
|
|
58
|
+
const reasons = collectReadinessReasons(input);
|
|
59
|
+
if (reasons.length === 0) {
|
|
60
|
+
return {
|
|
61
|
+
status: 'healthy'
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
return {
|
|
65
|
+
reason: reasons.join(' '),
|
|
66
|
+
status: 'degraded'
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* Creates a platform snapshot for passport strategy wiring and preset readiness.
|
|
72
|
+
*
|
|
73
|
+
* @param input Passport readiness inputs such as registered strategies, default strategy, and preset readiness flags.
|
|
74
|
+
* @returns A platform snapshot containing passport health, readiness, ownership, and structured details.
|
|
75
|
+
*/
|
|
76
|
+
export function createPassportPlatformStatusSnapshot(input) {
|
|
77
|
+
const componentId = input.componentId ?? 'passport.default';
|
|
78
|
+
const degraded = collectReadinessReasons(input).length > 0;
|
|
79
|
+
return {
|
|
80
|
+
details: {
|
|
81
|
+
policyBoundary: {
|
|
82
|
+
applicationOwned: ['login credential validation', 'session persistence and consent policy', 'account upsert or merge ownership'],
|
|
83
|
+
frameworkOwned: ['strategy execution and guard contract', 'cookie auth preset primitives', 'refresh token strategy bridge and lifecycle contract']
|
|
84
|
+
},
|
|
85
|
+
presets: {
|
|
86
|
+
cookieAuth: {
|
|
87
|
+
enabled: input.cookiePresetEnabled ?? false,
|
|
88
|
+
ready: isCookiePresetReady(input)
|
|
89
|
+
},
|
|
90
|
+
refreshToken: {
|
|
91
|
+
backingStore: {
|
|
92
|
+
dependencyId: input.refreshTokenDependencyId,
|
|
93
|
+
reason: input.refreshTokenStoreReason,
|
|
94
|
+
ready: isRefreshTokenStoreReady(input)
|
|
95
|
+
},
|
|
96
|
+
enabled: input.refreshTokenEnabled ?? false
|
|
97
|
+
}
|
|
98
|
+
},
|
|
99
|
+
strategyRegistry: {
|
|
100
|
+
defaultStrategy: input.defaultStrategy,
|
|
101
|
+
hasStrategies: hasRegisteredStrategies(input),
|
|
102
|
+
registeredStrategies: input.registeredStrategies
|
|
103
|
+
},
|
|
104
|
+
telemetry: {
|
|
105
|
+
labels: {
|
|
106
|
+
component_id: componentId,
|
|
107
|
+
component_kind: 'passport',
|
|
108
|
+
operation: 'auth-strategy-dispatch',
|
|
109
|
+
result: degraded ? 'degraded' : 'ready'
|
|
110
|
+
},
|
|
111
|
+
namespace: 'passport'
|
|
112
|
+
}
|
|
113
|
+
},
|
|
114
|
+
health: createHealth(input),
|
|
115
|
+
ownership: {
|
|
116
|
+
externallyManaged: true,
|
|
117
|
+
ownsResources: false
|
|
118
|
+
},
|
|
119
|
+
readiness: createReadiness(input)
|
|
120
|
+
};
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
/**
|
|
124
|
+
* Creates platform diagnostic issues for passport registry and preset readiness problems.
|
|
125
|
+
*
|
|
126
|
+
* @param input Passport readiness inputs such as registered strategies, default strategy, and preset readiness flags.
|
|
127
|
+
* @returns Diagnostic issues describing empty registries, strategy mismatches, and preset dependency failures.
|
|
128
|
+
*/
|
|
129
|
+
export function createPassportPlatformDiagnosticIssues(input) {
|
|
130
|
+
const componentId = input.componentId ?? 'passport.default';
|
|
131
|
+
const critical = input.readinessCritical ?? false;
|
|
132
|
+
const severity = critical ? 'error' : 'warning';
|
|
133
|
+
const issues = [];
|
|
134
|
+
if (!hasRegisteredStrategies(input)) {
|
|
135
|
+
issues.push({
|
|
136
|
+
code: 'AUTH_PASSPORT_STRATEGY_REGISTRY_EMPTY',
|
|
137
|
+
componentId,
|
|
138
|
+
fixHint: 'Register at least one auth strategy via PassportModule.forRoot(..., strategies).',
|
|
139
|
+
message: 'Passport strategy registry has no registered auth strategies.',
|
|
140
|
+
severity
|
|
141
|
+
});
|
|
142
|
+
}
|
|
143
|
+
if (hasDefaultStrategyMismatch(input)) {
|
|
144
|
+
issues.push({
|
|
145
|
+
code: 'AUTH_PASSPORT_DEFAULT_STRATEGY_NOT_REGISTERED',
|
|
146
|
+
componentId,
|
|
147
|
+
fixHint: 'Register the default strategy token or change defaultStrategy to a registered strategy name.',
|
|
148
|
+
message: `Passport default strategy "${input.defaultStrategy}" is not present in the strategy registry.`,
|
|
149
|
+
severity
|
|
150
|
+
});
|
|
151
|
+
}
|
|
152
|
+
if (!isCookiePresetReady(input)) {
|
|
153
|
+
issues.push({
|
|
154
|
+
code: 'AUTH_PASSPORT_COOKIE_PRESET_NOT_READY',
|
|
155
|
+
componentId,
|
|
156
|
+
fixHint: 'Ensure cookie auth preset providers are registered and cookie options are configured for this environment.',
|
|
157
|
+
message: 'Cookie auth preset is enabled but cannot accept authentication traffic safely.',
|
|
158
|
+
severity
|
|
159
|
+
});
|
|
160
|
+
}
|
|
161
|
+
if (!isRefreshTokenStoreReady(input)) {
|
|
162
|
+
issues.push({
|
|
163
|
+
code: 'AUTH_PASSPORT_REFRESH_TOKEN_BACKING_STORE_NOT_READY',
|
|
164
|
+
componentId,
|
|
165
|
+
cause: input.refreshTokenStoreReason,
|
|
166
|
+
dependsOn: input.refreshTokenDependencyId ? [input.refreshTokenDependencyId] : undefined,
|
|
167
|
+
fixHint: 'Restore refresh token backing store readiness, or disable refresh-token strategy for this environment.',
|
|
168
|
+
message: 'Refresh token strategy is enabled, but its backing dependency is not ready.',
|
|
169
|
+
severity
|
|
170
|
+
});
|
|
171
|
+
}
|
|
172
|
+
return issues;
|
|
173
|
+
}
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import type { MaybePromise, Token } from '@fluojs/core';
|
|
2
|
+
import type { Guard, GuardContext, Principal } from '@fluojs/http';
|
|
3
|
+
/** Route-level authentication requirement metadata. */
|
|
4
|
+
export interface AuthRequirement {
|
|
5
|
+
/** Named strategy to resolve from the strategy registry. */
|
|
6
|
+
strategy?: string;
|
|
7
|
+
/** Required scopes that must be present on the resolved principal. */
|
|
8
|
+
scopes?: string[];
|
|
9
|
+
}
|
|
10
|
+
/** Authentication result variant used when a strategy fully handled the response. */
|
|
11
|
+
export interface AuthHandledResult {
|
|
12
|
+
handled: true;
|
|
13
|
+
principal?: Principal;
|
|
14
|
+
}
|
|
15
|
+
/** Return type of an `AuthStrategy.authenticate(...)` call. */
|
|
16
|
+
export type AuthStrategyResult = Principal | AuthHandledResult;
|
|
17
|
+
/** Strategy contract implemented by authentication adapters. */
|
|
18
|
+
export interface AuthStrategy {
|
|
19
|
+
authenticate(context: GuardContext): MaybePromise<AuthStrategyResult>;
|
|
20
|
+
}
|
|
21
|
+
/** Registration entry used by `PassportModule.forRoot(...)`. */
|
|
22
|
+
export interface AuthStrategyRegistration {
|
|
23
|
+
name: string;
|
|
24
|
+
token: Token<AuthStrategy>;
|
|
25
|
+
}
|
|
26
|
+
/** Immutable strategy lookup map keyed by strategy name. */
|
|
27
|
+
export type AuthStrategyRegistry = Readonly<Record<string, Token<AuthStrategy>>>;
|
|
28
|
+
/** Module-level options for passport strategy wiring. */
|
|
29
|
+
export interface PassportModuleOptions {
|
|
30
|
+
defaultStrategy?: string;
|
|
31
|
+
}
|
|
32
|
+
/** Contract for the public `AuthGuard` behavior. */
|
|
33
|
+
export interface AuthGuardContract extends Guard {
|
|
34
|
+
canActivate(context: GuardContext): Promise<true>;
|
|
35
|
+
}
|
|
36
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,KAAK,EAAE,MAAM,cAAc,CAAC;AACxD,OAAO,KAAK,EAAE,KAAK,EAAE,YAAY,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAEnE,uDAAuD;AACvD,MAAM,WAAW,eAAe;IAC9B,4DAA4D;IAC5D,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,sEAAsE;IACtE,MAAM,CAAC,EAAE,MAAM,EAAE,CAAC;CACnB;AAED,qFAAqF;AACrF,MAAM,WAAW,iBAAiB;IAChC,OAAO,EAAE,IAAI,CAAC;IACd,SAAS,CAAC,EAAE,SAAS,CAAC;CACvB;AAED,+DAA+D;AAC/D,MAAM,MAAM,kBAAkB,GAAG,SAAS,GAAG,iBAAiB,CAAC;AAE/D,gEAAgE;AAChE,MAAM,WAAW,YAAY;IAC3B,YAAY,CAAC,OAAO,EAAE,YAAY,GAAG,YAAY,CAAC,kBAAkB,CAAC,CAAC;CACvE;AAED,gEAAgE;AAChE,MAAM,WAAW,wBAAwB;IACvC,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,KAAK,CAAC,YAAY,CAAC,CAAC;CAC5B;AAED,4DAA4D;AAC5D,MAAM,MAAM,oBAAoB,GAAG,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,KAAK,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC;AAEjF,yDAAyD;AACzD,MAAM,WAAW,qBAAqB;IACpC,eAAe,CAAC,EAAE,MAAM,CAAC;CAC1B;AAED,oDAAoD;AACpD,MAAM,WAAW,iBAAkB,SAAQ,KAAK;IAC9C,WAAW,CAAC,OAAO,EAAE,YAAY,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;CACnD"}
|
package/dist/types.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/package.json
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@fluojs/passport",
|
|
3
|
+
"description": "Strategy-agnostic authentication guard wiring and strategy registry for Fluo.",
|
|
4
|
+
"keywords": [
|
|
5
|
+
"fluo",
|
|
6
|
+
"passport",
|
|
7
|
+
"authentication",
|
|
8
|
+
"auth",
|
|
9
|
+
"guard",
|
|
10
|
+
"strategy"
|
|
11
|
+
],
|
|
12
|
+
"version": "1.0.0-beta.1",
|
|
13
|
+
"private": false,
|
|
14
|
+
"license": "MIT",
|
|
15
|
+
"repository": {
|
|
16
|
+
"type": "git",
|
|
17
|
+
"url": "https://github.com/fluojs/fluo.git",
|
|
18
|
+
"directory": "packages/passport"
|
|
19
|
+
},
|
|
20
|
+
"engines": {
|
|
21
|
+
"node": ">=20.0.0"
|
|
22
|
+
},
|
|
23
|
+
"publishConfig": {
|
|
24
|
+
"access": "public"
|
|
25
|
+
},
|
|
26
|
+
"type": "module",
|
|
27
|
+
"exports": {
|
|
28
|
+
".": {
|
|
29
|
+
"types": "./dist/index.d.ts",
|
|
30
|
+
"import": "./dist/index.js"
|
|
31
|
+
}
|
|
32
|
+
},
|
|
33
|
+
"main": "./dist/index.js",
|
|
34
|
+
"types": "./dist/index.d.ts",
|
|
35
|
+
"files": [
|
|
36
|
+
"dist"
|
|
37
|
+
],
|
|
38
|
+
"dependencies": {
|
|
39
|
+
"@fluojs/core": "^1.0.0-beta.1",
|
|
40
|
+
"@fluojs/di": "^1.0.0-beta.1",
|
|
41
|
+
"@fluojs/http": "^1.0.0-beta.1",
|
|
42
|
+
"@fluojs/jwt": "^1.0.0-beta.1",
|
|
43
|
+
"@fluojs/runtime": "^1.0.0-beta.1"
|
|
44
|
+
},
|
|
45
|
+
"devDependencies": {
|
|
46
|
+
"vitest": "^3.2.4"
|
|
47
|
+
},
|
|
48
|
+
"scripts": {
|
|
49
|
+
"prebuild": "node ../../tooling/scripts/clean-dist.mjs",
|
|
50
|
+
"build": "pnpm exec babel src --extensions .ts --ignore 'src/**/*.test.ts' --out-dir dist --config-file ../../tooling/babel/babel.config.cjs && pnpm exec tsc -p tsconfig.build.json",
|
|
51
|
+
"typecheck": "pnpm exec tsc -p tsconfig.json --noEmit",
|
|
52
|
+
"test": "pnpm exec vitest run -c vitest.config.ts",
|
|
53
|
+
"test:watch": "pnpm exec vitest -c vitest.config.ts"
|
|
54
|
+
}
|
|
55
|
+
}
|