@adonis-agora/authkit-sdk 1.0.0-rc.0 → 1.0.0-rc.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/CHANGELOG.md +13 -0
- package/build/src/embedded_driver.js +45 -3
- 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,18 @@
|
|
|
1
1
|
# @adonis-agora/authkit-sdk
|
|
2
2
|
|
|
3
|
+
## 1.0.0-rc.1
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- [#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.
|
|
8
|
+
|
|
9
|
+
- `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.
|
|
10
|
+
- 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`.
|
|
11
|
+
- 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.
|
|
12
|
+
- `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.
|
|
13
|
+
- New audit events: `client.disabled`, `client.enabled`, `service_tenant.token_issued`.
|
|
14
|
+
- 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.
|
|
15
|
+
|
|
3
16
|
## 1.0.0-rc.0
|
|
4
17
|
|
|
5
18
|
### 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);
|
|
@@ -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.1",
|
|
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.3",
|
|
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": {
|