@adonis-agora/authkit-server 0.38.0 → 0.39.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.
@@ -0,0 +1,17 @@
1
+ import type { OidcService } from "../src/provider/oidc_service.js";
2
+ /**
3
+ * Acessor singleton do {@link OidcService}, seguindo a convenção `services/main` do
4
+ * AdonisJS (igual `@adonisjs/lucid/services/db`, `@adonisjs/drive/services/main` e
5
+ * `@adonisjs/lock/services/main`). Permite que um app escreva
6
+ * `import authkit from "@adonis-agora/authkit-server/services/main"` e leia
7
+ * `authkit.config` / chame `authkit.provider` etc., em vez de resolver na mão a
8
+ * binding string-keyed `"authkit.server"` pelo container.
9
+ *
10
+ * Roda `await app.booted()` no top-level, então SÓ funciona dentro de um app
11
+ * booted — por isso `scripts/import-smoke.mjs` pula o diretório `services`.
12
+ *
13
+ * Dentro da própria lib continuamos resolvendo via `ctx.containerResolver.make("authkit.server")`,
14
+ * que é o idioma das libs first-party (ver `@adonisjs/auth`, `initialize_auth_middleware`).
15
+ */
16
+ declare let service: OidcService;
17
+ export { service as default };
@@ -0,0 +1,20 @@
1
+ import app from "@adonisjs/core/services/app";
2
+ /**
3
+ * Acessor singleton do {@link OidcService}, seguindo a convenção `services/main` do
4
+ * AdonisJS (igual `@adonisjs/lucid/services/db`, `@adonisjs/drive/services/main` e
5
+ * `@adonisjs/lock/services/main`). Permite que um app escreva
6
+ * `import authkit from "@adonis-agora/authkit-server/services/main"` e leia
7
+ * `authkit.config` / chame `authkit.provider` etc., em vez de resolver na mão a
8
+ * binding string-keyed `"authkit.server"` pelo container.
9
+ *
10
+ * Roda `await app.booted()` no top-level, então SÓ funciona dentro de um app
11
+ * booted — por isso `scripts/import-smoke.mjs` pula o diretório `services`.
12
+ *
13
+ * Dentro da própria lib continuamos resolvendo via `ctx.containerResolver.make("authkit.server")`,
14
+ * que é o idioma das libs first-party (ver `@adonisjs/auth`, `initialize_auth_middleware`).
15
+ */
16
+ let service;
17
+ await app.booted(async () => {
18
+ service = await app.container.make("authkit.server");
19
+ });
20
+ export { service as default };
@@ -1,6 +1,7 @@
1
1
  import '../augmentations.js';
2
2
  import type { HttpContext } from '@adonisjs/core/http';
3
3
  export default class AuthInteractionController {
4
+ #private;
4
5
  show(ctx: HttpContext): Promise<any>;
5
6
  /**
6
7
  * POST /auth/interaction/:uid/identifier
@@ -29,6 +29,23 @@ const MFA_PENDING_KEY = 'authkit_mfa_pending';
29
29
  /** Desafio WebAuthn pendente (autenticação) guardado entre begin/finish no login. */
30
30
  const PASSKEY_AUTH_CHALLENGE_KEY = 'authkit_passkey_auth_challenge';
31
31
  export default class AuthInteractionController {
32
+ /**
33
+ * Métodos de login efetivos (com os pins do `cfg.authMethods`) para QUALQUER render do
34
+ * passo login. Sem isto, os re-renders (erro de senha, magic link enviado, lockout…) mandam
35
+ * `authMethods` undefined → a view volta ao default (senha ligada), ignorando a config.
36
+ * `passkeyFirst` depende da conta (resolvido no fluxo principal); aqui cobrimos senha + magic link.
37
+ */
38
+ async #loginMethods(ctx, cfg) {
39
+ const runtimeSettings = await getRuntimeSettings(ctx);
40
+ const magicLinkCapableConfig = cfg.passwordless.magicLink && supportsMagicLink(cfg.accountStore);
41
+ const authMethods = await resolveEffectiveAuthMethods(runtimeSettings, {
42
+ configuredSocialProviders: cfg.social?.providers ?? [],
43
+ magicLinkCapable: magicLinkCapableConfig,
44
+ passkeyCapable: false,
45
+ configOverrides: cfg.authMethods,
46
+ });
47
+ return { authMethods, magicLinkAvailable: authMethods.magicLink && magicLinkCapableConfig };
48
+ }
32
49
  async show(ctx) {
33
50
  const service = await ctx.containerResolver.make('authkit.server');
34
51
  const cfg = service.config;
@@ -177,6 +194,7 @@ export default class AuthInteractionController {
177
194
  ? { fullName: found.name ?? null, globalRoles: found.globalRoles ?? [] }
178
195
  : null;
179
196
  return render(ctx, 'login', {
197
+ ...(await this.#loginMethods(ctx, cfg)),
180
198
  uid: ctx.request.param('uid'),
181
199
  csrfToken: ctx.request.csrfToken,
182
200
  step: 'password',
@@ -214,6 +232,7 @@ export default class AuthInteractionController {
214
232
  ? { fullName: found.name ?? null, globalRoles: found.globalRoles ?? [] }
215
233
  : null;
216
234
  return render(ctx, 'login', {
235
+ ...(await this.#loginMethods(ctx, cfg)),
217
236
  uid: ctx.request.param('uid'),
218
237
  csrfToken: ctx.request.csrfToken,
219
238
  step: 'password',
@@ -596,6 +615,7 @@ export default class AuthInteractionController {
596
615
  }
597
616
  // Resposta uniforme (não vaza existência de conta).
598
617
  return render(ctx, 'login', {
618
+ ...(await this.#loginMethods(ctx, cfg)),
599
619
  uid,
600
620
  csrfToken: ctx.request.csrfToken,
601
621
  step: 'password',
@@ -639,6 +659,7 @@ export default class AuthInteractionController {
639
659
  });
640
660
  const render = cfg.render;
641
661
  return render(ctx, 'login', {
662
+ ...(await this.#loginMethods(ctx, cfg)),
642
663
  uid,
643
664
  csrfToken: ctx.request.csrfToken,
644
665
  step: 'password',
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@adonis-agora/authkit-server",
3
- "version": "0.38.0",
3
+ "version": "0.39.0",
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",
@@ -38,6 +38,7 @@
38
38
  "exports": {
39
39
  ".": "./build/index.js",
40
40
  "./types": "./build/index.js",
41
+ "./services/main": "./build/services/main.js",
41
42
  "./durable": "./build/src/host/durable/index.js",
42
43
  "./telescope": "./build/src/observability/telescope/index.js",
43
44
  "./authkit_server_provider": "./build/providers/authkit_server_provider.js",