@adonis-agora/authkit-client 0.16.0 → 0.17.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/build/index.d.ts
CHANGED
|
@@ -16,6 +16,8 @@ export { default as BackchannelRevocationMiddleware } from './src/middleware/bac
|
|
|
16
16
|
export { authkitClientGuard, AuthkitClientGuard } from './src/host/authkit_client_guard.js';
|
|
17
17
|
export type { UnauthorizedAccessConstructor } from './src/host/authkit_client_guard.js';
|
|
18
18
|
export { getAuthkit } from './src/host/request_authenticator.js';
|
|
19
|
+
export { isAuthkitAdmin, authkitDashboardAuthorize, authkitDashboardMiddleware, } from './src/host/dashboard_guard.js';
|
|
20
|
+
export type { DashboardGuardOptions } from './src/host/dashboard_guard.js';
|
|
19
21
|
export { default as AuthkitContextMiddleware } from './src/middleware/authkit_context_middleware.js';
|
|
20
22
|
export { lucidMirror } from './src/lucid_mirror.js';
|
|
21
23
|
export type { LucidMirrorOptions } from './src/lucid_mirror.js';
|
package/build/index.js
CHANGED
|
@@ -9,6 +9,7 @@ export { lucidRevocationStore, DEFAULT_REVOCATION_TABLE, } from './src/revocatio
|
|
|
9
9
|
export { default as BackchannelRevocationMiddleware } from './src/middleware/backchannel_revocation_middleware.js';
|
|
10
10
|
export { authkitClientGuard, AuthkitClientGuard } from './src/host/authkit_client_guard.js';
|
|
11
11
|
export { getAuthkit } from './src/host/request_authenticator.js';
|
|
12
|
+
export { isAuthkitAdmin, authkitDashboardAuthorize, authkitDashboardMiddleware, } from './src/host/dashboard_guard.js';
|
|
12
13
|
export { default as AuthkitContextMiddleware } from './src/middleware/authkit_context_middleware.js';
|
|
13
14
|
export { lucidMirror } from './src/lucid_mirror.js';
|
|
14
15
|
export { registerOidcClient } from './src/register_oidc_client.js';
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import type { HttpContext } from '@adonisjs/core/http';
|
|
2
|
+
export interface DashboardGuardOptions {
|
|
3
|
+
/** Global role required to pass the gate. Default `'ADMIN'`. */
|
|
4
|
+
role?: string;
|
|
5
|
+
}
|
|
6
|
+
/**
|
|
7
|
+
* Core predicate behind {@link authkitDashboardAuthorize} and
|
|
8
|
+
* {@link authkitDashboardMiddleware}: authenticated (a resolvable authkit `Identity`) AND holding
|
|
9
|
+
* the configured global role — `ctx.auth.hasGlobalRole('ADMIN')`, the pattern hosts already
|
|
10
|
+
* hand-roll per embedded admin dashboard (durable/media/agent/telescope).
|
|
11
|
+
*
|
|
12
|
+
* Resolves the session via {@link getAuthkit} rather than reading `ctx.auth` directly: `ctx.auth`'s
|
|
13
|
+
* TYPE is host-owned (each app augments `HttpContext.auth` for its own user model, or leaves it to
|
|
14
|
+
* `@adonisjs/auth`'s guard), so this module — shipped from the library, with no visibility into
|
|
15
|
+
* that augmentation — can't assume its shape. `getAuthkit` is the one session-resolution path that
|
|
16
|
+
* works either way (legacy `authkit_middleware`'s `ctx.auth` or the newer `authkitClientGuard`'s
|
|
17
|
+
* `ctx.authkit`), memoizing so a second call in the same request is free.
|
|
18
|
+
*/
|
|
19
|
+
export declare function isAuthkitAdmin(ctx: HttpContext, options?: DashboardGuardOptions): Promise<boolean>;
|
|
20
|
+
/**
|
|
21
|
+
* Adapter for the `authorize: (ctx) => boolean` shape that `@adonis-agora/durable`,
|
|
22
|
+
* `@adonis-agora/agent` and `@adonis-agora/telescope` dashboard configs expect. A `false` return
|
|
23
|
+
* makes the provider reply `403 { error: 'forbidden' }` — the provider's own behavior, unchanged
|
|
24
|
+
* here.
|
|
25
|
+
*
|
|
26
|
+
* ```ts
|
|
27
|
+
* // config/durable_dashboard.ts
|
|
28
|
+
* import { defineConfig } from '@adonis-agora/durable/dashboard'
|
|
29
|
+
* import { authkitDashboardAuthorize } from '@adonis-agora/authkit-client'
|
|
30
|
+
*
|
|
31
|
+
* export default defineConfig({
|
|
32
|
+
* authorize: authkitDashboardAuthorize(),
|
|
33
|
+
* })
|
|
34
|
+
* ```
|
|
35
|
+
*/
|
|
36
|
+
export declare function authkitDashboardAuthorize(options?: DashboardGuardOptions): (ctx: HttpContext) => Promise<boolean>;
|
|
37
|
+
/**
|
|
38
|
+
* Adapter for the `middleware: (ctx, next) => Promise<void>` shape that
|
|
39
|
+
* `@adonis-agora/media`'s dashboard config expects. Mirrors the hand-rolled `requireAdmin` apps
|
|
40
|
+
* wrote themselves: no session -> `401`; session without the role -> `403`; otherwise `next()`.
|
|
41
|
+
*
|
|
42
|
+
* ```ts
|
|
43
|
+
* // config/media_dashboard.ts
|
|
44
|
+
* import { defineConfig } from '@adonis-agora/media/dashboard'
|
|
45
|
+
* import { authkitDashboardMiddleware } from '@adonis-agora/authkit-client'
|
|
46
|
+
*
|
|
47
|
+
* export default defineConfig({
|
|
48
|
+
* middleware: authkitDashboardMiddleware(),
|
|
49
|
+
* })
|
|
50
|
+
* ```
|
|
51
|
+
*/
|
|
52
|
+
export declare function authkitDashboardMiddleware(options?: DashboardGuardOptions): (ctx: HttpContext, next: () => Promise<void>) => Promise<void>;
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import { getAuthkit } from './request_authenticator.js';
|
|
2
|
+
/** Global role that counts as "admin" when the caller doesn't override it. Mirrors the default
|
|
3
|
+
* used across `@adonis-agora/authkit-server`'s own admin console (`admin.roles`, `adminRoles` on
|
|
4
|
+
* impersonation/token-exchange) — same convention, not a new one. */
|
|
5
|
+
const DEFAULT_ADMIN_ROLE = 'ADMIN';
|
|
6
|
+
/**
|
|
7
|
+
* Core predicate behind {@link authkitDashboardAuthorize} and
|
|
8
|
+
* {@link authkitDashboardMiddleware}: authenticated (a resolvable authkit `Identity`) AND holding
|
|
9
|
+
* the configured global role — `ctx.auth.hasGlobalRole('ADMIN')`, the pattern hosts already
|
|
10
|
+
* hand-roll per embedded admin dashboard (durable/media/agent/telescope).
|
|
11
|
+
*
|
|
12
|
+
* Resolves the session via {@link getAuthkit} rather than reading `ctx.auth` directly: `ctx.auth`'s
|
|
13
|
+
* TYPE is host-owned (each app augments `HttpContext.auth` for its own user model, or leaves it to
|
|
14
|
+
* `@adonisjs/auth`'s guard), so this module — shipped from the library, with no visibility into
|
|
15
|
+
* that augmentation — can't assume its shape. `getAuthkit` is the one session-resolution path that
|
|
16
|
+
* works either way (legacy `authkit_middleware`'s `ctx.auth` or the newer `authkitClientGuard`'s
|
|
17
|
+
* `ctx.authkit`), memoizing so a second call in the same request is free.
|
|
18
|
+
*/
|
|
19
|
+
export async function isAuthkitAdmin(ctx, options = {}) {
|
|
20
|
+
const authkit = await getAuthkit(ctx);
|
|
21
|
+
if (!(await authkit.check()))
|
|
22
|
+
return false;
|
|
23
|
+
return authkit.hasGlobalRole(options.role ?? DEFAULT_ADMIN_ROLE);
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Adapter for the `authorize: (ctx) => boolean` shape that `@adonis-agora/durable`,
|
|
27
|
+
* `@adonis-agora/agent` and `@adonis-agora/telescope` dashboard configs expect. A `false` return
|
|
28
|
+
* makes the provider reply `403 { error: 'forbidden' }` — the provider's own behavior, unchanged
|
|
29
|
+
* here.
|
|
30
|
+
*
|
|
31
|
+
* ```ts
|
|
32
|
+
* // config/durable_dashboard.ts
|
|
33
|
+
* import { defineConfig } from '@adonis-agora/durable/dashboard'
|
|
34
|
+
* import { authkitDashboardAuthorize } from '@adonis-agora/authkit-client'
|
|
35
|
+
*
|
|
36
|
+
* export default defineConfig({
|
|
37
|
+
* authorize: authkitDashboardAuthorize(),
|
|
38
|
+
* })
|
|
39
|
+
* ```
|
|
40
|
+
*/
|
|
41
|
+
export function authkitDashboardAuthorize(options = {}) {
|
|
42
|
+
return (ctx) => isAuthkitAdmin(ctx, options);
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Adapter for the `middleware: (ctx, next) => Promise<void>` shape that
|
|
46
|
+
* `@adonis-agora/media`'s dashboard config expects. Mirrors the hand-rolled `requireAdmin` apps
|
|
47
|
+
* wrote themselves: no session -> `401`; session without the role -> `403`; otherwise `next()`.
|
|
48
|
+
*
|
|
49
|
+
* ```ts
|
|
50
|
+
* // config/media_dashboard.ts
|
|
51
|
+
* import { defineConfig } from '@adonis-agora/media/dashboard'
|
|
52
|
+
* import { authkitDashboardMiddleware } from '@adonis-agora/authkit-client'
|
|
53
|
+
*
|
|
54
|
+
* export default defineConfig({
|
|
55
|
+
* middleware: authkitDashboardMiddleware(),
|
|
56
|
+
* })
|
|
57
|
+
* ```
|
|
58
|
+
*/
|
|
59
|
+
export function authkitDashboardMiddleware(options = {}) {
|
|
60
|
+
return async (ctx, next) => {
|
|
61
|
+
const authkit = await getAuthkit(ctx);
|
|
62
|
+
if (!(await authkit.check())) {
|
|
63
|
+
ctx.response.unauthorized({ message: 'Authentication required' });
|
|
64
|
+
return;
|
|
65
|
+
}
|
|
66
|
+
if (!authkit.hasGlobalRole(options.role ?? DEFAULT_ADMIN_ROLE)) {
|
|
67
|
+
ctx.response.forbidden({ message: 'Admin access required' });
|
|
68
|
+
return;
|
|
69
|
+
}
|
|
70
|
+
await next();
|
|
71
|
+
};
|
|
72
|
+
}
|
package/package.json
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@adonis-agora/authkit-client",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.17.0",
|
|
4
4
|
"description": "AdonisJS OIDC/OAuth2 relying-party (client) toolkit: session-based authentication against an OpenID Connect identity provider, with JWT/PAT user resolvers and OpenTelemetry metrics.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "dudousxd",
|
|
7
7
|
"homepage": "https://github.com/DavideCarvalho/adonis-authkit/tree/main/packages/authkit-client#readme",
|
|
8
8
|
"repository": {
|
|
9
9
|
"type": "git",
|
|
10
|
-
"url": "https://github.com/DavideCarvalho/adonis-authkit.git",
|
|
10
|
+
"url": "https://github.com/DavideCarvalho/adonis-agora-authkit.git",
|
|
11
11
|
"directory": "packages/authkit-client"
|
|
12
12
|
},
|
|
13
13
|
"bugs": {
|
|
@@ -39,6 +39,7 @@
|
|
|
39
39
|
"./services/main": "./build/services/main.js",
|
|
40
40
|
"./authkit_client_provider": "./build/providers/authkit_client_provider.js",
|
|
41
41
|
"./auth": "./build/src/host/authkit_client_guard.js",
|
|
42
|
+
"./dashboard_guard": "./build/src/host/dashboard_guard.js",
|
|
42
43
|
"./authkit_middleware": "./build/src/middleware/authkit_middleware.js",
|
|
43
44
|
"./authkit_context_middleware": "./build/src/middleware/authkit_context_middleware.js",
|
|
44
45
|
"./backchannel_revocation_middleware": "./build/src/middleware/backchannel_revocation_middleware.js",
|
|
@@ -74,23 +75,23 @@
|
|
|
74
75
|
}
|
|
75
76
|
},
|
|
76
77
|
"dependencies": {
|
|
77
|
-
"jose": "
|
|
78
|
+
"jose": "5.10.0",
|
|
78
79
|
"@adonis-agora/authkit-core": "0.7.0"
|
|
79
80
|
},
|
|
80
81
|
"devDependencies": {
|
|
81
82
|
"@adonisjs/auth": "10.1.0",
|
|
82
|
-
"@adonisjs/core": "7.
|
|
83
|
-
"@adonis-agora/resilience": "
|
|
83
|
+
"@adonisjs/core": "7.4.0",
|
|
84
|
+
"@adonis-agora/resilience": "0.3.1",
|
|
84
85
|
"@adonisjs/session": "8.1.0",
|
|
85
86
|
"@adonisjs/lucid": "22.4.2",
|
|
86
87
|
"@adonisjs/tsconfig": "2.0.0",
|
|
87
88
|
"@japa/assert": "4.2.0",
|
|
88
89
|
"@japa/runner": "5.3.0",
|
|
89
90
|
"@poppinss/ts-exec": "1.4.4",
|
|
90
|
-
"ioredis-mock": "
|
|
91
|
+
"ioredis-mock": "8.13.1",
|
|
91
92
|
"@types/node": "25.9.1",
|
|
92
93
|
"typescript": "6.0.3",
|
|
93
|
-
"@adonis-agora/authkit-server": "0.
|
|
94
|
+
"@adonis-agora/authkit-server": "0.56.0"
|
|
94
95
|
},
|
|
95
96
|
"scripts": {
|
|
96
97
|
"build": "tsc && node -e \"require('node:fs').cpSync('stubs','build/stubs',{recursive:true,filter:(s)=>!s.endsWith('.ts')})\"",
|