@adonis-agora/authkit-client 0.18.9 → 0.19.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/build/commands/configure.js +6 -0
- package/build/index.d.ts +9 -3
- package/build/index.js +5 -2
- package/build/providers/authkit_client_provider.d.ts +57 -9
- package/build/providers/authkit_client_provider.js +173 -34
- package/build/src/authorization.d.ts +125 -0
- package/build/src/authorization.js +142 -0
- package/build/src/backchannel_logout.d.ts +1 -1
- package/build/src/backchannel_logout.js +3 -15
- package/build/src/define_config.d.ts +24 -0
- package/build/src/define_config.js +6 -0
- package/build/src/discovery.d.ts +52 -20
- package/build/src/discovery.js +104 -42
- package/build/src/id_token.d.ts +57 -0
- package/build/src/id_token.js +61 -0
- package/build/src/jwks.d.ts +15 -0
- package/build/src/jwks.js +36 -0
- package/build/src/oidc_login.d.ts +7 -1
- package/build/src/oidc_login.js +31 -2
- package/build/src/register_oidc_client.js +30 -31
- package/build/src/resolvers/factory.d.ts +9 -2
- package/build/src/resolvers/factory.js +37 -5
- package/build/src/resolvers/jwt_resolver.d.ts +7 -3
- package/build/src/resolvers/jwt_resolver.js +8 -17
- package/build/src/resolvers/opaque_resolver.d.ts +5 -2
- package/build/src/resolvers/opaque_resolver.js +4 -1
- package/build/src/verify_access_token.d.ts +0 -2
- package/build/src/verify_access_token.js +2 -27
- package/build/stubs/controllers/oidc_session_controller.stub +31 -26
- package/package.json +7 -6
- package/skills/authkit-rp-client/SKILL.md +11 -6
- package/stubs/controllers/oidc_session_controller.stub +31 -26
|
@@ -1,42 +1,47 @@
|
|
|
1
1
|
{{{
|
|
2
2
|
exports({ to: app.makePath('app/controllers/oidc_session_controller.ts') })
|
|
3
3
|
}}}
|
|
4
|
+
import { inject } from '@adonisjs/core'
|
|
4
5
|
import type { HttpContext } from '@adonisjs/core/http'
|
|
5
|
-
import {
|
|
6
|
-
import { randomUUID } from 'node:crypto'
|
|
6
|
+
import { AuthkitClientManager, OidcCallbackError } from '@adonis-agora/authkit-client'
|
|
7
7
|
|
|
8
|
+
/**
|
|
9
|
+
* Login, callback and logout written out by hand. If you do not need to customise
|
|
10
|
+
* them, registerOidcClient(router) registers the same three routes for you.
|
|
11
|
+
*/
|
|
12
|
+
@inject()
|
|
8
13
|
export default class OidcSessionController {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
const
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
issuer: cfg.issuer, clientId: cfg.clientId, redirectUri: cfg.redirectUri,
|
|
17
|
-
scopes: cfg.scopes, state, codeChallenge: challenge,
|
|
18
|
-
})
|
|
19
|
-
return ctx.response.redirect(url)
|
|
14
|
+
constructor(protected authkit: AuthkitClientManager) {}
|
|
15
|
+
|
|
16
|
+
async login({ session, response }: HttpContext) {
|
|
17
|
+
// Fresh state + nonce + PKCE, against the endpoints discovered from the issuer.
|
|
18
|
+
const { url, pending } = await this.authkit.createAuthorizationRequest()
|
|
19
|
+
session.put('authkit_pkce', pending)
|
|
20
|
+
return response.redirect(url)
|
|
20
21
|
}
|
|
21
22
|
|
|
22
23
|
async callback(ctx: HttpContext) {
|
|
23
|
-
const
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
24
|
+
const pending = ctx.session.pull('authkit_pkce')
|
|
25
|
+
try {
|
|
26
|
+
// Checks state and iss, exchanges the code and validates the id_token (nonce included).
|
|
27
|
+
const { tokens: tokenSet } = await this.authkit.completeAuthorization({
|
|
28
|
+
pending,
|
|
29
|
+
callbackParams: ctx.request.qs(),
|
|
30
|
+
})
|
|
31
|
+
// startSession (not session.put) drops any impersonation parked by a previous session.
|
|
32
|
+
this.authkit.startSession(ctx, tokenSet)
|
|
33
|
+
} catch (error) {
|
|
34
|
+
// Stale callback, or the IdP sent the user back with an error (access_denied…).
|
|
35
|
+
if (error instanceof OidcCallbackError && error.restartable) {
|
|
36
|
+
return ctx.response.redirect('/auth/login')
|
|
37
|
+
}
|
|
38
|
+
throw error
|
|
39
|
+
}
|
|
34
40
|
return ctx.response.redirect('/')
|
|
35
41
|
}
|
|
36
42
|
|
|
37
43
|
async logout(ctx: HttpContext) {
|
|
38
|
-
|
|
39
|
-
manager.endSession(ctx)
|
|
44
|
+
this.authkit.endSession(ctx)
|
|
40
45
|
return ctx.response.redirect('/')
|
|
41
46
|
}
|
|
42
47
|
}
|