@adonis-agora/authkit-client 0.18.5 → 0.18.7

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.
@@ -18,6 +18,15 @@ export function registerOidcClient(router, options = {}) {
18
18
  const prefix = options.prefix ?? '/auth';
19
19
  const passthrough = options.passthroughParams ?? ['audience'];
20
20
  const pkceKey = 'authkit_pkce';
21
+ // Todo redirect desta função vai para uma URL que a PRÓPRIA lib monta (authorize,
22
+ // /login, destino do app, end-session), então nenhum deve encaminhar a query da
23
+ // request atual. Isso precisa ser o builder `withQs(false)`, NÃO o segundo
24
+ // argumento de `redirect(path, forwardQueryString)`: quando o app liga
25
+ // `redirect.forwardQueryString` no config/app.ts — que é o caso comum — o
26
+ // positional é ignorado e o Redirect herda a config global, encaminhando mesmo
27
+ // assim. Sem o opt-out explícito o `code`/`state`/`iss` do callback vazam para o
28
+ // destino (o app termina em `/?code=…`) e o `/auth/login` de um callback falho
29
+ // arrasta o code antigo para o authorize seguinte.
21
30
  const loginRoute = router.get(`${prefix}/login`, async (ctx) => {
22
31
  const manager = await ctx.containerResolver.make('authkit.client');
23
32
  const cfg = manager.clientConfig;
@@ -39,7 +48,7 @@ export function registerOidcClient(router, options = {}) {
39
48
  codeChallenge: challenge,
40
49
  ...(Object.keys(extraParams).length ? { extraParams } : {}),
41
50
  });
42
- return ctx.response.redirect(url);
51
+ return ctx.response.redirect().withQs(false).toPath(url);
43
52
  });
44
53
  if (options.loginMiddleware)
45
54
  loginRoute.use(options.loginMiddleware);
@@ -53,7 +62,7 @@ export function registerOidcClient(router, options = {}) {
53
62
  // Callback velho/expirado (state perdido ou code ausente) → recomeça o login.
54
63
  if (!pkce || pkce.state !== state || !code) {
55
64
  ctx.session?.forget(pkceKey);
56
- return ctx.response.redirect(`${prefix}/login`);
65
+ return ctx.response.redirect().withQs(false).toPath(`${prefix}/login`);
57
66
  }
58
67
  const tokenSet = await exchangeCode({
59
68
  issuer: cfg.issuer,
@@ -72,10 +81,10 @@ export function registerOidcClient(router, options = {}) {
72
81
  // 1) Hook do app tem prioridade quando retorna uma rota.
73
82
  const hook = await options.afterLogin?.(ctx, identity);
74
83
  if (typeof hook === 'string')
75
- return ctx.response.redirect(hook);
84
+ return ctx.response.redirect().withQs(false).toPath(hook);
76
85
  // 2) Redirect por role global (do token).
77
86
  const dest = resolveDestination(identity, options.redirects);
78
- return ctx.response.redirect(dest);
87
+ return ctx.response.redirect().withQs(false).toPath(dest);
79
88
  })
80
89
  .as('auth.callback');
81
90
  router
@@ -95,7 +104,7 @@ export function registerOidcClient(router, options = {}) {
95
104
  postLogoutRedirectUri,
96
105
  clientId: cfg.clientId,
97
106
  });
98
- return ctx.response.redirect(endSessionUrl);
107
+ return ctx.response.redirect().withQs(false).toPath(endSessionUrl);
99
108
  })
100
109
  .as('auth.logout');
101
110
  if (options.backchannelLogout !== false) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@adonis-agora/authkit-client",
3
- "version": "0.18.5",
3
+ "version": "0.18.7",
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",
@@ -83,7 +83,7 @@
83
83
  "jose": "6.2.12"
84
84
  },
85
85
  "devDependencies": {
86
- "@adonis-agora/authkit-server": "0.68.0",
86
+ "@adonis-agora/authkit-server": "0.68.2",
87
87
  "@adonis-agora/resilience": "0.3.7",
88
88
  "@adonisjs/auth": "10.1.0",
89
89
  "@adonisjs/core": "7.5.0",