@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.
- package/README.md +167 -86
- package/build/{authorize_controller-D3Kau97j.js → authorize_controller-BNWhlPZQ.js} +8 -7
- package/build/{client_info_controller-CSipLLoV.js → client_info_controller-BucHGx4u.js} +2 -2
- package/build/{client_service-DrkqOh37.js → client_service-BqPSlaTS.js} +1 -1
- package/build/commands/sesame_purge.js +1 -1
- package/build/configure.js +7 -0
- package/build/{consent_controller-DXayMjAi.js → consent_controller-COvvkpHM.js} +6 -5
- package/build/index.d.ts +1 -2
- package/build/index.js +6 -7
- package/build/{introspect_controller-lK9gL03t.js → introspect_controller-JjAAXFIV.js} +5 -5
- package/build/{metadata_controller-DMAahJkn.js → metadata_controller-BzCjyqUG.js} +28 -6
- package/build/{oauth_error-BOn0846g.js → oauth_error-CnJ3L8tf.js} +17 -1
- package/build/providers/sesame_provider.d.ts +0 -8
- package/build/providers/sesame_provider.js +1 -6
- package/build/{register_controller-B0saLAuc.js → register_controller-DOlN9wNl.js} +4 -4
- package/build/{revoke_controller-D0nl2hS5.js → revoke_controller-B281b8ZO.js} +5 -5
- package/build/{sesame_manager-CA7dOGwg.js → sesame_manager-CFq4VEIZ.js} +53 -11
- package/build/src/controllers/authorize_controller.d.ts +3 -3
- package/build/src/controllers/metadata_controller.d.ts +1 -0
- package/build/src/define_config.d.ts +6 -1
- package/build/src/guard/guard.d.ts +4 -3
- package/build/src/guard/main.js +4 -4
- package/build/src/middleware/any_scope_middleware.d.ts +15 -0
- package/build/src/middleware/any_scope_middleware.js +18 -0
- package/build/src/middleware/scope_middleware.d.ts +15 -0
- package/build/src/middleware/scope_middleware.js +18 -0
- package/build/src/oauth_error.d.ts +32 -0
- package/build/src/routes.d.ts +21 -20
- package/build/src/sesame_manager.d.ts +38 -8
- package/build/src/types.d.ts +27 -0
- package/build/stubs/config/sesame.stub +5 -0
- package/build/{token_controller-CDFuzY6S.js → token_controller-ll9sjcvn.js} +10 -9
- package/build/{token_service-BLKxKIHI.js → token_service-fhoA4slP.js} +2 -1
- package/build/{user_provider-CQczt8_g.js → user_provider-DXAOfv8-.js} +2 -2
- package/package.json +7 -2
- package/build/rolldown-runtime-BASaM9lw.js +0 -12
- package/build/routes-qYJLHjeB.js +0 -43
- /package/build/{oauth_client-Cpppi0_7.js → oauth_client-BIoY5jBR.js} +0 -0
package/README.md
CHANGED
|
@@ -1,130 +1,211 @@
|
|
|
1
|
-
#
|
|
1
|
+
# Sésame
|
|
2
2
|
|
|
3
|
-
>
|
|
4
|
-
> This starter kit targets **AdonisJS v7**
|
|
3
|
+
> OAuth 2.1 + OIDC server for AdonisJS
|
|
5
4
|
|
|
6
|
-
|
|
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
|
-
|
|
7
|
+
## Features
|
|
9
8
|
|
|
10
|
-
|
|
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
|
-
|
|
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
|
-
|
|
22
|
+
```bash
|
|
23
|
+
node ace add @julr/sesame
|
|
24
|
+
```
|
|
21
25
|
|
|
22
|
-
|
|
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
|
-
|
|
26
|
-
|
|
27
|
-
|
|
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
|
-
|
|
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
|
-
|
|
39
|
+
The configuration file lives at `config/sesame.ts`:
|
|
47
40
|
|
|
48
|
-
|
|
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
|
-
|
|
46
|
+
const sesameConfig = defineConfig({
|
|
47
|
+
issuer: env.get('APP_URL'),
|
|
51
48
|
|
|
52
|
-
|
|
49
|
+
scopes: {
|
|
50
|
+
'read': 'Read access',
|
|
51
|
+
'write': 'Write access',
|
|
52
|
+
},
|
|
53
53
|
|
|
54
|
-
|
|
54
|
+
defaultScopes: ['read'],
|
|
55
55
|
|
|
56
|
-
|
|
56
|
+
grantTypes: ['authorization_code', 'refresh_token'],
|
|
57
57
|
|
|
58
|
-
|
|
58
|
+
accessTokenTtl: '1h',
|
|
59
|
+
refreshTokenTtl: '30d',
|
|
60
|
+
authorizationCodeTtl: '10m',
|
|
59
61
|
|
|
60
|
-
|
|
62
|
+
loginPage: '/login',
|
|
63
|
+
consentPage: '/oauth/consent',
|
|
61
64
|
|
|
62
|
-
|
|
65
|
+
allowDynamicRegistration: false,
|
|
66
|
+
allowPublicRegistration: false,
|
|
67
|
+
})
|
|
63
68
|
|
|
64
|
-
|
|
69
|
+
export default sesameConfig
|
|
65
70
|
|
|
66
|
-
|
|
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
|
-
|
|
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
|
-
|
|
129
|
+
Then use it in your controllers:
|
|
83
130
|
|
|
84
|
-
|
|
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
|
-
|
|
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
|
-
|
|
96
|
-
|
|
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
|
-
|
|
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
|
-
##
|
|
159
|
+
## MCP Support
|
|
101
160
|
|
|
102
|
-
|
|
161
|
+
For MCP (Model Context Protocol) servers, register per-resource discovery:
|
|
103
162
|
|
|
104
|
-
|
|
105
|
-
|
|
163
|
+
```ts
|
|
164
|
+
sesame.registerProtectedResource(router, {
|
|
165
|
+
resource: '/api/mcp',
|
|
166
|
+
scopes: ['read:mcp'],
|
|
167
|
+
})
|
|
168
|
+
```
|
|
106
169
|
|
|
107
|
-
|
|
170
|
+
This creates a `/.well-known/oauth-protected-resource/api/mcp` endpoint following RFC 9728.
|
|
108
171
|
|
|
109
|
-
|
|
172
|
+
You can also enable public client registration for MCP clients:
|
|
110
173
|
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
174
|
+
```ts
|
|
175
|
+
const sesameConfig = defineConfig({
|
|
176
|
+
// ...
|
|
177
|
+
allowDynamicRegistration: true,
|
|
178
|
+
allowPublicRegistration: true,
|
|
179
|
+
})
|
|
180
|
+
```
|
|
115
181
|
|
|
116
|
-
|
|
182
|
+
## Token Cleanup
|
|
117
183
|
|
|
118
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
209
|
+
## License
|
|
129
210
|
|
|
130
|
-
|
|
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 {
|
|
4
|
-
import {
|
|
5
|
-
import { t as
|
|
6
|
-
import { t as
|
|
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 =
|
|
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 =
|
|
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 {
|
|
3
|
-
import { t as OAuthClient } from "./oauth_client-
|
|
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,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";
|
package/build/configure.js
CHANGED
|
@@ -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
|
|
4
|
-
import {
|
|
5
|
-
import { t as
|
|
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 =
|
|
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
|
|
5
|
-
import {
|
|
6
|
-
import
|
|
7
|
-
import "./
|
|
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
|
|
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 {
|
|
4
|
-
import {
|
|
5
|
-
import { t as
|
|
6
|
-
import { t as
|
|
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 {
|
|
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:
|
|
12
|
-
token_endpoint:
|
|
13
|
-
registration_endpoint: manager.config.allowDynamicRegistration ?
|
|
14
|
-
introspection_endpoint:
|
|
15
|
-
revocation_endpoint:
|
|
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
|
-
|
|
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
|
|
4
|
-
import {
|
|
5
|
-
import { t as
|
|
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 {
|
|
4
|
-
import {
|
|
5
|
-
import { t as
|
|
6
|
-
import { t as
|
|
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) {
|