@adonis-agora/authkit-server 1.0.0-rc.2 → 1.0.0-rc.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/CHANGELOG.md +13 -0
- package/build/commands/clients_create.d.ts +4 -0
- package/build/commands/clients_create.js +97 -0
- package/build/commands/commands.json +14 -0
- package/build/index.d.ts +3 -0
- package/build/index.js +1 -0
- package/build/src/audit/audit_sink.d.ts +1 -1
- package/build/src/audit/audit_sink.js +5 -0
- package/build/src/define_config.d.ts +16 -0
- package/build/src/define_config.js +2 -0
- package/build/src/host/access_token_verifier.js +7 -0
- package/build/src/host/admin_api/api_clients_controller.d.ts +37 -0
- package/build/src/host/admin_api/api_clients_controller.js +31 -1
- package/build/src/host/admin_api/dto.d.ts +3 -1
- package/build/src/host/admin_api/dto.js +2 -0
- package/build/src/host/admin_clients_service.d.ts +20 -0
- package/build/src/host/admin_clients_service.js +55 -0
- package/build/src/host/admin_console/console_clients_controller.d.ts +41 -0
- package/build/src/host/admin_console/console_clients_controller.js +34 -1
- package/build/src/host/admin_validators.d.ts +29 -0
- package/build/src/host/admin_validators.js +30 -0
- package/build/src/host/register_auth_host.js +4 -0
- package/build/src/host/ui-dist/assets/index-u0bMxkLg.js +67 -0
- package/build/src/host/ui-dist/index.html +1 -1
- package/build/src/provider/build_provider.js +37 -6
- package/build/src/service_tenants/client_metadata.d.ts +39 -0
- package/build/src/service_tenants/client_metadata.js +80 -0
- package/build/src/service_tenants/config.d.ts +44 -0
- package/build/src/service_tenants/config.js +44 -0
- package/build/src/service_tenants/provider_hooks.d.ts +52 -0
- package/build/src/service_tenants/provider_hooks.js +124 -0
- package/build/src/service_tenants/tenant_verifier.d.ts +73 -0
- package/build/src/service_tenants/tenant_verifier.js +104 -0
- package/package.json +2 -2
- package/build/src/host/ui-dist/assets/index-BqyJYRVX.js +0 -67
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
import { createLocalJWKSet, errors as joseErrors, jwtVerify } from 'jose';
|
|
2
|
+
import { getBootedApp } from '../../services/booted_app.js';
|
|
3
|
+
/** Asymmetric JWS algorithms only: never `none`, never `HS*`. */
|
|
4
|
+
const ALGORITHMS = [
|
|
5
|
+
'RS256',
|
|
6
|
+
'RS384',
|
|
7
|
+
'RS512',
|
|
8
|
+
'PS256',
|
|
9
|
+
'PS384',
|
|
10
|
+
'PS512',
|
|
11
|
+
'ES256',
|
|
12
|
+
'ES384',
|
|
13
|
+
'ES512',
|
|
14
|
+
'EdDSA',
|
|
15
|
+
'Ed25519',
|
|
16
|
+
];
|
|
17
|
+
const defaultIssuer = async () => (await getBootedApp().container.make('authkit.server'));
|
|
18
|
+
function audienceFor(issuer, explicit) {
|
|
19
|
+
if (explicit)
|
|
20
|
+
return explicit;
|
|
21
|
+
const resources = Object.values(issuer.config.serviceTenants?.resources ?? {});
|
|
22
|
+
if (resources.length === 1)
|
|
23
|
+
return resources[0].audience;
|
|
24
|
+
throw new Error(resources.length === 0
|
|
25
|
+
? 'authkitTenantVerifier: no serviceTenants.resources declared in config/authkit.ts'
|
|
26
|
+
: 'authkitTenantVerifier: several serviceTenants.resources are declared; pass { audience }');
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Verifies service-tenant tokens against the local authkit issuer and its JWKS (no
|
|
30
|
+
* network call), and returns the tenant they authenticate as, or `null`.
|
|
31
|
+
*
|
|
32
|
+
* Satisfies durable's `TenantVerifierContract` (`verify(input)`); usable as a class in
|
|
33
|
+
* `verifyTenant` (built by the container with the default options) or through
|
|
34
|
+
* {@link authkitTenantVerifier}.
|
|
35
|
+
*/
|
|
36
|
+
export class AuthkitTenantVerifier {
|
|
37
|
+
#options;
|
|
38
|
+
#jwks;
|
|
39
|
+
#keySet;
|
|
40
|
+
constructor(options = {}) {
|
|
41
|
+
this.#options = options;
|
|
42
|
+
}
|
|
43
|
+
#keySetFor(jwks) {
|
|
44
|
+
// `publicJwks` is a new object whenever the keys change (rotation/reload).
|
|
45
|
+
if (jwks !== this.#jwks || !this.#keySet) {
|
|
46
|
+
this.#jwks = jwks;
|
|
47
|
+
this.#keySet = createLocalJWKSet(jwks);
|
|
48
|
+
}
|
|
49
|
+
return this.#keySet;
|
|
50
|
+
}
|
|
51
|
+
async verify(input) {
|
|
52
|
+
const token = input?.token;
|
|
53
|
+
if (typeof token !== 'string' || !token)
|
|
54
|
+
return null;
|
|
55
|
+
const issuer = await (this.#options.issuer ?? defaultIssuer)();
|
|
56
|
+
const audience = audienceFor(issuer, this.#options.audience);
|
|
57
|
+
let payload;
|
|
58
|
+
try {
|
|
59
|
+
({ payload } = await jwtVerify(token, this.#keySetFor(issuer.publicJwks), {
|
|
60
|
+
issuer: issuer.config.issuer,
|
|
61
|
+
audience,
|
|
62
|
+
algorithms: ALGORITHMS,
|
|
63
|
+
typ: 'at+jwt',
|
|
64
|
+
clockTolerance: this.#options.clockToleranceSec ?? 30,
|
|
65
|
+
requiredClaims: ['exp', 'sub'],
|
|
66
|
+
}));
|
|
67
|
+
}
|
|
68
|
+
catch (error) {
|
|
69
|
+
if (error instanceof joseErrors.JOSEError)
|
|
70
|
+
return null;
|
|
71
|
+
throw error;
|
|
72
|
+
}
|
|
73
|
+
// A client_credentials token: no user behind it, `sub` is the client.
|
|
74
|
+
const clientId = payload.client_id;
|
|
75
|
+
if (typeof clientId !== 'string' || payload.sub !== clientId)
|
|
76
|
+
return null;
|
|
77
|
+
const partition = payload[this.#options.partitionClaim ?? 'partition'];
|
|
78
|
+
if (typeof partition !== 'string' || !partition)
|
|
79
|
+
return null;
|
|
80
|
+
const rawCapabilities = payload[this.#options.capabilitiesClaim ?? 'capabilities'];
|
|
81
|
+
if (rawCapabilities === undefined)
|
|
82
|
+
return { tenant: partition };
|
|
83
|
+
if (!Array.isArray(rawCapabilities) || rawCapabilities.some((c) => typeof c !== 'string')) {
|
|
84
|
+
return null;
|
|
85
|
+
}
|
|
86
|
+
return { tenant: partition, capabilities: rawCapabilities };
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* Tenant verifier for a durable control plane hosted by the authkit app:
|
|
91
|
+
*
|
|
92
|
+
* ```ts
|
|
93
|
+
* // config/durable.ts
|
|
94
|
+
* verifyTenant: authkitTenantVerifier()
|
|
95
|
+
* ```
|
|
96
|
+
*
|
|
97
|
+
* The result is a function (durable's `TenantVerifier`) that also has `verify`
|
|
98
|
+
* (durable's `TenantVerifierContract`).
|
|
99
|
+
*/
|
|
100
|
+
export function authkitTenantVerifier(options = {}) {
|
|
101
|
+
const verifier = new AuthkitTenantVerifier(options);
|
|
102
|
+
const verify = (input) => verifier.verify(input);
|
|
103
|
+
return Object.assign(verify, { verify });
|
|
104
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@adonis-agora/authkit-server",
|
|
3
|
-
"version": "1.0.0-rc.
|
|
3
|
+
"version": "1.0.0-rc.3",
|
|
4
4
|
"description": "AdonisJS OIDC/OAuth2 provider (Identity Provider) toolkit: ejectable auth server with sessions, rate-limiting, MFA/TOTP, audit log, federated logout and OpenTelemetry metrics.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "dudousxd",
|
|
@@ -117,7 +117,7 @@
|
|
|
117
117
|
"qrcode": "1.5.4"
|
|
118
118
|
},
|
|
119
119
|
"devDependencies": {
|
|
120
|
-
"@adonis-agora/authkit-react": "1.0.0-rc.
|
|
120
|
+
"@adonis-agora/authkit-react": "1.0.0-rc.2",
|
|
121
121
|
"@adonis-agora/durable": "0.59.0",
|
|
122
122
|
"@adonis-agora/telescope": "0.27.1",
|
|
123
123
|
"@adonisjs/ally": "6.3.2",
|