@oxy.so/core 1.3.0 → 1.4.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/cjs/.tsbuildinfo +1 -1
- package/dist/cjs/mixins/OxyServices.agency.js +41 -0
- package/dist/cjs/server/index.js +16 -1
- package/dist/cjs/server/requesterAssertion.js +362 -0
- package/dist/esm/.tsbuildinfo +1 -1
- package/dist/esm/mixins/OxyServices.agency.js +41 -0
- package/dist/esm/server/index.js +3 -0
- package/dist/esm/server/requesterAssertion.js +353 -0
- package/dist/types/.tsbuildinfo +1 -1
- package/dist/types/index.d.ts +1 -1
- package/dist/types/mixins/OxyServices.agency.d.ts +41 -0
- package/dist/types/server/index.d.ts +2 -0
- package/dist/types/server/requesterAssertion.d.ts +151 -0
- package/package.json +2 -2
- package/src/index.ts +2 -0
- package/src/mixins/OxyServices.agency.ts +76 -0
- package/src/server/__tests__/requesterAssertion.test.ts +359 -0
- package/src/server/index.ts +27 -0
- package/src/server/requesterAssertion.ts +465 -0
|
@@ -0,0 +1,359 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Present-requester assertions (ADR 0025): the format, the JWKS resolver, the
|
|
3
|
+
* audience middleware and the two SDK calls.
|
|
4
|
+
*
|
|
5
|
+
* Built around what must be REFUSED. An assertion is the only thing that lets a
|
|
6
|
+
* product's service token speak for a signed-in person at Alia, so every way to
|
|
7
|
+
* forge, stretch, redirect or reuse one has its own case.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
import { generateKeyPairSync, randomUUID, sign as signBytes, type KeyObject } from 'node:crypto';
|
|
11
|
+
import type { NextFunction, Request, Response } from 'express';
|
|
12
|
+
import { OxyServices } from '../../OxyServices';
|
|
13
|
+
import {
|
|
14
|
+
createOxyJwksKeyResolver,
|
|
15
|
+
createOxyRequesterAssertionAuth,
|
|
16
|
+
OXY_REQUESTER_ASSERTION_HEADER,
|
|
17
|
+
OxyRequesterAssertionError,
|
|
18
|
+
signOxyRequesterAssertion,
|
|
19
|
+
verifyOxyRequesterAssertion,
|
|
20
|
+
type OxyRequesterAssertionClaims,
|
|
21
|
+
type OxyRequesterAssertionIntrospection,
|
|
22
|
+
type OxyRequesterAssertionRequest,
|
|
23
|
+
} from '../requesterAssertion';
|
|
24
|
+
|
|
25
|
+
const NOW = new Date('2026-09-17T12:00:00.000Z');
|
|
26
|
+
const NOW_SECONDS = Math.floor(NOW.getTime() / 1000);
|
|
27
|
+
const ISSUER = 'https://api.oxy.so';
|
|
28
|
+
const KEY = generateKeyPairSync('ed25519');
|
|
29
|
+
const OTHER_KEY = generateKeyPairSync('ed25519');
|
|
30
|
+
const KEY_ID = 'cap-test-1';
|
|
31
|
+
|
|
32
|
+
function claims(overrides: Partial<OxyRequesterAssertionClaims> = {}): OxyRequesterAssertionClaims {
|
|
33
|
+
return {
|
|
34
|
+
iss: ISSUER,
|
|
35
|
+
aud: 'alia',
|
|
36
|
+
sub: 'requester-1',
|
|
37
|
+
jti: randomUUID(),
|
|
38
|
+
iat: NOW_SECONDS,
|
|
39
|
+
exp: NOW_SECONDS + 120,
|
|
40
|
+
azp: 'homiio-app',
|
|
41
|
+
cid: 'sindi-credential',
|
|
42
|
+
agentId: 'sindi-agent',
|
|
43
|
+
...overrides,
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
function sign(value: OxyRequesterAssertionClaims, privateKey: KeyObject = KEY.privateKey): string {
|
|
48
|
+
return signOxyRequesterAssertion(value, { keyId: KEY_ID, privateKey });
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/** Hand-rolled JWS so tests can produce what the real signer refuses to. */
|
|
52
|
+
function rawToken(header: Record<string, unknown>, payload: Record<string, unknown>, privateKey = KEY.privateKey): string {
|
|
53
|
+
const input = `${Buffer.from(JSON.stringify(header)).toString('base64url')}.${Buffer.from(JSON.stringify(payload)).toString('base64url')}`;
|
|
54
|
+
return `${input}.${signBytes(null, Buffer.from(input), privateKey).toString('base64url')}`;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
function verify(token: string, overrides: Partial<Parameters<typeof verifyOxyRequesterAssertion>[1]> = {}) {
|
|
58
|
+
return verifyOxyRequesterAssertion(token, {
|
|
59
|
+
publicKey: KEY.publicKey,
|
|
60
|
+
issuer: ISSUER,
|
|
61
|
+
audience: 'alia',
|
|
62
|
+
now: NOW,
|
|
63
|
+
...overrides,
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
function codeOf(run: () => unknown): string {
|
|
68
|
+
try {
|
|
69
|
+
run();
|
|
70
|
+
} catch (error) {
|
|
71
|
+
if (error instanceof OxyRequesterAssertionError) return error.code;
|
|
72
|
+
throw error;
|
|
73
|
+
}
|
|
74
|
+
throw new Error('expected a rejection');
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
describe('requester assertion format', () => {
|
|
78
|
+
it('round-trips a signed assertion', () => {
|
|
79
|
+
const value = claims();
|
|
80
|
+
expect(verify(sign(value))).toEqual(value);
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
it('refuses a signature from any other key', () => {
|
|
84
|
+
expect(codeOf(() => verify(sign(claims()), { publicKey: OTHER_KEY.publicKey }))).toBe('invalid_signature');
|
|
85
|
+
expect(codeOf(() => verify(sign(claims(), OTHER_KEY.privateKey)))).toBe('invalid_signature');
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
it('refuses a payload altered after signing', () => {
|
|
89
|
+
const [header, , signature] = sign(claims()).split('.');
|
|
90
|
+
const forged = Buffer.from(JSON.stringify(claims({ sub: 'someone-else' }))).toString('base64url');
|
|
91
|
+
expect(codeOf(() => verify(`${header}.${forged}.${signature}`))).toBe('invalid_signature');
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
it('refuses an unknown key', () => {
|
|
95
|
+
expect(codeOf(() => verify(sign(claims()), { publicKey: undefined }))).toBe('unknown_key');
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
it('refuses expired, future and over-long assertions', () => {
|
|
99
|
+
expect(codeOf(() => verify(sign(claims({ iat: NOW_SECONDS - 200, exp: NOW_SECONDS - 80 }))))).toBe('expired');
|
|
100
|
+
expect(codeOf(() => verify(sign(claims({ iat: NOW_SECONDS + 60, exp: NOW_SECONDS + 180 }))))).toBe('not_yet_valid');
|
|
101
|
+
const long = rawToken({ alg: 'EdDSA', typ: 'OXY-REQUESTER+JWT', kid: KEY_ID }, claims({ exp: NOW_SECONDS + 3600 }));
|
|
102
|
+
expect(codeOf(() => verify(long))).toBe('ttl_exceeded');
|
|
103
|
+
expect(() => sign(claims({ exp: NOW_SECONDS + 3600 }))).toThrow(OxyRequesterAssertionError);
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
it('refuses the wrong audience and the wrong issuer', () => {
|
|
107
|
+
expect(codeOf(() => verify(sign(claims({ aud: 'syra' }))))).toBe('wrong_audience');
|
|
108
|
+
expect(codeOf(() => verify(sign(claims({ iss: 'https://evil.example' }))))).toBe('wrong_issuer');
|
|
109
|
+
});
|
|
110
|
+
|
|
111
|
+
it('refuses other token types, alg none and extra header members', () => {
|
|
112
|
+
const payload = claims();
|
|
113
|
+
expect(codeOf(() => verify(rawToken({ alg: 'EdDSA', typ: 'OXY-CAPABILITY+JWT', kid: KEY_ID }, payload)))).toBe('malformed');
|
|
114
|
+
expect(codeOf(() => verify(rawToken({ alg: 'EdDSA', typ: 'JWT', kid: KEY_ID }, payload)))).toBe('malformed');
|
|
115
|
+
expect(codeOf(() => verify(rawToken({ alg: 'none', typ: 'OXY-REQUESTER+JWT', kid: KEY_ID }, payload)))).toBe('malformed');
|
|
116
|
+
expect(codeOf(() => verify(rawToken({ alg: 'EdDSA', typ: 'OXY-REQUESTER+JWT', kid: KEY_ID, jku: 'x' }, payload)))).toBe('malformed');
|
|
117
|
+
const [header, body] = sign(payload).split('.');
|
|
118
|
+
expect(codeOf(() => verify(`${header}.${body}.`))).toBe('malformed');
|
|
119
|
+
expect(codeOf(() => verify('not-a-token'))).toBe('malformed');
|
|
120
|
+
});
|
|
121
|
+
|
|
122
|
+
it('refuses unknown or missing claims', () => {
|
|
123
|
+
const header = { alg: 'EdDSA', typ: 'OXY-REQUESTER+JWT', kid: KEY_ID };
|
|
124
|
+
expect(codeOf(() => verify(rawToken(header, { ...claims(), scopes: ['*'] })))).toBe('invalid_claims');
|
|
125
|
+
const { agentId: _agentId, ...withoutAgent } = claims();
|
|
126
|
+
expect(codeOf(() => verify(rawToken(header, withoutAgent)))).toBe('invalid_claims');
|
|
127
|
+
});
|
|
128
|
+
});
|
|
129
|
+
|
|
130
|
+
describe('JWKS key resolver', () => {
|
|
131
|
+
const jwk = { ...KEY.publicKey.export({ format: 'jwk' }), use: 'sig', alg: 'EdDSA', kid: KEY_ID };
|
|
132
|
+
|
|
133
|
+
function fetchReturning(body: unknown) {
|
|
134
|
+
return jest.fn(async () => new Response(JSON.stringify(body), { status: 200 }));
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
it('resolves and caches a published Ed25519 key', async () => {
|
|
138
|
+
const fetchImpl = fetchReturning({ keys: [jwk] });
|
|
139
|
+
const resolve = createOxyJwksKeyResolver({ jwksUrl: 'https://api.oxy.so/jwks', fetch: fetchImpl as never });
|
|
140
|
+
const key = await resolve(KEY_ID);
|
|
141
|
+
expect(key?.asymmetricKeyType).toBe('ed25519');
|
|
142
|
+
expect(verify(sign(claims()), { publicKey: key })).toBeDefined();
|
|
143
|
+
await resolve(KEY_ID);
|
|
144
|
+
expect(fetchImpl).toHaveBeenCalledTimes(1);
|
|
145
|
+
});
|
|
146
|
+
|
|
147
|
+
it('rate-limits refreshes caused by unknown key ids', async () => {
|
|
148
|
+
let clock = 0;
|
|
149
|
+
const fetchImpl = fetchReturning({ keys: [jwk] });
|
|
150
|
+
const resolve = createOxyJwksKeyResolver({ jwksUrl: 'https://api.oxy.so/jwks', fetch: fetchImpl as never, clock: () => clock });
|
|
151
|
+
for (let i = 0; i < 10; i += 1) expect(await resolve(`forged-${i}`)).toBeUndefined();
|
|
152
|
+
expect(fetchImpl).toHaveBeenCalledTimes(1);
|
|
153
|
+
clock += 61_000;
|
|
154
|
+
await resolve('forged-late');
|
|
155
|
+
expect(fetchImpl).toHaveBeenCalledTimes(2);
|
|
156
|
+
});
|
|
157
|
+
|
|
158
|
+
it('never accepts a key set that publishes private material', async () => {
|
|
159
|
+
const privateJwk = { ...KEY.privateKey.export({ format: 'jwk' }), use: 'sig', alg: 'EdDSA', kid: KEY_ID };
|
|
160
|
+
const resolve = createOxyJwksKeyResolver({ jwksUrl: 'https://api.oxy.so/jwks', fetch: fetchReturning({ keys: [privateJwk] }) as never });
|
|
161
|
+
expect(await resolve(KEY_ID)).toBeUndefined();
|
|
162
|
+
});
|
|
163
|
+
});
|
|
164
|
+
|
|
165
|
+
describe('createOxyRequesterAssertionAuth', () => {
|
|
166
|
+
const serviceApp = {
|
|
167
|
+
appId: 'homiio-app',
|
|
168
|
+
appName: 'Homiio',
|
|
169
|
+
credentialId: 'sindi-credential',
|
|
170
|
+
ownerAccountId: 'homiio-owner',
|
|
171
|
+
scopes: ['inference:invoke'],
|
|
172
|
+
environment: 'live' as const,
|
|
173
|
+
};
|
|
174
|
+
|
|
175
|
+
function activeAnswer(value: OxyRequesterAssertionClaims): OxyRequesterAssertionIntrospection {
|
|
176
|
+
return {
|
|
177
|
+
active: true,
|
|
178
|
+
requesterAccountId: value.sub,
|
|
179
|
+
agentId: value.agentId,
|
|
180
|
+
applicationId: value.azp,
|
|
181
|
+
credentialId: value.cid,
|
|
182
|
+
jti: value.jti,
|
|
183
|
+
expiresAt: new Date(value.exp * 1000).toISOString(),
|
|
184
|
+
};
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
function harness(introspect: (input: unknown) => Promise<OxyRequesterAssertionIntrospection>) {
|
|
188
|
+
const introspector = {
|
|
189
|
+
introspectRequesterAssertion: jest.fn(introspect),
|
|
190
|
+
getBaseURL: () => 'https://api.oxy.so',
|
|
191
|
+
};
|
|
192
|
+
const middleware = createOxyRequesterAssertionAuth(introspector, {
|
|
193
|
+
audience: 'alia',
|
|
194
|
+
now: () => NOW,
|
|
195
|
+
resolvePublicKey: async (keyId) => (keyId === KEY_ID ? KEY.publicKey : undefined),
|
|
196
|
+
});
|
|
197
|
+
const run = async (request: Partial<OxyRequesterAssertionRequest> & { headers: Record<string, unknown> }) => {
|
|
198
|
+
let statusCode = 200;
|
|
199
|
+
let body: Record<string, unknown> | undefined;
|
|
200
|
+
const res = {
|
|
201
|
+
status(code: number) { statusCode = code; return this; },
|
|
202
|
+
json(value: Record<string, unknown>) { body = value; return this; },
|
|
203
|
+
} as unknown as Response;
|
|
204
|
+
const next = jest.fn() as unknown as NextFunction;
|
|
205
|
+
await middleware(request as unknown as Request, res, next);
|
|
206
|
+
return { statusCode, body, next: next as unknown as jest.Mock, request: request as OxyRequesterAssertionRequest };
|
|
207
|
+
};
|
|
208
|
+
return { introspector, run };
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
it('does nothing without the header', async () => {
|
|
212
|
+
const { run, introspector } = harness(async () => ({ active: false }));
|
|
213
|
+
const result = await run({ headers: {}, serviceApp });
|
|
214
|
+
expect(result.next).toHaveBeenCalledTimes(1);
|
|
215
|
+
expect(result.request.userId).toBeUndefined();
|
|
216
|
+
expect(introspector.introspectRequesterAssertion).not.toHaveBeenCalled();
|
|
217
|
+
});
|
|
218
|
+
|
|
219
|
+
it('attaches the requester only after live introspection succeeds', async () => {
|
|
220
|
+
const value = claims();
|
|
221
|
+
const assertion = sign(value);
|
|
222
|
+
const { run, introspector } = harness(async () => activeAnswer(value));
|
|
223
|
+
const result = await run({ headers: { [OXY_REQUESTER_ASSERTION_HEADER]: assertion }, serviceApp, userId: null, user: null });
|
|
224
|
+
expect(result.next).toHaveBeenCalledTimes(1);
|
|
225
|
+
expect(result.request.userId).toBe('requester-1');
|
|
226
|
+
expect(result.request.user).toEqual({ id: 'requester-1' });
|
|
227
|
+
expect(result.request.oxyRequester).toMatchObject({ userId: 'requester-1', agentId: 'sindi-agent', jti: value.jti });
|
|
228
|
+
expect(introspector.introspectRequesterAssertion).toHaveBeenCalledWith({
|
|
229
|
+
assertion,
|
|
230
|
+
presenter: { applicationId: 'homiio-app', credentialId: 'sindi-credential' },
|
|
231
|
+
});
|
|
232
|
+
});
|
|
233
|
+
|
|
234
|
+
it('requires a verified service token as presenter', async () => {
|
|
235
|
+
const { run } = harness(async () => activeAnswer(claims()));
|
|
236
|
+
const result = await run({ headers: { [OXY_REQUESTER_ASSERTION_HEADER]: sign(claims()) } });
|
|
237
|
+
expect(result.statusCode).toBe(401);
|
|
238
|
+
expect(result.body?.code).toBe('service_token_required');
|
|
239
|
+
expect(result.next).not.toHaveBeenCalled();
|
|
240
|
+
});
|
|
241
|
+
|
|
242
|
+
it('refuses to combine with offline delegation or an existing identity', async () => {
|
|
243
|
+
const { run, introspector } = harness(async () => activeAnswer(claims()));
|
|
244
|
+
const assertion = sign(claims());
|
|
245
|
+
for (const request of [
|
|
246
|
+
{ headers: { [OXY_REQUESTER_ASSERTION_HEADER]: assertion, 'x-oxy-user-id': 'victim' }, serviceApp },
|
|
247
|
+
{ headers: { [OXY_REQUESTER_ASSERTION_HEADER]: assertion }, serviceApp, serviceActingAs: { userId: 'victim', scopes: [] } },
|
|
248
|
+
{ headers: { [OXY_REQUESTER_ASSERTION_HEADER]: assertion }, serviceApp, userId: 'victim' },
|
|
249
|
+
]) {
|
|
250
|
+
const result = await run(request);
|
|
251
|
+
expect(result.statusCode).toBe(400);
|
|
252
|
+
expect(result.next).not.toHaveBeenCalled();
|
|
253
|
+
}
|
|
254
|
+
expect(introspector.introspectRequesterAssertion).not.toHaveBeenCalled();
|
|
255
|
+
});
|
|
256
|
+
|
|
257
|
+
it('refuses an assertion presented by another application or credential without spending it', async () => {
|
|
258
|
+
const { run, introspector } = harness(async () => activeAnswer(claims()));
|
|
259
|
+
for (const presenter of [
|
|
260
|
+
{ ...serviceApp, appId: 'other-app' },
|
|
261
|
+
{ ...serviceApp, credentialId: 'other-credential' },
|
|
262
|
+
]) {
|
|
263
|
+
const result = await run({ headers: { [OXY_REQUESTER_ASSERTION_HEADER]: sign(claims()) }, serviceApp: presenter });
|
|
264
|
+
expect(result.statusCode).toBe(401);
|
|
265
|
+
expect(result.body?.code).toBe('presenter_mismatch');
|
|
266
|
+
}
|
|
267
|
+
expect(introspector.introspectRequesterAssertion).not.toHaveBeenCalled();
|
|
268
|
+
});
|
|
269
|
+
|
|
270
|
+
it('refuses forged, expired and wrong-audience assertions before introspection', async () => {
|
|
271
|
+
const { run, introspector } = harness(async () => activeAnswer(claims()));
|
|
272
|
+
for (const [token, code] of [
|
|
273
|
+
[sign(claims(), OTHER_KEY.privateKey), 'invalid_signature'],
|
|
274
|
+
[sign(claims({ iat: NOW_SECONDS - 300, exp: NOW_SECONDS - 180 })), 'expired'],
|
|
275
|
+
[sign(claims({ aud: 'kaana' })), 'wrong_audience'],
|
|
276
|
+
[signOxyRequesterAssertion(claims(), { keyId: 'unknown', privateKey: KEY.privateKey }), 'unknown_key'],
|
|
277
|
+
['garbage', 'malformed'],
|
|
278
|
+
] as const) {
|
|
279
|
+
const result = await run({ headers: { [OXY_REQUESTER_ASSERTION_HEADER]: token }, serviceApp });
|
|
280
|
+
expect(result.statusCode).toBe(401);
|
|
281
|
+
expect(result.body?.code).toBe(code);
|
|
282
|
+
}
|
|
283
|
+
expect(introspector.introspectRequesterAssertion).not.toHaveBeenCalled();
|
|
284
|
+
});
|
|
285
|
+
|
|
286
|
+
it('refuses a replayed (inactive) assertion and a mismatched introspection answer', async () => {
|
|
287
|
+
const value = claims();
|
|
288
|
+
const answers: OxyRequesterAssertionIntrospection[] = [
|
|
289
|
+
{ active: false },
|
|
290
|
+
{ ...activeAnswer(value), requesterAccountId: 'someone-else' },
|
|
291
|
+
{ ...activeAnswer(value), agentId: 'other-agent' },
|
|
292
|
+
{ ...activeAnswer(value), jti: randomUUID() },
|
|
293
|
+
];
|
|
294
|
+
const { run } = harness(async () => answers.shift() as OxyRequesterAssertionIntrospection);
|
|
295
|
+
for (let i = 0; i < 4; i += 1) {
|
|
296
|
+
const result = await run({ headers: { [OXY_REQUESTER_ASSERTION_HEADER]: sign(value) }, serviceApp });
|
|
297
|
+
expect(result.statusCode).toBe(401);
|
|
298
|
+
expect(result.body?.error).toBe('REQUESTER_ASSERTION_INACTIVE');
|
|
299
|
+
expect(result.request.userId).toBeUndefined();
|
|
300
|
+
}
|
|
301
|
+
});
|
|
302
|
+
|
|
303
|
+
it('reports each rejection with ids only', async () => {
|
|
304
|
+
const events: unknown[] = [];
|
|
305
|
+
const introspector = {
|
|
306
|
+
introspectRequesterAssertion: jest.fn(async () => ({ active: false })),
|
|
307
|
+
getBaseURL: () => 'https://api.oxy.so',
|
|
308
|
+
};
|
|
309
|
+
const middleware = createOxyRequesterAssertionAuth(introspector, {
|
|
310
|
+
audience: 'alia',
|
|
311
|
+
now: () => NOW,
|
|
312
|
+
resolvePublicKey: async () => KEY.publicKey,
|
|
313
|
+
onRejected: (event) => events.push(event),
|
|
314
|
+
});
|
|
315
|
+
const assertion = sign(claims());
|
|
316
|
+
const res = { status() { return this; }, json() { return this; } } as unknown as Response;
|
|
317
|
+
await middleware({ headers: { [OXY_REQUESTER_ASSERTION_HEADER]: assertion }, serviceApp } as unknown as Request, res, jest.fn());
|
|
318
|
+
expect(events).toEqual([{ code: 'inactive', status: 401, applicationId: 'homiio-app' }]);
|
|
319
|
+
expect(JSON.stringify(events)).not.toContain(assertion);
|
|
320
|
+
});
|
|
321
|
+
|
|
322
|
+
it('fails closed when Oxy cannot be asked', async () => {
|
|
323
|
+
const { run } = harness(async () => { throw new Error('ECONNREFUSED'); });
|
|
324
|
+
const result = await run({ headers: { [OXY_REQUESTER_ASSERTION_HEADER]: sign(claims()) }, serviceApp });
|
|
325
|
+
expect(result.statusCode).toBe(503);
|
|
326
|
+
expect(result.next).not.toHaveBeenCalled();
|
|
327
|
+
});
|
|
328
|
+
});
|
|
329
|
+
|
|
330
|
+
describe('OxyServices requester assertion calls', () => {
|
|
331
|
+
afterEach(() => jest.restoreAllMocks());
|
|
332
|
+
|
|
333
|
+
it('mints with the product service token and sends the subject token only in the body', async () => {
|
|
334
|
+
const oxy = new OxyServices({ baseURL: 'http://test.invalid' });
|
|
335
|
+
jest.spyOn(oxy, 'getServiceToken').mockResolvedValue('product-service-token');
|
|
336
|
+
const spy = jest.spyOn(oxy, 'makeRequest').mockResolvedValue({ assertion: 'a', expiresAt: 'e', requesterAccountId: 'u', agentId: 'g' } as never);
|
|
337
|
+
await oxy.mintRequesterAssertion({ agentId: 'sindi-agent', subjectToken: 'human-bearer' });
|
|
338
|
+
const [method, url, data, options] = spy.mock.calls[0] ?? [];
|
|
339
|
+
expect(method).toBe('POST');
|
|
340
|
+
expect(url).toBe('/internal/native-agents/requester-assertions');
|
|
341
|
+
expect(data).toEqual({ agentId: 'sindi-agent', subjectToken: 'human-bearer' });
|
|
342
|
+
expect(options?.headers).toEqual({ Authorization: 'Bearer product-service-token' });
|
|
343
|
+
expect(options?.retry).toBe(false);
|
|
344
|
+
expect(JSON.stringify(options)).not.toContain('human-bearer');
|
|
345
|
+
});
|
|
346
|
+
|
|
347
|
+
it('introspects with the audience service token and never retries a consuming call', async () => {
|
|
348
|
+
const oxy = new OxyServices({ baseURL: 'http://test.invalid' });
|
|
349
|
+
jest.spyOn(oxy, 'getServiceToken').mockResolvedValue('alia-service-token');
|
|
350
|
+
const spy = jest.spyOn(oxy, 'makeRequest').mockResolvedValue({ active: false } as never);
|
|
351
|
+
const presenter = { applicationId: 'homiio-app', credentialId: 'sindi-credential' };
|
|
352
|
+
await expect(oxy.introspectRequesterAssertion({ assertion: 'signed', presenter })).resolves.toEqual({ active: false });
|
|
353
|
+
const [method, url, data, options] = spy.mock.calls[0] ?? [];
|
|
354
|
+
expect([method, url]).toEqual(['POST', '/internal/native-agents/requester-assertions/introspect']);
|
|
355
|
+
expect(data).toEqual({ assertion: 'signed', presenter });
|
|
356
|
+
expect(options?.headers).toEqual({ Authorization: 'Bearer alia-service-token' });
|
|
357
|
+
expect(options?.retry).toBe(false);
|
|
358
|
+
});
|
|
359
|
+
});
|
package/src/server/index.ts
CHANGED
|
@@ -109,6 +109,33 @@ export type {
|
|
|
109
109
|
CapabilityTicketVerificationOptions,
|
|
110
110
|
} from './capabilityTicket';
|
|
111
111
|
|
|
112
|
+
// Present-requester assertions (ADR 0025): a product backend trades a signed-in
|
|
113
|
+
// person's live session with Oxy for a one-use assertion its audience consumes.
|
|
114
|
+
export {
|
|
115
|
+
createOxyJwksKeyResolver,
|
|
116
|
+
createOxyRequesterAssertionAuth,
|
|
117
|
+
OXY_REQUESTER_ASSERTION_DEFAULT_ISSUER,
|
|
118
|
+
OXY_REQUESTER_ASSERTION_HEADER,
|
|
119
|
+
OXY_REQUESTER_ASSERTION_MAX_TTL_SECONDS,
|
|
120
|
+
OXY_REQUESTER_ASSERTION_TYPE,
|
|
121
|
+
OxyRequesterAssertionError,
|
|
122
|
+
oxyRequesterAssertionClaimsSchema,
|
|
123
|
+
readOxyRequesterAssertionKeyId,
|
|
124
|
+
signOxyRequesterAssertion,
|
|
125
|
+
verifyOxyRequesterAssertion,
|
|
126
|
+
} from './requesterAssertion';
|
|
127
|
+
export type {
|
|
128
|
+
OxyJwksKeyResolverOptions,
|
|
129
|
+
OxyRequesterAssertionAuthOptions,
|
|
130
|
+
OxyRequesterAssertionClaims,
|
|
131
|
+
OxyRequesterAssertionErrorCode,
|
|
132
|
+
OxyRequesterAssertionIntrospection,
|
|
133
|
+
OxyRequesterAssertionIntrospector,
|
|
134
|
+
OxyRequesterAssertionRequest,
|
|
135
|
+
OxyRequesterAssertionVerificationOptions,
|
|
136
|
+
OxyRequesterContext,
|
|
137
|
+
} from './requesterAssertion';
|
|
138
|
+
|
|
112
139
|
// Constant-time secret comparison.
|
|
113
140
|
export { verifySecret } from './verifySecret';
|
|
114
141
|
|