@fluojs/passport 1.0.1 → 1.0.3
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/README.ko.md +42 -11
- package/README.md +40 -9
- package/dist/cookie/cookie-manager.d.ts.map +1 -1
- package/dist/cookie/cookie-manager.js +25 -4
- package/package.json +6 -6
package/README.ko.md
CHANGED
|
@@ -144,6 +144,8 @@ export class AuthModule {}
|
|
|
144
144
|
|
|
145
145
|
Cookie access token은 비어 있지 않은 문자열이어야 합니다. `requireAccessToken: false`일 때만 누락된 cookie가 `{ authenticated: false }`로 resolve될 수 있으며, 존재하지만 malformed인 cookie 값은 JWT 검증 전에 항상 인증 실패로 처리됩니다.
|
|
146
146
|
|
|
147
|
+
`CookieManager`는 underlying adapter가 기존 header를 `set-cookie`처럼 다른 casing으로 저장했더라도, response에 이미 설정된 cookie를 덮어쓰지 않고 access-token 및 refresh-token `Set-Cookie` 값을 append합니다.
|
|
148
|
+
|
|
147
149
|
보호된 라우트는 계속 `@UseAuth(...)`를 사용해야 합니다. `requireAccessToken: false`를 설정해도 쿠키가 없을 때는 익명 principal이 아니라 명시적인 미인증 결과를 반환하므로, 보호된 라우트는 요청을 계속 거부합니다.
|
|
148
150
|
|
|
149
151
|
로그인 사용자와 게스트 호출자를 모두 허용하려는 라우트에서만 `@UseOptionalAuth(...)`를 사용하세요.
|
|
@@ -216,21 +218,50 @@ Identity-link 결정을 모델링하려면 `createConservativeAccountLinkPolicy(
|
|
|
216
218
|
- `@UseOptionalAuth(strategyName)`: `AuthGuard`를 부착하지만 전략이 자격 증명 누락을 보고하면 스코프가 없는 라우트는 계속 진행할 수 있게 합니다.
|
|
217
219
|
- `@RequireScopes(...scopes)`: 특정 권한(스코프) 요구 사항을 강제합니다.
|
|
218
220
|
|
|
219
|
-
###
|
|
221
|
+
### 모듈 및 가드 진입점
|
|
220
222
|
- `PassportModule`: passport 전략 wiring을 위한 모듈 진입점입니다.
|
|
221
|
-
- `AuthGuard`: 전략 체인을
|
|
222
|
-
- `
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
- `
|
|
226
|
-
- `
|
|
223
|
+
- `AuthGuard`: 전략 체인을 실행하고 required scope를 강제하는 HTTP 가드입니다.
|
|
224
|
+
- `PassportModuleOptions`, `AuthStrategyRegistration`, `AuthStrategyRegistry`, `AuthGuardContract`: Strategy registry 및 guard wiring 계약입니다.
|
|
225
|
+
|
|
226
|
+
### 전략 계약 및 에러
|
|
227
|
+
- `AuthStrategy`: 커스텀 인증 로직 구현을 위한 계약입니다.
|
|
228
|
+
- `AuthRequirement`: 선택된 strategy, optional-auth mode, required scope를 담는 route-level metadata입니다.
|
|
229
|
+
- `AuthStrategyResult`, `AuthOptionalResult`, `AuthHandledResult`: Principal, 의도적으로 누락된 credential, 이미 처리된 response를 표현하는 strategy return variant입니다.
|
|
230
|
+
- `AuthStrategyResolutionError`, `AuthenticationRequiredError`, `AuthenticationFailedError`, `AuthenticationExpiredError`: Registry miss, 누락된 credential, 잘못된 credential, 만료된 credential에 대해 guard와 strategy adapter가 사용하는 공개 error입니다.
|
|
231
|
+
|
|
232
|
+
### Metadata 및 scope helper
|
|
233
|
+
- `defineAuthRequirement(...)`, `getOwnAuthRequirement(...)`, `getAuthRequirement(...)`: Custom decorator나 tooling을 `AuthGuard`와 통합할 때 auth requirement metadata를 읽고 쓰는 공개 helper입니다.
|
|
234
|
+
- Scope requirement는 일반적으로 `@RequireScopes(...)`로 작성합니다. 더 낮은 수준의 scope normalization helper는 internal로 남아 있으며 package root export의 일부가 아닙니다.
|
|
235
|
+
|
|
236
|
+
### Cookie auth preset
|
|
237
|
+
- `CookieAuthModule`: 내장 cookie-auth preset의 모듈 진입점입니다.
|
|
238
|
+
- `CookieAuthStrategy`, `COOKIE_AUTH_STRATEGY_NAME`, `COOKIE_AUTH_OPTIONS`, `DEFAULT_COOKIE_AUTH_OPTIONS`: Cookie strategy wiring token과 기본값입니다.
|
|
239
|
+
- `CookieAuthOptions`, `CookieAuthPresetConfig`, `CookieManagerConfig`, `CookieOptions`, `SetCookieOptions`: Cookie strategy 및 response cookie 설정 타입입니다.
|
|
240
|
+
- `CookieManager`: HttpOnly access/refresh token cookie를 설정하고 제거하는 유틸리티입니다.
|
|
227
241
|
- Cookie helper: `createCookieAuthPreset`, `createCookieAuthStrategyRegistration`, `createCookieManager`, `normalizeCookieAuthOptions`.
|
|
242
|
+
|
|
243
|
+
### Refresh token preset
|
|
244
|
+
- `RefreshTokenModule`: 내장 refresh-token preset의 모듈 진입점입니다.
|
|
245
|
+
- `RefreshTokenStrategy`, `REFRESH_TOKEN_STRATEGY_NAME`, `REFRESH_TOKEN_SERVICE`: Refresh-token strategy 및 service alias wiring입니다.
|
|
246
|
+
- `RefreshTokenService`, `RefreshTokenInput`, `RefreshTokenAuthResult`: Application service contract와 exchange payload shape입니다.
|
|
247
|
+
- `JwtRefreshTokenAdapter`: `@fluojs/jwt`의 refresh logic을 passport interface로 연결합니다.
|
|
248
|
+
- `REFRESH_TOKEN_MODULE_OPTIONS`, `RefreshTokenModuleOptions`: 필수 `secret`과 `store` 계약을 포함하는 JWT 기반 refresh-token adapter 설정 token 및 option입니다.
|
|
228
249
|
- Refresh helper: `createRefreshTokenStrategyRegistration`.
|
|
229
|
-
- Status/diagnostics helper: `createPassportPlatformStatusSnapshot`, `createPassportPlatformDiagnosticIssues`.
|
|
230
250
|
|
|
231
|
-
###
|
|
232
|
-
- `
|
|
233
|
-
- `
|
|
251
|
+
### Passport.js bridge
|
|
252
|
+
- `createPassportJsStrategyBridge(...)`: Passport.js strategy를 fluo `AuthStrategy`로 변환합니다.
|
|
253
|
+
- `PassportJsAuthStrategy`, `PassportJsStrategyLike`, `PassportJsPrincipalMapperInput`, `PassportJsPrincipalMapper`, `PassportJsAuthStrategyOptions`, `PassportJsStrategyBridge`: Bridge strategy, mapper, 설정, provider bundle 계약입니다.
|
|
254
|
+
|
|
255
|
+
### Account linking
|
|
256
|
+
- `ACCOUNT_LINKING_POLICY`: Account-linking policy implementation을 등록하기 위한 DI token입니다.
|
|
257
|
+
- `createConservativeAccountLinkPolicy(...)`, `resolveAccountLinking(...)`: Identity-link 결정을 위한 conservative default policy와 resolver입니다.
|
|
258
|
+
- `AccountIdentity`, `AccountLinkCandidate`, `AccountLinkAttempt`, `AccountLinkContext`, `AccountLinkPolicy`, `AccountLinkPolicyDecision`, `AccountLinkingOptions`, `AccountLinkingResolution`: Account-linking input, policy, result 계약입니다.
|
|
259
|
+
- `AccountLinkConflictError`, `AccountLinkRejectedError`: 모호하거나 거부된 account-linking attempt에서 발생하는 error입니다.
|
|
260
|
+
|
|
261
|
+
### Status 및 diagnostics
|
|
262
|
+
- `createPassportPlatformStatusSnapshot(...)`: Strategy registry, preset readiness, ownership, telemetry label을 위한 runtime platform snapshot을 생성합니다.
|
|
263
|
+
- `createPassportPlatformDiagnosticIssues(...)`: Empty registry, 누락된 default strategy, cookie preset readiness, refresh-token backing store readiness 문제에 대한 diagnostic issue를 생성합니다.
|
|
264
|
+
- `PassportPlatformStatusSnapshot`, `PassportStatusAdapterInput`: Status helper input/output 계약입니다.
|
|
234
265
|
|
|
235
266
|
`UseOptionalAuth`는 scope가 필요 없는 route에서만 credential 누락을 우회합니다. Scoped route에는 여전히 principal이 필요합니다. Passport.js bridge의 `redirect()`는 response를 commit하고 protected handler를 건너뛰며, `pass()`와 Passport action 없이 완료된 strategy는 인증 실패입니다.
|
|
236
267
|
|
package/README.md
CHANGED
|
@@ -144,6 +144,8 @@ Import `CookieAuthModule.forRoot(...)`, `JwtModule.forRoot(...)`, and `PassportM
|
|
|
144
144
|
|
|
145
145
|
Cookie access tokens must be non-empty strings. Missing cookies can resolve to `{ authenticated: false }` only when `requireAccessToken: false`; malformed present cookie values always fail authentication before JWT verification.
|
|
146
146
|
|
|
147
|
+
`CookieManager` appends access-token and refresh-token `Set-Cookie` values without overwriting cookies that were already placed on the response, even when the underlying adapter stores the existing header with different casing such as `set-cookie`.
|
|
148
|
+
|
|
147
149
|
Protected routes must keep using `@UseAuth(...)`. If you configure `requireAccessToken: false`, a missing cookie resolves to an explicit unauthenticated result instead of an anonymous principal, so protected routes still reject the request.
|
|
148
150
|
|
|
149
151
|
Use `@UseOptionalAuth(...)` only on routes that intentionally support both signed-in and guest callers:
|
|
@@ -216,21 +218,50 @@ Use `createConservativeAccountLinkPolicy(...)` and `resolveAccountLinking(...)`
|
|
|
216
218
|
- `@UseOptionalAuth(strategyName)`: Attaches `AuthGuard` but allows routes without scopes to continue when the strategy reports missing credentials.
|
|
217
219
|
- `@RequireScopes(...scopes)`: Enforces specific scope requirements.
|
|
218
220
|
|
|
219
|
-
###
|
|
221
|
+
### Module and Guard Entry Points
|
|
220
222
|
- `PassportModule`: Module entry point for passport strategy wiring.
|
|
221
|
-
- `AuthGuard`: The HTTP guard that executes the strategy chain.
|
|
223
|
+
- `AuthGuard`: The HTTP guard that executes the strategy chain and enforces required scopes.
|
|
224
|
+
- `PassportModuleOptions`, `AuthStrategyRegistration`, `AuthStrategyRegistry`, `AuthGuardContract`: Strategy registry and guard wiring contracts.
|
|
225
|
+
|
|
226
|
+
### Strategy Contracts and Errors
|
|
227
|
+
- `AuthStrategy`: The contract for implementing custom authentication logic.
|
|
228
|
+
- `AuthRequirement`: Route-level metadata for the selected strategy, optional-auth mode, and required scopes.
|
|
229
|
+
- `AuthStrategyResult`, `AuthOptionalResult`, `AuthHandledResult`: Strategy return variants for principals, intentionally missing credentials, and fully handled responses.
|
|
230
|
+
- `AuthStrategyResolutionError`, `AuthenticationRequiredError`, `AuthenticationFailedError`, `AuthenticationExpiredError`: Public errors used by guards and strategy adapters for registry misses, missing credentials, invalid credentials, and expired credentials.
|
|
231
|
+
|
|
232
|
+
### Metadata and Scope Helpers
|
|
233
|
+
- `defineAuthRequirement(...)`, `getOwnAuthRequirement(...)`, `getAuthRequirement(...)`: Public helpers for reading and writing auth requirement metadata when integrating custom decorators or tooling with `AuthGuard`.
|
|
234
|
+
- Scope requirements are normally authored with `@RequireScopes(...)`; lower-level scope normalization helpers remain internal and are not part of the package root export.
|
|
235
|
+
|
|
236
|
+
### Cookie Auth Preset
|
|
222
237
|
- `CookieAuthModule`: Module entry point for the built-in cookie-auth preset.
|
|
223
|
-
- `
|
|
238
|
+
- `CookieAuthStrategy`, `COOKIE_AUTH_STRATEGY_NAME`, `COOKIE_AUTH_OPTIONS`, `DEFAULT_COOKIE_AUTH_OPTIONS`: Cookie strategy wiring tokens and defaults.
|
|
239
|
+
- `CookieAuthOptions`, `CookieAuthPresetConfig`, `CookieManagerConfig`, `CookieOptions`, `SetCookieOptions`: Cookie strategy and response cookie configuration types.
|
|
240
|
+
- `CookieManager`: Utility for setting and clearing HttpOnly access/refresh token cookies.
|
|
241
|
+
- Cookie helpers: `createCookieAuthPreset`, `createCookieAuthStrategyRegistration`, `createCookieManager`, `normalizeCookieAuthOptions`.
|
|
242
|
+
|
|
243
|
+
### Refresh Token Preset
|
|
224
244
|
- `RefreshTokenModule`: Module entry point for the built-in refresh-token preset.
|
|
245
|
+
- `RefreshTokenStrategy`, `REFRESH_TOKEN_STRATEGY_NAME`, `REFRESH_TOKEN_SERVICE`: Refresh-token strategy and service alias wiring.
|
|
246
|
+
- `RefreshTokenService`, `RefreshTokenInput`, `RefreshTokenAuthResult`: Application service contract and exchange payload shapes.
|
|
225
247
|
- `JwtRefreshTokenAdapter`: Bridges `@fluojs/jwt` refresh logic to the passport interface.
|
|
226
|
-
- `
|
|
227
|
-
- Cookie helpers: `createCookieAuthPreset`, `createCookieAuthStrategyRegistration`, `createCookieManager`, `normalizeCookieAuthOptions`.
|
|
248
|
+
- `REFRESH_TOKEN_MODULE_OPTIONS`, `RefreshTokenModuleOptions`: JWT-backed refresh-token adapter configuration token and options, including the required `secret` and `store` contract.
|
|
228
249
|
- Refresh helpers: `createRefreshTokenStrategyRegistration`.
|
|
229
|
-
- Status/diagnostics helpers: `createPassportPlatformStatusSnapshot`, `createPassportPlatformDiagnosticIssues`.
|
|
230
250
|
|
|
231
|
-
###
|
|
232
|
-
- `
|
|
233
|
-
- `
|
|
251
|
+
### Passport.js Bridge
|
|
252
|
+
- `createPassportJsStrategyBridge(...)`: Adapts Passport.js strategies to fluo `AuthStrategy`.
|
|
253
|
+
- `PassportJsAuthStrategy`, `PassportJsStrategyLike`, `PassportJsPrincipalMapperInput`, `PassportJsPrincipalMapper`, `PassportJsAuthStrategyOptions`, `PassportJsStrategyBridge`: Bridge strategy, mapper, configuration, and provider bundle contracts.
|
|
254
|
+
|
|
255
|
+
### Account Linking
|
|
256
|
+
- `ACCOUNT_LINKING_POLICY`: DI token for registering an account-linking policy implementation.
|
|
257
|
+
- `createConservativeAccountLinkPolicy(...)`, `resolveAccountLinking(...)`: Conservative default policy and resolver for identity-link decisions.
|
|
258
|
+
- `AccountIdentity`, `AccountLinkCandidate`, `AccountLinkAttempt`, `AccountLinkContext`, `AccountLinkPolicy`, `AccountLinkPolicyDecision`, `AccountLinkingOptions`, `AccountLinkingResolution`: Account-linking input, policy, and result contracts.
|
|
259
|
+
- `AccountLinkConflictError`, `AccountLinkRejectedError`: Errors raised for ambiguous or rejected account-linking attempts.
|
|
260
|
+
|
|
261
|
+
### Status and Diagnostics
|
|
262
|
+
- `createPassportPlatformStatusSnapshot(...)`: Creates a runtime platform snapshot for strategy registry, preset readiness, ownership, and telemetry labels.
|
|
263
|
+
- `createPassportPlatformDiagnosticIssues(...)`: Emits diagnostic issues for empty registries, missing default strategies, cookie preset readiness, and refresh-token backing store readiness.
|
|
264
|
+
- `PassportPlatformStatusSnapshot`, `PassportStatusAdapterInput`: Status helper input/output contracts.
|
|
234
265
|
|
|
235
266
|
`UseOptionalAuth` only bypasses missing credentials when no scopes are required; scoped routes still need a principal. Passport.js bridge `redirect()` commits the response and skips the protected handler, while `pass()` and strategy completion without a Passport action are authentication failures.
|
|
236
267
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cookie-manager.d.ts","sourceRoot":"","sources":["../../src/cookie/cookie-manager.ts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,EAAE,KAAK,EAAE,MAAM,EAAE,UAAU,CAAC,EAAE,MAAM,GAAG,IAAI;IAa3F,qBAAqB,CAAC,QAAQ,EAAE,iBAAiB,EAAE,KAAK,EAAE,MAAM,EAAE,UAAU,CAAC,EAAE,MAAM,GAAG,IAAI;IAa5F,sBAAsB,CAAC,QAAQ,EAAE,iBAAiB,GAAG,IAAI;IASzD,uBAAuB,CAAC,QAAQ,EAAE,iBAAiB,GAAG,IAAI;IAS1D,eAAe,CAAC,QAAQ,EAAE,iBAAiB,GAAG,IAAI;IAKlD,cAAc,CACZ,QAAQ,EAAE,iBAAiB,EAC3B,WAAW,EAAE,MAAM,EACnB,qBAAqB,CAAC,EAAE,MAAM,EAC9B,YAAY,CAAC,EAAE,MAAM,EACrB,sBAAsB,CAAC,EAAE,MAAM,GAC9B,IAAI;IAQP,OAAO,CAAC,eAAe;CAcxB;AAED;;;;;GAKG;AACH,wBAAgB,mBAAmB,CAAC,MAAM,CAAC,EAAE,mBAAmB,GAAG,aAAa,CAE/E"}
|
|
@@ -51,6 +51,23 @@ function buildClearCookieHeader(name, options) {
|
|
|
51
51
|
maxAge: 0
|
|
52
52
|
});
|
|
53
53
|
}
|
|
54
|
+
function getHeaderCaseInsensitive(headers, name) {
|
|
55
|
+
for (const [headerName, value] of Object.entries(headers)) {
|
|
56
|
+
if (headerName.toLowerCase() === name.toLowerCase() && (typeof value === 'string' || Array.isArray(value))) {
|
|
57
|
+
return {
|
|
58
|
+
key: headerName,
|
|
59
|
+
value
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
return undefined;
|
|
64
|
+
}
|
|
65
|
+
function toHeaderValues(value) {
|
|
66
|
+
if (Array.isArray(value)) {
|
|
67
|
+
return [...value];
|
|
68
|
+
}
|
|
69
|
+
return value ? [value] : [];
|
|
70
|
+
}
|
|
54
71
|
|
|
55
72
|
/**
|
|
56
73
|
* Represents the cookie manager.
|
|
@@ -102,10 +119,14 @@ export class CookieManager {
|
|
|
102
119
|
}
|
|
103
120
|
}
|
|
104
121
|
appendSetCookie(response, cookie) {
|
|
105
|
-
const
|
|
106
|
-
const cookies =
|
|
107
|
-
|
|
108
|
-
response.
|
|
122
|
+
const existingHeader = getHeaderCaseInsensitive(response.headers, 'Set-Cookie');
|
|
123
|
+
const cookies = [...toHeaderValues(existingHeader?.value), cookie];
|
|
124
|
+
response.setHeader('Set-Cookie', cookie);
|
|
125
|
+
const updatedHeader = getHeaderCaseInsensitive(response.headers, 'Set-Cookie');
|
|
126
|
+
if (updatedHeader?.key && updatedHeader.key !== 'Set-Cookie') {
|
|
127
|
+
delete response.headers[updatedHeader.key];
|
|
128
|
+
}
|
|
129
|
+
response.headers['Set-Cookie'] = cookies.length === 1 ? cookies[0] : cookies;
|
|
109
130
|
}
|
|
110
131
|
}
|
|
111
132
|
|
package/package.json
CHANGED
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
"guard",
|
|
10
10
|
"strategy"
|
|
11
11
|
],
|
|
12
|
-
"version": "1.0.
|
|
12
|
+
"version": "1.0.3",
|
|
13
13
|
"private": false,
|
|
14
14
|
"license": "MIT",
|
|
15
15
|
"repository": {
|
|
@@ -36,11 +36,11 @@
|
|
|
36
36
|
"dist"
|
|
37
37
|
],
|
|
38
38
|
"dependencies": {
|
|
39
|
-
"@fluojs/
|
|
40
|
-
"@fluojs/
|
|
41
|
-
"@fluojs/http": "^1.
|
|
42
|
-
"@fluojs/jwt": "^1.0.
|
|
43
|
-
"@fluojs/runtime": "^1.
|
|
39
|
+
"@fluojs/di": "^1.0.3",
|
|
40
|
+
"@fluojs/core": "^1.0.3",
|
|
41
|
+
"@fluojs/http": "^1.1.0",
|
|
42
|
+
"@fluojs/jwt": "^1.0.1",
|
|
43
|
+
"@fluojs/runtime": "^1.1.1"
|
|
44
44
|
},
|
|
45
45
|
"devDependencies": {
|
|
46
46
|
"vitest": "^3.2.4"
|