@adonis-agora/authkit-sdk 1.0.0-rc.0 → 1.0.0-rc.2
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/CHANGELOG.md +26 -0
- package/build/src/embedded_driver.js +50 -8
- package/build/src/remote_driver.js +6 -0
- package/build/src/types.d.ts +18 -0
- package/package.json +3 -3
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,31 @@
|
|
|
1
1
|
# @adonis-agora/authkit-sdk
|
|
2
2
|
|
|
3
|
+
## 1.0.0-rc.2
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [#473](https://github.com/DavideCarvalho/adonis-agora-authkit/pull/473) [`427c4a3`](https://github.com/DavideCarvalho/adonis-agora-authkit/commit/427c4a301907dc78d8e7c5405d4e73e29b8a2be4) Thanks [@DavideCarvalho](https://github.com/DavideCarvalho)! - Every table AuthKit owns now uses one Lucid connection: `schema.connection` (default: the primary connection). Before, some of them followed other connections, so with the account model on a named connection the boot created a table on one connection and the code read it on another:
|
|
8
|
+
|
|
9
|
+
- `auth_settings` (runtime settings, the settings CLI, `authkit:expire-scan`, the SDK's embedded driver) followed the account model's connection.
|
|
10
|
+
- `auth_mfa` and `auth_password_history` used the account model's connection.
|
|
11
|
+
- The built-in organization models had no connection, so they always used the primary one.
|
|
12
|
+
- `adapters.database()` and the `lucid` keystore without their own `connection` used the primary connection.
|
|
13
|
+
|
|
14
|
+
They all use `schema.connection` now; `adapters.database({ connection })` and `jwks.store: { driver: 'lucid', connection }` still win when set. The app's account table stays on the account model's connection, and the boot adds the `login_methods` column there. If your app had `schema.connection` unset and the account model on a named connection, those tables move to the primary connection: set `schema.connection` to the connection where they already are.
|
|
15
|
+
|
|
16
|
+
## 1.0.0-rc.1
|
|
17
|
+
|
|
18
|
+
### Minor Changes
|
|
19
|
+
|
|
20
|
+
- [#460](https://github.com/DavideCarvalho/adonis-agora-authkit/pull/460) [`1858ee8`](https://github.com/DavideCarvalho/adonis-agora-authkit/commit/1858ee837bb4edcf0578f86d224693ac9a86a495) Thanks [@DavideCarvalho](https://github.com/DavideCarvalho)! - Service tenants: a client can act as one partition of another service, such as a durable control plane.
|
|
21
|
+
|
|
22
|
+
- `serviceTenants: { resources: { 'urn:agora:durable': { expiresIn: 600 } } }` in `config/authkit.ts` declares the resources (RFC 8707) that issue service-tenant tokens: JWT access tokens (RFC 9068) with `aud` = the resource and the client's `partition` and `capabilities` as claims.
|
|
23
|
+
- A service-tenant client is confidential, uses only `client_credentials` and has no redirect URIs. Create and edit it from the console (**Service tenant** kind), the Admin API and the SDKs (`serviceTenant: { partition, capabilities? }`), or `node ace authkit:clients:create --partition=acme --capability=reports`.
|
|
24
|
+
- Any client can now be disabled and enabled again (console, `POST /clients/:id/disable|enable`, SDK `clients.disable/enable`): the token endpoint answers `invalid_client` from the next request on.
|
|
25
|
+
- `authkitTenantVerifier()` (authkit-server) verifies those tokens against the local issuer and keys and returns `{ tenant, capabilities }`; `authkitTenantToken({ issuer, clientId, clientSecret, resource })` (authkit-client) fetches, caches and refreshes them on the tenant side. Both fit durable's `verifyTenant` and `tenant.token` as a function or a class, without depending on durable.
|
|
26
|
+
- New audit events: `client.disabled`, `client.enabled`, `service_tenant.token_issued`.
|
|
27
|
+
- Access-token verification (`oidcBearerGuard`, in-process and remote) now refuses a token whose `sub` is a client (a `client_credentials` token), so a service-tenant token never authenticates a user.
|
|
28
|
+
|
|
3
29
|
## 1.0.0-rc.0
|
|
4
30
|
|
|
5
31
|
### Major Changes
|
|
@@ -84,6 +84,8 @@ export async function createEmbeddedAuthkit(opts) {
|
|
|
84
84
|
tokenEndpointAuthMethod: client.tokenEndpointAuthMethod,
|
|
85
85
|
clientName: client.clientName ?? null,
|
|
86
86
|
logoUri: client.logoUri ?? null,
|
|
87
|
+
disabled: client.disabled ?? false,
|
|
88
|
+
serviceTenant: client.serviceTenant ?? null,
|
|
87
89
|
};
|
|
88
90
|
}
|
|
89
91
|
function sessionDto(s) {
|
|
@@ -126,10 +128,43 @@ export async function createEmbeddedAuthkit(opts) {
|
|
|
126
128
|
clientId: input.clientId?.trim() || undefined,
|
|
127
129
|
redirectUris: input.redirectUris ?? [],
|
|
128
130
|
postLogoutRedirectUris: input.postLogoutRedirectUris ?? [],
|
|
129
|
-
|
|
131
|
+
// A service tenant only uses client_credentials: that is its default grant.
|
|
132
|
+
grantTypes: input.grantTypes ?? (input.serviceTenant ? ['client_credentials'] : []),
|
|
130
133
|
tokenEndpointAuthMethod: input.tokenEndpointAuthMethod ?? 'client_secret_basic',
|
|
134
|
+
...(input.serviceTenant ? { serviceTenant: input.serviceTenant } : {}),
|
|
131
135
|
};
|
|
132
136
|
}
|
|
137
|
+
/** PATCH: only the fields sent; the service keeps the rest. */
|
|
138
|
+
function partialClientInput(input) {
|
|
139
|
+
const out = {};
|
|
140
|
+
for (const key of [
|
|
141
|
+
'redirectUris',
|
|
142
|
+
'postLogoutRedirectUris',
|
|
143
|
+
'grantTypes',
|
|
144
|
+
'tokenEndpointAuthMethod',
|
|
145
|
+
'serviceTenant',
|
|
146
|
+
]) {
|
|
147
|
+
if (input[key] !== undefined)
|
|
148
|
+
out[key] = input[key];
|
|
149
|
+
}
|
|
150
|
+
return out;
|
|
151
|
+
}
|
|
152
|
+
async function setClientDisabled(id, disabled) {
|
|
153
|
+
const svc = new AdminClientsService(service);
|
|
154
|
+
if (!(await svc.setDisabled(id, disabled)))
|
|
155
|
+
throw new Error('Client não encontrado.');
|
|
156
|
+
const client = await svc.find(id);
|
|
157
|
+
await cfg.audit?.record({
|
|
158
|
+
type: disabled ? 'client.disabled' : 'client.enabled',
|
|
159
|
+
clientId: id,
|
|
160
|
+
ip: null,
|
|
161
|
+
metadata: {
|
|
162
|
+
actor: 'admin-api',
|
|
163
|
+
...(client?.serviceTenant ? { partition: client.serviceTenant.partition } : {}),
|
|
164
|
+
},
|
|
165
|
+
});
|
|
166
|
+
return clientDto(client);
|
|
167
|
+
}
|
|
133
168
|
return {
|
|
134
169
|
users: {
|
|
135
170
|
async list(params = {}) {
|
|
@@ -257,7 +292,7 @@ export async function createEmbeddedAuthkit(opts) {
|
|
|
257
292
|
const existing = await svc.find(id);
|
|
258
293
|
if (!existing)
|
|
259
294
|
throw new Error('Client não encontrado.');
|
|
260
|
-
await svc.update(id,
|
|
295
|
+
await svc.update(id, partialClientInput(input));
|
|
261
296
|
await cfg.audit?.record({
|
|
262
297
|
type: 'client.updated',
|
|
263
298
|
clientId: id,
|
|
@@ -269,14 +304,21 @@ export async function createEmbeddedAuthkit(opts) {
|
|
|
269
304
|
async regenerateSecret(id) {
|
|
270
305
|
const svc = new AdminClientsService(service);
|
|
271
306
|
const secret = await svc.regenerateSecret(id);
|
|
307
|
+
const tenant = (await svc.find(id))?.serviceTenant;
|
|
272
308
|
await cfg.audit?.record({
|
|
273
309
|
type: 'client.updated',
|
|
274
310
|
clientId: id,
|
|
275
311
|
ip: null,
|
|
276
|
-
metadata: {
|
|
312
|
+
metadata: {
|
|
313
|
+
actor: 'admin-api',
|
|
314
|
+
action: 'regenerate_secret',
|
|
315
|
+
...(tenant ? { partition: tenant.partition } : {}),
|
|
316
|
+
},
|
|
277
317
|
});
|
|
278
318
|
return { clientId: id, clientSecret: secret };
|
|
279
319
|
},
|
|
320
|
+
disable: (id) => setClientDisabled(id, true),
|
|
321
|
+
enable: (id) => setClientDisabled(id, false),
|
|
280
322
|
async delete(id) {
|
|
281
323
|
const svc = new AdminClientsService(service);
|
|
282
324
|
await svc.delete(id);
|
|
@@ -452,7 +494,7 @@ export async function createEmbeddedAuthkit(opts) {
|
|
|
452
494
|
catch {
|
|
453
495
|
return { data: [] };
|
|
454
496
|
}
|
|
455
|
-
const connection = cfg.
|
|
497
|
+
const connection = cfg.schema?.connection;
|
|
456
498
|
const svc = new RuntimeSettings(db, connection ? { connection } : {});
|
|
457
499
|
const rows = await svc.listSettings();
|
|
458
500
|
return {
|
|
@@ -473,7 +515,7 @@ export async function createEmbeddedAuthkit(opts) {
|
|
|
473
515
|
catch {
|
|
474
516
|
throw new Error('Runtime settings not available.');
|
|
475
517
|
}
|
|
476
|
-
const connection = cfg.
|
|
518
|
+
const connection = cfg.schema?.connection;
|
|
477
519
|
const svc = new RuntimeSettings(db, connection ? { connection } : {});
|
|
478
520
|
const value = await svc.getSetting(key);
|
|
479
521
|
if (value === null)
|
|
@@ -489,7 +531,7 @@ export async function createEmbeddedAuthkit(opts) {
|
|
|
489
531
|
catch {
|
|
490
532
|
throw new Error('Runtime settings not available.');
|
|
491
533
|
}
|
|
492
|
-
const connection = cfg.
|
|
534
|
+
const connection = cfg.schema?.connection;
|
|
493
535
|
const svc = new RuntimeSettings(db, connection ? { connection } : {});
|
|
494
536
|
await svc.setSetting(key, value, null);
|
|
495
537
|
const saved = await svc.getSetting(key);
|
|
@@ -510,7 +552,7 @@ export async function createEmbeddedAuthkit(opts) {
|
|
|
510
552
|
catch {
|
|
511
553
|
throw new Error('Runtime settings not available.');
|
|
512
554
|
}
|
|
513
|
-
const connection = cfg.
|
|
555
|
+
const connection = cfg.schema?.connection;
|
|
514
556
|
const svc = new RuntimeSettings(db, connection ? { connection } : {});
|
|
515
557
|
await svc.deleteSetting(key);
|
|
516
558
|
await cfg.audit?.record({
|
|
@@ -529,7 +571,7 @@ export async function createEmbeddedAuthkit(opts) {
|
|
|
529
571
|
let settingsSvc = null;
|
|
530
572
|
try {
|
|
531
573
|
const db = await app.container.make('lucid.db');
|
|
532
|
-
const connection = cfg.
|
|
574
|
+
const connection = cfg.schema?.connection;
|
|
533
575
|
settingsSvc = new RuntimeSettings(db, connection ? { connection } : {});
|
|
534
576
|
}
|
|
535
577
|
catch {
|
|
@@ -112,6 +112,12 @@ export function createRemoteAuthkit(opts) {
|
|
|
112
112
|
regenerateSecret(id) {
|
|
113
113
|
return request('POST', `/clients/${encodeURIComponent(id)}/regenerate-secret`);
|
|
114
114
|
},
|
|
115
|
+
disable(id) {
|
|
116
|
+
return request('POST', `/clients/${encodeURIComponent(id)}/disable`);
|
|
117
|
+
},
|
|
118
|
+
enable(id) {
|
|
119
|
+
return request('POST', `/clients/${encodeURIComponent(id)}/enable`);
|
|
120
|
+
},
|
|
115
121
|
delete(id) {
|
|
116
122
|
return request('DELETE', `/clients/${encodeURIComponent(id)}`);
|
|
117
123
|
},
|
package/build/src/types.d.ts
CHANGED
|
@@ -127,6 +127,13 @@ export interface AuthkitClient {
|
|
|
127
127
|
clientName: string | null;
|
|
128
128
|
/** Registered `logo_uri`, or `null`. */
|
|
129
129
|
logoUri: string | null;
|
|
130
|
+
/** Disabled clients get no tokens until enabled again. */
|
|
131
|
+
disabled: boolean;
|
|
132
|
+
/** Service-tenant settings, or `null` for a regular client. */
|
|
133
|
+
serviceTenant: {
|
|
134
|
+
partition: string;
|
|
135
|
+
capabilities: string[];
|
|
136
|
+
} | null;
|
|
130
137
|
}
|
|
131
138
|
export interface ListClientsResult {
|
|
132
139
|
data: AuthkitClient[];
|
|
@@ -139,6 +146,14 @@ export interface ClientInput {
|
|
|
139
146
|
postLogoutRedirectUris?: string[];
|
|
140
147
|
grantTypes?: string[];
|
|
141
148
|
tokenEndpointAuthMethod?: TokenEndpointAuthMethod;
|
|
149
|
+
/**
|
|
150
|
+
* Makes the client a service tenant (confidential, `client_credentials` only, no
|
|
151
|
+
* redirect URIs). On update, `null` turns it back into a regular client.
|
|
152
|
+
*/
|
|
153
|
+
serviceTenant?: {
|
|
154
|
+
partition: string;
|
|
155
|
+
capabilities?: string[];
|
|
156
|
+
} | null;
|
|
142
157
|
}
|
|
143
158
|
/** Created/regenerated client — the secret is shown ONCE (`createdClientDto`). */
|
|
144
159
|
export interface AuthkitCreatedClient {
|
|
@@ -381,6 +396,9 @@ export interface Authkit {
|
|
|
381
396
|
create(input: ClientInput): Promise<AuthkitCreatedClient>;
|
|
382
397
|
update(id: string, input: ClientInput): Promise<AuthkitClient>;
|
|
383
398
|
regenerateSecret(id: string): Promise<RegeneratedSecret>;
|
|
399
|
+
/** Stops issuing tokens to the client (`invalid_client`) until `enable`. */
|
|
400
|
+
disable(id: string): Promise<AuthkitClient>;
|
|
401
|
+
enable(id: string): Promise<AuthkitClient>;
|
|
384
402
|
delete(id: string): Promise<DeletedClient>;
|
|
385
403
|
};
|
|
386
404
|
audit: {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@adonis-agora/authkit-sdk",
|
|
3
|
-
"version": "1.0.0-rc.
|
|
3
|
+
"version": "1.0.0-rc.2",
|
|
4
4
|
"description": "Backend SDK for the AuthKit Admin API with one typed interface and two drivers: remote (HTTP/Bearer) and embedded (in-process when the IdP runs in the same AdonisJS app).",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "dudousxd",
|
|
@@ -51,13 +51,13 @@
|
|
|
51
51
|
}
|
|
52
52
|
},
|
|
53
53
|
"devDependencies": {
|
|
54
|
-
"@adonis-agora/authkit-server": "1.0.0-rc.
|
|
54
|
+
"@adonis-agora/authkit-server": "1.0.0-rc.11",
|
|
55
55
|
"@adonisjs/core": "7.6.0",
|
|
56
56
|
"@adonisjs/tsconfig": "2.0.0",
|
|
57
57
|
"@japa/assert": "4.2.0",
|
|
58
58
|
"@japa/runner": "5.4.0",
|
|
59
59
|
"@poppinss/ts-exec": "1.5.2",
|
|
60
|
-
"@types/node": "26.6.
|
|
60
|
+
"@types/node": "26.6.6",
|
|
61
61
|
"typescript": "7.0.2"
|
|
62
62
|
},
|
|
63
63
|
"scripts": {
|