@julr/sesame 0.2.0 → 0.2.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.
Files changed (38) hide show
  1. package/README.md +167 -86
  2. package/build/{authorize_controller-D3Kau97j.js → authorize_controller-BNWhlPZQ.js} +8 -7
  3. package/build/{client_info_controller-CSipLLoV.js → client_info_controller-BucHGx4u.js} +2 -2
  4. package/build/{client_service-DrkqOh37.js → client_service-BqPSlaTS.js} +1 -1
  5. package/build/commands/sesame_purge.js +1 -1
  6. package/build/configure.js +7 -0
  7. package/build/{consent_controller-DXayMjAi.js → consent_controller-COvvkpHM.js} +6 -5
  8. package/build/index.d.ts +1 -2
  9. package/build/index.js +6 -7
  10. package/build/{introspect_controller-lK9gL03t.js → introspect_controller-JjAAXFIV.js} +5 -5
  11. package/build/{metadata_controller-DMAahJkn.js → metadata_controller-BzCjyqUG.js} +28 -6
  12. package/build/{oauth_error-BOn0846g.js → oauth_error-CnJ3L8tf.js} +17 -1
  13. package/build/providers/sesame_provider.d.ts +0 -8
  14. package/build/providers/sesame_provider.js +1 -6
  15. package/build/{register_controller-B0saLAuc.js → register_controller-DOlN9wNl.js} +4 -4
  16. package/build/{revoke_controller-D0nl2hS5.js → revoke_controller-B281b8ZO.js} +5 -5
  17. package/build/{sesame_manager-CA7dOGwg.js → sesame_manager-CFq4VEIZ.js} +53 -11
  18. package/build/src/controllers/authorize_controller.d.ts +3 -3
  19. package/build/src/controllers/metadata_controller.d.ts +1 -0
  20. package/build/src/define_config.d.ts +6 -1
  21. package/build/src/guard/guard.d.ts +4 -3
  22. package/build/src/guard/main.js +4 -4
  23. package/build/src/middleware/any_scope_middleware.d.ts +15 -0
  24. package/build/src/middleware/any_scope_middleware.js +18 -0
  25. package/build/src/middleware/scope_middleware.d.ts +15 -0
  26. package/build/src/middleware/scope_middleware.js +18 -0
  27. package/build/src/oauth_error.d.ts +32 -0
  28. package/build/src/routes.d.ts +21 -20
  29. package/build/src/sesame_manager.d.ts +38 -8
  30. package/build/src/types.d.ts +27 -0
  31. package/build/stubs/config/sesame.stub +5 -0
  32. package/build/{token_controller-CDFuzY6S.js → token_controller-ll9sjcvn.js} +10 -9
  33. package/build/{token_service-BLKxKIHI.js → token_service-fhoA4slP.js} +2 -1
  34. package/build/{user_provider-CQczt8_g.js → user_provider-DXAOfv8-.js} +2 -2
  35. package/package.json +7 -2
  36. package/build/rolldown-runtime-BASaM9lw.js +0 -12
  37. package/build/routes-qYJLHjeB.js +0 -43
  38. /package/build/{oauth_client-Cpppi0_7.js → oauth_client-BIoY5jBR.js} +0 -0
package/README.md CHANGED
@@ -1,130 +1,211 @@
1
- # AdonisJS package starter kit
1
+ # Sésame
2
2
 
3
- > [!note]
4
- > This starter kit targets **AdonisJS v7**
3
+ > OAuth 2.1 + OIDC server for AdonisJS
5
4
 
6
- > A boilerplate for creating AdonisJS packages
5
+ Sésame is an AdonisJS package that turns your application into a full-featured OAuth 2.1 authorization server. It implements the core OAuth 2.1 specification along with OIDC discovery, token introspection, dynamic client registration, and MCP (Model Context Protocol) support.
7
6
 
8
- This repo provides you with a starting point for creating AdonisJS packages. Of course, you can create a package from scratch with your folder structure and workflow. However, using this starter kit can speed up the process, as you have fewer decisions to make.
7
+ ## Features
9
8
 
10
- ## Setup
9
+ - **Authorization Code Grant** with PKCE (S256)
10
+ - **Refresh Token Rotation** with replay detection
11
+ - **Token Introspection** (RFC 7662) and **Revocation** (RFC 7009)
12
+ - **Dynamic Client Registration** (RFC 7591)
13
+ - **OIDC Discovery** (`/.well-known/openid-configuration`)
14
+ - **OAuth Server Metadata** (RFC 8414)
15
+ - **Protected Resource Metadata** (RFC 9728) for MCP servers
16
+ - **Type-safe scopes** via module augmentation
17
+ - **OAuth guard** for `@adonisjs/auth` with scope-checking middleware
18
+ - **Token cleanup** via `sesame:purge` Ace command
11
19
 
12
- - Clone the repo on your computer, or use `giget` to download this repo without the Git history.
13
- ```sh
14
- npx giget@latest gh:adonisjs/pkg-starter-kit
15
- ```
16
- - Install dependencies.
17
- - Update the `package.json` file and define the `name`, `description`, `keywords`, and `author` properties.
18
- - The repo is configured with an MIT license. Feel free to change that if you are not publishing under the MIT license.
20
+ ## Installation
19
21
 
20
- ## Folder structure
22
+ ```bash
23
+ node ace add @julr/sesame
24
+ ```
21
25
 
22
- The starter kit mimics the folder structure of the official packages. Feel free to rename files and folders as per your requirements.
26
+ This will:
27
+ - Publish the configuration file to `config/sesame.ts`
28
+ - Publish database migrations (6 tables)
29
+ - Register the service provider and commands
23
30
 
24
- ```
25
- ├── providers
26
- ├── src
27
- ├── bin
28
- ├── stubs
29
- ├── configure.ts
30
- ├── index.ts
31
- ├── LICENSE.md
32
- ├── package.json
33
- ├── README.md
34
- ├── tsconfig.json
35
- ├── tsnode.esm.js
31
+ Then run the migrations:
32
+
33
+ ```bash
34
+ node ace migration:run
36
35
  ```
37
36
 
38
- - The `configure.ts` file exports the `configure` hook to configure the package using the `node ace configure` command.
39
- - The `index.ts` file is the main entry point of the package.
40
- - The `tsnode.esm.js` file runs TypeScript code using TS-Node + SWC. Please read the code comment in this file to learn more.
41
- - The `bin` directory contains the entry point file to run Japa tests.
42
- - Learn more about [the `providers` directory](./providers/README.md).
43
- - Learn more about [the `src` directory](./src/README.md).
44
- - Learn more about [the `stubs` directory](./stubs/README.md).
37
+ ## Configuration
45
38
 
46
- ### File system naming convention
39
+ The configuration file lives at `config/sesame.ts`:
47
40
 
48
- We use `snake_case` naming conventions for the file system. The rule is enforced using ESLint. However, turn off the rule and use your preferred naming conventions.
41
+ ```ts
42
+ import env from '#start/env'
43
+ import { defineConfig } from '@julr/sesame'
44
+ import type { InferScopes } from '@julr/sesame/types'
49
45
 
50
- ## Peer dependencies
46
+ const sesameConfig = defineConfig({
47
+ issuer: env.get('APP_URL'),
51
48
 
52
- The starter kit has a peer dependency on `@adonisjs/core@6`. Since you are creating a package for AdonisJS, you must make it against a specific version of the framework core.
49
+ scopes: {
50
+ 'read': 'Read access',
51
+ 'write': 'Write access',
52
+ },
53
53
 
54
- If your package needs Lucid to be functional, you may install `@adonisjs/lucid` as a development dependency and add it to the list of `peerDependencies`.
54
+ defaultScopes: ['read'],
55
55
 
56
- As a rule of thumb, packages installed in the user application should be part of the `peerDependencies` of your package and not the main dependency.
56
+ grantTypes: ['authorization_code', 'refresh_token'],
57
57
 
58
- For example, if you install `@adonisjs/core` as a main dependency, then essentially, you are importing a separate copy of `@adonisjs/core` and not sharing the one from the user application. Here is a great article explaining [peer dependencies](https://blog.bitsrc.io/understanding-peer-dependencies-in-javascript-dbdb4ab5a7be).
58
+ accessTokenTtl: '1h',
59
+ refreshTokenTtl: '30d',
60
+ authorizationCodeTtl: '10m',
59
61
 
60
- ## Published files
62
+ loginPage: '/login',
63
+ consentPage: '/oauth/consent',
61
64
 
62
- Instead of publishing your repo's source code to npm, you must cherry-pick files and folders to publish only the required files.
65
+ allowDynamicRegistration: false,
66
+ allowPublicRegistration: false,
67
+ })
63
68
 
64
- The cherry-picking uses the `files` property inside the `package.json` file. By default, we publish the following files and folders.
69
+ export default sesameConfig
65
70
 
66
- ```json
67
- {
68
- "files": [
69
- "build/src",
70
- "build/providers",
71
- "build/stubs",
72
- "build/index.d.ts",
73
- "build/index.js",
74
- "build/configure.d.ts",
75
- "build/configure.js"
76
- ]
71
+ declare module '@julr/sesame/types' {
72
+ interface SesameScopes extends InferScopes<typeof sesameConfig> {}
77
73
  }
78
74
  ```
79
75
 
80
- If you create additional folders or files, mention them inside the `files` array.
76
+ The `SesameScopes` augmentation gives you type-safe scope names throughout your application.
77
+
78
+ ## Routes
79
+
80
+ Register OAuth routes from your `start/routes.ts` file:
81
+
82
+ ```ts
83
+ import { SesameManager } from '@julr/sesame'
84
+
85
+ const sesame = await app.container.make(SesameManager)
86
+
87
+ // OAuth endpoints under /oauth
88
+ router.group(() => {
89
+ sesame.registerRoutes(router)
90
+ }).prefix('/oauth')
91
+
92
+ // Discovery endpoints at the root
93
+ sesame.registerWellKnownRoutes(router)
94
+ ```
95
+
96
+ This registers the following endpoints:
97
+
98
+ | Method | Path | Description |
99
+ | ------ | ----------------------------------------- | -------------------------------------- |
100
+ | `POST` | `/oauth/token` | Token endpoint |
101
+ | `GET` | `/oauth/authorize` | Authorization endpoint |
102
+ | `POST` | `/oauth/consent` | Consent submission |
103
+ | `POST` | `/oauth/introspect` | Token introspection (RFC 7662) |
104
+ | `POST` | `/oauth/revoke` | Token revocation (RFC 7009) |
105
+ | `POST` | `/oauth/register` | Dynamic client registration (RFC 7591) |
106
+ | `GET` | `/oauth/client-info` | Public client info |
107
+ | `GET` | `/.well-known/oauth-authorization-server` | Server metadata (RFC 8414) |
108
+ | `GET` | `/.well-known/openid-configuration` | OIDC discovery |
109
+
110
+ ## Authentication Guard
111
+
112
+ Sésame provides an OAuth guard for `@adonisjs/auth`. Configure it in `config/auth.ts`:
113
+
114
+ ```ts
115
+ import { oauthGuard, oauthUserProvider } from '@julr/sesame/guard'
116
+ import User from '#models/user'
117
+
118
+ const authConfig = defineConfig({
119
+ default: 'web',
120
+ guards: {
121
+ // ...your other guards
122
+ oauth: oauthGuard({
123
+ provider: oauthUserProvider({ model: () => import('#models/user') }),
124
+ }),
125
+ },
126
+ })
127
+ ```
81
128
 
82
- ## Exports
129
+ Then use it in your controllers:
83
130
 
84
- [Node.js Subpath exports](https://nodejs.org/api/packages.html#subpath-exports) allows you to define the exports of your package regardless of the folder structure. This starter kit defines the following exports.
131
+ ```ts
132
+ export default class ApiController {
133
+ async index({ auth }: HttpContext) {
134
+ const guard = auth.use('oauth')
135
+ await guard.authenticate()
85
136
 
86
- ```json
87
- {
88
- "exports": {
89
- ".": "./build/index.js",
90
- "./types": "./build/src/types.js"
137
+ const user = auth.user!
138
+ const scopes = guard.scopes
91
139
  }
92
140
  }
93
141
  ```
94
142
 
95
- - The dot `.` export is the main export.
96
- - The `./types` exports all the types defined inside the `./build/src/types.js` file (the compiled output).
143
+ ## Scope Middleware
144
+
145
+ Two named middleware are available for checking scopes on authenticated requests:
146
+
147
+ ```ts
148
+ // Requires ALL listed scopes
149
+ router
150
+ .get('/admin', [AdminController])
151
+ .use(middleware.scopes({ scopes: ['admin', 'write'] }))
97
152
 
98
- Feel free to change the exports as per your requirements.
153
+ // Requires AT LEAST ONE of the listed scopes
154
+ router
155
+ .get('/data', [DataController])
156
+ .use(middleware.anyScope({ scopes: ['read', 'write'] }))
157
+ ```
99
158
 
100
- ## Testing
159
+ ## MCP Support
101
160
 
102
- We configure the [Japa test runner](https://japa.dev/) with this starter kit. Japa is used in AdonisJS applications as well. Just run one of the following commands to execute tests.
161
+ For MCP (Model Context Protocol) servers, register per-resource discovery:
103
162
 
104
- - `npm run test`: This command will first lint the code using ESlint and then run tests and report the test coverage using [c8](https://github.com/bcoe/c8).
105
- - `npm run quick:test`: Runs only the tests without linting or coverage reporting.
163
+ ```ts
164
+ sesame.registerProtectedResource(router, {
165
+ resource: '/api/mcp',
166
+ scopes: ['read:mcp'],
167
+ })
168
+ ```
106
169
 
107
- The starter kit also has a Github workflow file to run tests using Github Actions. The tests are executed against `Node.js 20.x` and `Node.js 21.x` versions on both Linux and Windows. Feel free to edit the workflow file in the `.github/workflows` directory.
170
+ This creates a `/.well-known/oauth-protected-resource/api/mcp` endpoint following RFC 9728.
108
171
 
109
- ## TypeScript workflow
172
+ You can also enable public client registration for MCP clients:
110
173
 
111
- - The starter kit uses [tsc](https://www.typescriptlang.org/docs/handbook/compiler-options.html) for compiling the TypeScript to JavaScript when publishing the package.
112
- - [TS-Node](https://typestrong.org/ts-node/) and [SWC](https://swc.rs/) are used to run tests without compiling the source code.
113
- - The `tsconfig.json` file is extended from [`@adonisjs/tsconfig`](https://github.com/adonisjs/tooling-config/tree/main/packages/typescript-config) and uses the `NodeNext` module system. Meaning the packages are written using ES modules.
114
- - You can perform type checking without compiling the source code using the `npm run type check` script.
174
+ ```ts
175
+ const sesameConfig = defineConfig({
176
+ // ...
177
+ allowDynamicRegistration: true,
178
+ allowPublicRegistration: true,
179
+ })
180
+ ```
115
181
 
116
- Feel free to explore the `tsconfig.json` file for all the configured options.
182
+ ## Token Cleanup
117
183
 
118
- ## ESLint and Prettier setup
184
+ Purge expired and revoked tokens with the Ace command:
185
+
186
+ ```bash
187
+ node ace sesame:purge
188
+ node ace sesame:purge --revoked-only
189
+ node ace sesame:purge --expired-only
190
+ node ace sesame:purge --retention-hours=168
191
+ ```
192
+
193
+ You can also call it programmatically:
194
+
195
+ ```ts
196
+ const sesame = await app.container.make(SesameManager)
197
+ const result = await sesame.purgeTokens({ retentionHours: 168 })
198
+ ```
119
199
 
120
- The starter kit configures ESLint and Prettier
121
- using our [shared config](https://github.com/adonisjs/tooling-config/tree/main/packages).
122
- ESLint configuration is stored within the `eslint.config.js` file.
123
- Prettier configuration is stored within the `package.json` file.
124
- Feel free to change the configuration, use custom plugins, or remove both tools altogether.
200
+ ## Security
125
201
 
126
- ## Using Stale bot
202
+ - Tokens (access, refresh, authorization codes, client secrets) are stored as **SHA-256 hashes** — raw values are never persisted
203
+ - PKCE with **S256** is required for public clients
204
+ - Refresh tokens use **rotation** — the old token is revoked on each use
205
+ - **Replay detection**: if a revoked refresh token is reused, all tokens for that client+user pair are revoked
206
+ - Client secret verification uses **timing-safe comparison**
207
+ - OAuth errors follow the standard JSON format with proper HTTP status codes and `WWW-Authenticate` headers
127
208
 
128
- The [Stale bot](https://github.com/apps/stale) is a Github application that automatically marks issues and PRs as stale and closes after a specific duration of inactivity.
209
+ ## License
129
210
 
130
- Feel free to delete the `.github/stale.yml` and `.github/lock.yml` files if you decide not to use the Stale bot.
211
+ MIT
@@ -1,11 +1,12 @@
1
+ import { a as OAuthAuthorizationCode, i as OAuthConsent, r as OAuthPendingAuthorizationRequest, t as SesameManager } from "./sesame_manager-CFq4VEIZ.js";
1
2
  import "./decorate-BKZEjPRg.js";
2
3
  import "./oauth_access_token-bsoM5KeU.js";
3
- import { a as OAuthAuthorizationCode, i as OAuthConsent, r as OAuthPendingAuthorizationRequest, t as SesameManager } from "./sesame_manager-CA7dOGwg.js";
4
- import { a as E_INVALID_REQUEST, n as E_INVALID_CLIENT, u as E_UNSUPPORTED_RESPONSE_TYPE } from "./oauth_error-BOn0846g.js";
5
- import { t as OAuthClient } from "./oauth_client-Cpppi0_7.js";
6
- import { t as TokenService } from "./token_service-BLKxKIHI.js";
7
- import { t as ClientService } from "./client_service-DrkqOh37.js";
4
+ import { d as E_UNSUPPORTED_RESPONSE_TYPE, o as E_INVALID_REQUEST, r as E_INVALID_CLIENT } from "./oauth_error-CnJ3L8tf.js";
5
+ import { t as OAuthClient } from "./oauth_client-BIoY5jBR.js";
6
+ import { t as TokenService } from "./token_service-fhoA4slP.js";
7
+ import { t as ClientService } from "./client_service-BqPSlaTS.js";
8
8
  import { DateTime } from "luxon";
9
+ import string from "@adonisjs/core/helpers/string";
9
10
  import vine from "@vinejs/vine";
10
11
  var AuthorizeController = class AuthorizeController {
11
12
  static validator = vine.create({
@@ -28,7 +29,7 @@ var AuthorizeController = class AuthorizeController {
28
29
  async #buildAuthorizationRequestParams(manager, options) {
29
30
  const tokenService = new TokenService(manager);
30
31
  const rawRequestToken = tokenService.generateOpaqueToken();
31
- const ttl = manager.parseTtl(manager.config.authorizationRequestTtl);
32
+ const ttl = string.seconds.parse(manager.config.authorizationRequestTtl);
32
33
  await OAuthPendingAuthorizationRequest.create({
33
34
  id: crypto.randomUUID(),
34
35
  token: tokenService.hashToken(rawRequestToken),
@@ -59,7 +60,7 @@ var AuthorizeController = class AuthorizeController {
59
60
  const tokenService = new TokenService(manager);
60
61
  const raw = tokenService.generateOpaqueToken();
61
62
  const hashed = tokenService.hashToken(raw);
62
- const ttl = manager.parseTtl(manager.config.authorizationCodeTtl);
63
+ const ttl = string.seconds.parse(manager.config.authorizationCodeTtl);
63
64
  await OAuthAuthorizationCode.create({
64
65
  id: crypto.randomUUID(),
65
66
  code: hashed,
@@ -1,6 +1,6 @@
1
1
  import "./decorate-BKZEjPRg.js";
2
- import { a as E_INVALID_REQUEST, n as E_INVALID_CLIENT } from "./oauth_error-BOn0846g.js";
3
- import { t as OAuthClient } from "./oauth_client-Cpppi0_7.js";
2
+ import { o as E_INVALID_REQUEST, r as E_INVALID_CLIENT } from "./oauth_error-CnJ3L8tf.js";
3
+ import { t as OAuthClient } from "./oauth_client-BIoY5jBR.js";
4
4
  import vine from "@vinejs/vine";
5
5
  var ClientInfoController = class ClientInfoController {
6
6
  static validator = vine.create({ client_id: vine.string() });
@@ -1,4 +1,4 @@
1
- import { o as E_INVALID_SCOPE } from "./oauth_error-BOn0846g.js";
1
+ import { s as E_INVALID_SCOPE } from "./oauth_error-CnJ3L8tf.js";
2
2
  import { createHash, randomBytes, timingSafeEqual } from "node:crypto";
3
3
  var ClientService = class {
4
4
  parseBasicAuth(header) {
@@ -1,6 +1,6 @@
1
+ import { t as SesameManager } from "../sesame_manager-CFq4VEIZ.js";
1
2
  import { t as __decorate } from "../decorate-BKZEjPRg.js";
2
3
  import "../oauth_access_token-bsoM5KeU.js";
3
- import { t as SesameManager } from "../sesame_manager-CA7dOGwg.js";
4
4
  import { BaseCommand, flags } from "@adonisjs/core/ace";
5
5
  var SesamePurge = class extends BaseCommand {
6
6
  static commandName = "sesame:purge";
@@ -14,5 +14,12 @@ async function configure(command) {
14
14
  await codemods.updateRcFile((rcFile) => {
15
15
  rcFile.addProvider("@julr/sesame/sesame_provider").addCommand("@julr/sesame/commands");
16
16
  });
17
+ await codemods.registerMiddleware("named", [{
18
+ name: "scopes",
19
+ path: "@julr/sesame/scope_middleware"
20
+ }, {
21
+ name: "anyScope",
22
+ path: "@julr/sesame/any_scope_middleware"
23
+ }]);
17
24
  }
18
25
  export { configure };
@@ -1,10 +1,11 @@
1
+ import { a as OAuthAuthorizationCode, i as OAuthConsent, r as OAuthPendingAuthorizationRequest, t as SesameManager } from "./sesame_manager-CFq4VEIZ.js";
1
2
  import "./decorate-BKZEjPRg.js";
2
3
  import "./oauth_access_token-bsoM5KeU.js";
3
- import { a as OAuthAuthorizationCode, i as OAuthConsent, r as OAuthPendingAuthorizationRequest, t as SesameManager } from "./sesame_manager-CA7dOGwg.js";
4
- import { a as E_INVALID_REQUEST, i as E_INVALID_GRANT, n as E_INVALID_CLIENT } from "./oauth_error-BOn0846g.js";
5
- import { t as OAuthClient } from "./oauth_client-Cpppi0_7.js";
6
- import { t as TokenService } from "./token_service-BLKxKIHI.js";
4
+ import { a as E_INVALID_GRANT, o as E_INVALID_REQUEST, r as E_INVALID_CLIENT } from "./oauth_error-CnJ3L8tf.js";
5
+ import { t as OAuthClient } from "./oauth_client-BIoY5jBR.js";
6
+ import { t as TokenService } from "./token_service-fhoA4slP.js";
7
7
  import { DateTime } from "luxon";
8
+ import string from "@adonisjs/core/helpers/string";
8
9
  import vine from "@vinejs/vine";
9
10
  var ConsentController = class ConsentController {
10
11
  static validator = vine.create({ auth_token: vine.string() });
@@ -19,7 +20,7 @@ var ConsentController = class ConsentController {
19
20
  const tokenService = new TokenService(manager);
20
21
  const raw = tokenService.generateOpaqueToken();
21
22
  const hashed = tokenService.hashToken(raw);
22
- const ttl = manager.parseTtl(manager.config.authorizationCodeTtl);
23
+ const ttl = string.seconds.parse(manager.config.authorizationCodeTtl);
23
24
  await OAuthAuthorizationCode.create({
24
25
  id: crypto.randomUUID(),
25
26
  code: hashed,
package/build/index.d.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  export { configure } from './configure.ts';
2
2
  export { defineConfig } from './src/define_config.ts';
3
3
  export { SesameManager } from './src/sesame_manager.ts';
4
- export { OAuthError, E_INVALID_REQUEST, E_INVALID_CLIENT, E_INVALID_GRANT, E_INVALID_SCOPE, E_INVALID_TOKEN, E_UNSUPPORTED_GRANT_TYPE, E_UNSUPPORTED_RESPONSE_TYPE, E_ACCESS_DENIED, E_INVALID_CLIENT_METADATA, E_SERVER_ERROR, } from './src/oauth_error.ts';
4
+ export { OAuthError, E_INVALID_REQUEST, E_INVALID_CLIENT, E_INVALID_GRANT, E_INVALID_SCOPE, E_INVALID_TOKEN, E_UNSUPPORTED_GRANT_TYPE, E_UNSUPPORTED_RESPONSE_TYPE, E_ACCESS_DENIED, E_INVALID_CLIENT_METADATA, E_SERVER_ERROR, E_INSUFFICIENT_SCOPE, } from './src/oauth_error.ts';
5
5
  export { OAuthClient } from './src/models/oauth_client.ts';
6
6
  export { OAuthAccessToken } from './src/models/oauth_access_token.ts';
7
7
  export { OAuthRefreshToken } from './src/models/oauth_refresh_token.ts';
@@ -10,4 +10,3 @@ export { OAuthConsent } from './src/models/oauth_consent.ts';
10
10
  export { OAuthGuard } from './src/guard/guard.ts';
11
11
  export { OAuthLucidUserProvider } from './src/guard/user_provider.ts';
12
12
  export { oauthGuard, oauthUserProvider } from './src/guard/main.ts';
13
- export { registerRoutes, registerProtectedResource } from './src/routes.ts';
package/build/index.js CHANGED
@@ -1,13 +1,12 @@
1
+ import { a as OAuthAuthorizationCode, i as OAuthConsent, o as OAuthRefreshToken, t as SesameManager } from "./sesame_manager-CFq4VEIZ.js";
1
2
  import { configure } from "./configure.js";
2
3
  import "./decorate-BKZEjPRg.js";
3
4
  import { t as OAuthAccessToken } from "./oauth_access_token-bsoM5KeU.js";
4
- import { a as OAuthAuthorizationCode, i as OAuthConsent, o as OAuthRefreshToken, t as SesameManager } from "./sesame_manager-CA7dOGwg.js";
5
- import { a as E_INVALID_REQUEST, c as E_SERVER_ERROR, d as OAuthError, i as E_INVALID_GRANT, l as E_UNSUPPORTED_GRANT_TYPE, n as E_INVALID_CLIENT, o as E_INVALID_SCOPE, r as E_INVALID_CLIENT_METADATA, s as E_INVALID_TOKEN, t as E_ACCESS_DENIED, u as E_UNSUPPORTED_RESPONSE_TYPE } from "./oauth_error-BOn0846g.js";
6
- import { t as OAuthClient } from "./oauth_client-Cpppi0_7.js";
7
- import "./token_service-BLKxKIHI.js";
8
- import { n as OAuthGuard, t as OAuthLucidUserProvider } from "./user_provider-CQczt8_g.js";
5
+ import { a as E_INVALID_GRANT, c as E_INVALID_TOKEN, d as E_UNSUPPORTED_RESPONSE_TYPE, f as OAuthError, i as E_INVALID_CLIENT_METADATA, l as E_SERVER_ERROR, n as E_INSUFFICIENT_SCOPE, o as E_INVALID_REQUEST, r as E_INVALID_CLIENT, s as E_INVALID_SCOPE, t as E_ACCESS_DENIED, u as E_UNSUPPORTED_GRANT_TYPE } from "./oauth_error-CnJ3L8tf.js";
6
+ import { t as OAuthClient } from "./oauth_client-BIoY5jBR.js";
7
+ import "./token_service-fhoA4slP.js";
8
+ import { n as OAuthGuard, t as OAuthLucidUserProvider } from "./user_provider-DXAOfv8-.js";
9
9
  import { oauthGuard, oauthUserProvider } from "./src/guard/main.js";
10
- import { n as registerRoutes, t as registerProtectedResource } from "./routes-qYJLHjeB.js";
11
10
  function defineConfig(config) {
12
11
  return {
13
12
  issuer: config.issuer,
@@ -24,4 +23,4 @@ function defineConfig(config) {
24
23
  allowPublicRegistration: config.allowPublicRegistration ?? false
25
24
  };
26
25
  }
27
- export { E_ACCESS_DENIED, E_INVALID_CLIENT, E_INVALID_CLIENT_METADATA, E_INVALID_GRANT, E_INVALID_REQUEST, E_INVALID_SCOPE, E_INVALID_TOKEN, E_SERVER_ERROR, E_UNSUPPORTED_GRANT_TYPE, E_UNSUPPORTED_RESPONSE_TYPE, OAuthAccessToken, OAuthAuthorizationCode, OAuthClient, OAuthConsent, OAuthError, OAuthGuard, OAuthLucidUserProvider, OAuthRefreshToken, SesameManager, configure, defineConfig, oauthGuard, oauthUserProvider, registerProtectedResource, registerRoutes };
26
+ export { E_ACCESS_DENIED, E_INSUFFICIENT_SCOPE, E_INVALID_CLIENT, E_INVALID_CLIENT_METADATA, E_INVALID_GRANT, E_INVALID_REQUEST, E_INVALID_SCOPE, E_INVALID_TOKEN, E_SERVER_ERROR, E_UNSUPPORTED_GRANT_TYPE, E_UNSUPPORTED_RESPONSE_TYPE, OAuthAccessToken, OAuthAuthorizationCode, OAuthClient, OAuthConsent, OAuthError, OAuthGuard, OAuthLucidUserProvider, OAuthRefreshToken, SesameManager, configure, defineConfig, oauthGuard, oauthUserProvider };
@@ -1,10 +1,10 @@
1
+ import { o as OAuthRefreshToken, t as SesameManager } from "./sesame_manager-CFq4VEIZ.js";
1
2
  import "./decorate-BKZEjPRg.js";
2
3
  import { t as OAuthAccessToken } from "./oauth_access_token-bsoM5KeU.js";
3
- import { o as OAuthRefreshToken, t as SesameManager } from "./sesame_manager-CA7dOGwg.js";
4
- import { n as E_INVALID_CLIENT } from "./oauth_error-BOn0846g.js";
5
- import { t as OAuthClient } from "./oauth_client-Cpppi0_7.js";
6
- import { t as TokenService } from "./token_service-BLKxKIHI.js";
7
- import { t as ClientService } from "./client_service-DrkqOh37.js";
4
+ import { r as E_INVALID_CLIENT } from "./oauth_error-CnJ3L8tf.js";
5
+ import { t as OAuthClient } from "./oauth_client-BIoY5jBR.js";
6
+ import { t as TokenService } from "./token_service-fhoA4slP.js";
7
+ import { t as ClientService } from "./client_service-BqPSlaTS.js";
8
8
  const INACTIVE = { active: false };
9
9
  var IntrospectController = class {
10
10
  async handle(ctx) {
@@ -1,18 +1,40 @@
1
+ import { t as SesameManager } from "./sesame_manager-CFq4VEIZ.js";
1
2
  import "./decorate-BKZEjPRg.js";
2
3
  import "./oauth_access_token-bsoM5KeU.js";
3
- import { t as SesameManager } from "./sesame_manager-CA7dOGwg.js";
4
+ import { l as E_SERVER_ERROR } from "./oauth_error-CnJ3L8tf.js";
5
+ const DISCOVERY_ROUTE_NAMES = {
6
+ authorization_endpoint: "sesame.authorize",
7
+ token_endpoint: "sesame.token",
8
+ registration_endpoint: "sesame.register",
9
+ introspection_endpoint: "sesame.introspect",
10
+ revocation_endpoint: "sesame.revoke"
11
+ };
4
12
  var MetadataController = class {
13
+ #assertDiscoveryRoutes(router, options) {
14
+ const requiredRoutes = [
15
+ DISCOVERY_ROUTE_NAMES.authorization_endpoint,
16
+ DISCOVERY_ROUTE_NAMES.token_endpoint,
17
+ DISCOVERY_ROUTE_NAMES.introspection_endpoint,
18
+ DISCOVERY_ROUTE_NAMES.revocation_endpoint
19
+ ];
20
+ if (options.includeRegistration) requiredRoutes.push(DISCOVERY_ROUTE_NAMES.registration_endpoint);
21
+ const missingRoutes = requiredRoutes.filter((routeName) => !router.has(routeName));
22
+ if (missingRoutes.length > 0) throw new E_SERVER_ERROR(`OAuth discovery is misconfigured. Missing named route(s): ${missingRoutes.join(", ")}. Register OAuth routes with sesame.registerRoutes(router) before exposing well-known metadata.`);
23
+ }
5
24
  async authServer(ctx) {
6
25
  const manager = await ctx.containerResolver.make(SesameManager);
26
+ const router = await ctx.containerResolver.make("router");
7
27
  const issuer = manager.config.issuer;
28
+ const prefixUrl = issuer;
29
+ this.#assertDiscoveryRoutes(router, { includeRegistration: manager.config.allowDynamicRegistration });
8
30
  ctx.response.header("Cache-Control", "public, max-age=15, stale-while-revalidate=15, stale-if-error=86400");
9
31
  return {
10
32
  issuer,
11
- authorization_endpoint: `${issuer}/oauth/authorize`,
12
- token_endpoint: `${issuer}/oauth/token`,
13
- registration_endpoint: manager.config.allowDynamicRegistration ? `${issuer}/oauth/register` : void 0,
14
- introspection_endpoint: `${issuer}/oauth/introspect`,
15
- revocation_endpoint: `${issuer}/oauth/revoke`,
33
+ authorization_endpoint: router.makeUrl("sesame.authorize", {}, { prefixUrl }),
34
+ token_endpoint: router.makeUrl("sesame.token", {}, { prefixUrl }),
35
+ registration_endpoint: manager.config.allowDynamicRegistration ? router.makeUrl("sesame.register", {}, { prefixUrl }) : void 0,
36
+ introspection_endpoint: router.makeUrl("sesame.introspect", {}, { prefixUrl }),
37
+ revocation_endpoint: router.makeUrl("sesame.revoke", {}, { prefixUrl }),
16
38
  response_types_supported: ["code"],
17
39
  response_modes_supported: ["query"],
18
40
  grant_types_supported: manager.config.grantTypes,
@@ -75,4 +75,20 @@ const E_SERVER_ERROR = class extends OAuthError {
75
75
  static message = "Server error";
76
76
  static oauthCode = "server_error";
77
77
  };
78
- export { E_INVALID_REQUEST as a, E_SERVER_ERROR as c, OAuthError as d, E_INVALID_GRANT as i, E_UNSUPPORTED_GRANT_TYPE as l, E_INVALID_CLIENT as n, E_INVALID_SCOPE as o, E_INVALID_CLIENT_METADATA as r, E_INVALID_TOKEN as s, E_ACCESS_DENIED as t, E_UNSUPPORTED_RESPONSE_TYPE as u };
78
+ const E_INSUFFICIENT_SCOPE = class extends OAuthError {
79
+ static status = 403;
80
+ static code = "E_INSUFFICIENT_SCOPE";
81
+ static message = "Insufficient scope";
82
+ static oauthCode = "insufficient_scope";
83
+ missingScopes;
84
+ constructor(missingScopes, message) {
85
+ super(message ?? "The token does not have the required scope(s)");
86
+ this.missingScopes = missingScopes;
87
+ }
88
+ handle(error, ctx) {
89
+ const scope = error.missingScopes.join(" ");
90
+ ctx.response.header("WWW-Authenticate", `Bearer error="insufficient_scope", error_description="${error.message}", scope="${scope}"`);
91
+ super.handle(error, ctx);
92
+ }
93
+ };
94
+ export { E_INVALID_GRANT as a, E_INVALID_TOKEN as c, E_UNSUPPORTED_RESPONSE_TYPE as d, OAuthError as f, E_INVALID_CLIENT_METADATA as i, E_SERVER_ERROR as l, E_INSUFFICIENT_SCOPE as n, E_INVALID_REQUEST as o, E_INVALID_CLIENT as r, E_INVALID_SCOPE as s, E_ACCESS_DENIED as t, E_UNSUPPORTED_GRANT_TYPE as u };
@@ -1,10 +1,6 @@
1
1
  import type { ApplicationService } from '@adonisjs/core/types';
2
2
  /**
3
3
  * AdonisJS service provider for the Sésame OAuth 2.1 server.
4
- *
5
- * - `register()`: Binds `SesameManager` as a singleton in the IoC
6
- * container, reading the resolved config from `config/sesame.ts`.
7
- * - `boot()`: Registers all OAuth routes on the AdonisJS router.
8
4
  */
9
5
  export default class SesameProvider {
10
6
  protected app: ApplicationService;
@@ -14,8 +10,4 @@ export default class SesameProvider {
14
10
  * The manager is resolved from the `sesame` config key.
15
11
  */
16
12
  register(): void;
17
- /**
18
- * Boot the provider by registering all OAuth 2.1 routes.
19
- */
20
- boot(): Promise<void>;
21
13
  }
@@ -1,6 +1,6 @@
1
+ import { t as SesameManager } from "../sesame_manager-CFq4VEIZ.js";
1
2
  import "../decorate-BKZEjPRg.js";
2
3
  import "../oauth_access_token-bsoM5KeU.js";
3
- import { t as SesameManager } from "../sesame_manager-CA7dOGwg.js";
4
4
  var SesameProvider = class {
5
5
  constructor(app) {
6
6
  this.app = app;
@@ -10,10 +10,5 @@ var SesameProvider = class {
10
10
  return new SesameManager(this.app.config.get("sesame"));
11
11
  });
12
12
  }
13
- async boot() {
14
- const router = await this.app.container.make("router");
15
- const { registerRoutes } = await import("../routes-qYJLHjeB.js").then((n) => n.r);
16
- registerRoutes(router);
17
- }
18
13
  };
19
14
  export { SesameProvider as default };
@@ -1,9 +1,9 @@
1
+ import { t as SesameManager } from "./sesame_manager-CFq4VEIZ.js";
1
2
  import "./decorate-BKZEjPRg.js";
2
3
  import "./oauth_access_token-bsoM5KeU.js";
3
- import { t as SesameManager } from "./sesame_manager-CA7dOGwg.js";
4
- import { a as E_INVALID_REQUEST, o as E_INVALID_SCOPE, r as E_INVALID_CLIENT_METADATA, t as E_ACCESS_DENIED } from "./oauth_error-BOn0846g.js";
5
- import { t as OAuthClient } from "./oauth_client-Cpppi0_7.js";
6
- import { t as ClientService } from "./client_service-DrkqOh37.js";
4
+ import { i as E_INVALID_CLIENT_METADATA, o as E_INVALID_REQUEST, s as E_INVALID_SCOPE, t as E_ACCESS_DENIED } from "./oauth_error-CnJ3L8tf.js";
5
+ import { t as OAuthClient } from "./oauth_client-BIoY5jBR.js";
6
+ import { t as ClientService } from "./client_service-BqPSlaTS.js";
7
7
  import vine from "@vinejs/vine";
8
8
  const DANGEROUS_SCHEMES = [
9
9
  "javascript:",
@@ -1,10 +1,10 @@
1
+ import { o as OAuthRefreshToken, t as SesameManager } from "./sesame_manager-CFq4VEIZ.js";
1
2
  import "./decorate-BKZEjPRg.js";
2
3
  import { t as OAuthAccessToken } from "./oauth_access_token-bsoM5KeU.js";
3
- import { o as OAuthRefreshToken, t as SesameManager } from "./sesame_manager-CA7dOGwg.js";
4
- import { n as E_INVALID_CLIENT } from "./oauth_error-BOn0846g.js";
5
- import { t as OAuthClient } from "./oauth_client-Cpppi0_7.js";
6
- import { t as TokenService } from "./token_service-BLKxKIHI.js";
7
- import { t as ClientService } from "./client_service-DrkqOh37.js";
4
+ import { r as E_INVALID_CLIENT } from "./oauth_error-CnJ3L8tf.js";
5
+ import { t as OAuthClient } from "./oauth_client-BIoY5jBR.js";
6
+ import { t as TokenService } from "./token_service-fhoA4slP.js";
7
+ import { t as ClientService } from "./client_service-BqPSlaTS.js";
8
8
  import { DateTime } from "luxon";
9
9
  var RevokeController = class {
10
10
  async handle(ctx) {