@oauth-spa-kit/server 2.5.0 → 2.6.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/dist/authzen.d.ts +7 -0
- package/dist/authzen.js +18 -0
- package/package.json +2 -2
package/dist/authzen.d.ts
CHANGED
|
@@ -117,3 +117,10 @@ export declare function searchResources(request: Request, config: OAuthHandlersC
|
|
|
117
117
|
export declare function searchSubjects(request: Request, config: OAuthHandlersConfig, authzen: AuthzenClientConfig, search: AuthzenSubjectSearchRequest): Promise<AuthzenResult<AuthzenSubjectSearchResponse> | null>;
|
|
118
118
|
/** Which actions the subject can perform on `resource` -- `POST /access/v1/search/action`. */
|
|
119
119
|
export declare function searchActions(request: Request, config: OAuthHandlersConfig, authzen: AuthzenClientConfig, search: AuthzenActionSearchRequest): Promise<AuthzenResult<AuthzenActionSearchResponse> | null>;
|
|
120
|
+
export interface SubjectResolverConfig {
|
|
121
|
+
endpoint: string;
|
|
122
|
+
idField?: string;
|
|
123
|
+
subjectType?: string;
|
|
124
|
+
fetchImpl?: typeof fetch;
|
|
125
|
+
}
|
|
126
|
+
export declare function resolveOwnSubject(request: Request, config: OAuthHandlersConfig, resolver: SubjectResolverConfig): Promise<AuthzenResult<AuthzenEntity> | null>;
|
package/dist/authzen.js
CHANGED
|
@@ -61,3 +61,21 @@ export async function searchSubjects(request, config, authzen, search) {
|
|
|
61
61
|
export async function searchActions(request, config, authzen, search) {
|
|
62
62
|
return callPdp(request, config, authzen, "access/v1/search/action", search);
|
|
63
63
|
}
|
|
64
|
+
export async function resolveOwnSubject(request, config, resolver) {
|
|
65
|
+
const auth = await getAuthorizationHeader(request, config);
|
|
66
|
+
if (!auth)
|
|
67
|
+
return null;
|
|
68
|
+
const fetchImpl = resolver.fetchImpl ?? fetch;
|
|
69
|
+
const response = await fetchImpl(resolver.endpoint, { headers: { authorization: auth.header } });
|
|
70
|
+
if (!response.ok) {
|
|
71
|
+
const body = await response.text().catch(() => "");
|
|
72
|
+
throw new AuthzenError(`Subject resolver call to ${resolver.endpoint} failed with status ${response.status}`, response.status, body);
|
|
73
|
+
}
|
|
74
|
+
const claims = (await response.json());
|
|
75
|
+
const idField = resolver.idField ?? "membershipId";
|
|
76
|
+
const id = claims[idField];
|
|
77
|
+
if (typeof id !== "string") {
|
|
78
|
+
throw new AuthzenError(`Subject resolver response from ${resolver.endpoint} is missing a string "${idField}" field`);
|
|
79
|
+
}
|
|
80
|
+
return { result: { type: resolver.subjectType ?? "membership", id }, setCookie: auth.setCookie };
|
|
81
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@oauth-spa-kit/server",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.6.0",
|
|
4
4
|
"description": "BFF-pattern OAuth handlers: sealed HttpOnly-cookie sessions + login/callback/refresh/logout route factories, built on Web-standard Request/Response so they drop into Nitro, Next.js route handlers, Cloudflare Workers, or plain Node (via a small adapter).",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -22,7 +22,7 @@
|
|
|
22
22
|
"node": ">=18"
|
|
23
23
|
},
|
|
24
24
|
"dependencies": {
|
|
25
|
-
"@oauth-spa-kit/core": "2.
|
|
25
|
+
"@oauth-spa-kit/core": "2.6.0"
|
|
26
26
|
},
|
|
27
27
|
"devDependencies": {
|
|
28
28
|
"typescript": "^5.6.0",
|