@julr/sesame 0.0.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.
- package/LICENSE.md +9 -0
- package/README.md +130 -0
- package/build/authorize_controller-CUdEDNEi.js +136 -0
- package/build/client_info_controller-DeIVcW8B.js +18 -0
- package/build/client_service-B9fD3ZGe.js +53 -0
- package/build/commands/commands.json +1 -0
- package/build/commands/main.d.ts +4 -0
- package/build/commands/main.js +36 -0
- package/build/commands/sesame_purge.d.ts +21 -0
- package/build/commands/sesame_purge.js +28 -0
- package/build/configure.d.ts +2 -0
- package/build/configure.js +16 -0
- package/build/consent_controller-DFfx7qVs.js +87 -0
- package/build/decorate-2_8Ex77k.js +15 -0
- package/build/index.d.ts +14 -0
- package/build/index.js +27 -0
- package/build/introspect_controller-BzwfaUUE.js +63 -0
- package/build/main-kn40V-hF.js +2 -0
- package/build/metadata_controller-BSRRElQX.js +51 -0
- package/build/oauth_access_token-BpG8sq-c.js +18 -0
- package/build/oauth_client-eh0e5ql-.js +24 -0
- package/build/oauth_error-BQPqV-MV.js +78 -0
- package/build/providers/sesame_provider.d.ts +21 -0
- package/build/providers/sesame_provider.js +19 -0
- package/build/register_controller-BA7uQAgt.js +139 -0
- package/build/revoke_controller-CNIgNKH3.js +50 -0
- package/build/rolldown-runtime-BASaM9lw.js +12 -0
- package/build/routes-D6QCu0Pz.js +43 -0
- package/build/sesame_manager-B4tO2PLO.js +116 -0
- package/build/src/controllers/authorize_controller.d.ts +53 -0
- package/build/src/controllers/client_info_controller.d.ts +22 -0
- package/build/src/controllers/consent_controller.d.ts +27 -0
- package/build/src/controllers/introspect_controller.d.ts +28 -0
- package/build/src/controllers/metadata_controller.d.ts +64 -0
- package/build/src/controllers/register_controller.d.ts +91 -0
- package/build/src/controllers/revoke_controller.d.ts +16 -0
- package/build/src/controllers/token_controller.d.ts +24 -0
- package/build/src/decorators.d.ts +10 -0
- package/build/src/define_config.d.ts +16 -0
- package/build/src/grants/authorization_code_grant.d.ts +27 -0
- package/build/src/grants/refresh_token_grant.d.ts +27 -0
- package/build/src/guard/guard.d.ts +30 -0
- package/build/src/guard/main.d.ts +20 -0
- package/build/src/guard/main.js +17 -0
- package/build/src/guard/types.d.ts +46 -0
- package/build/src/guard/user_provider.d.ts +14 -0
- package/build/src/models/oauth_access_token.d.ts +23 -0
- package/build/src/models/oauth_authorization_code.d.ts +30 -0
- package/build/src/models/oauth_client.d.ts +33 -0
- package/build/src/models/oauth_consent.d.ts +22 -0
- package/build/src/models/oauth_refresh_token.d.ts +29 -0
- package/build/src/oauth_error.d.ts +359 -0
- package/build/src/routes.d.ts +28 -0
- package/build/src/rules.d.ts +12 -0
- package/build/src/services/client_service.d.ts +67 -0
- package/build/src/services/token_service.d.ts +42 -0
- package/build/src/sesame_manager.d.ts +66 -0
- package/build/src/types.d.ts +141 -0
- package/build/stubs/config/sesame.stub +30 -0
- package/build/stubs/main.d.ts +5 -0
- package/build/stubs/migrations/create_oauth_access_tokens_table.stub +25 -0
- package/build/stubs/migrations/create_oauth_authorization_codes_table.stub +27 -0
- package/build/stubs/migrations/create_oauth_clients_table.stub +31 -0
- package/build/stubs/migrations/create_oauth_consents_table.stub +24 -0
- package/build/stubs/migrations/create_oauth_refresh_tokens_table.stub +26 -0
- package/build/token_controller-C9wh813f.js +172 -0
- package/build/token_service-Czz9v5GI.js +30 -0
- package/build/user_provider-B3rXEUT3.js +150 -0
- package/package.json +144 -0
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import type { HttpContext } from '@adonisjs/core/http';
|
|
2
|
+
/**
|
|
3
|
+
* Handles the OAuth 2.0 Authorization Endpoint (RFC 6749 §3.1).
|
|
4
|
+
*
|
|
5
|
+
* Implements the authorization code flow with PKCE support (RFC 7636).
|
|
6
|
+
* Validates the client, requested scopes, and PKCE parameters, then
|
|
7
|
+
* either redirects the user to the login/consent page or directly
|
|
8
|
+
* issues an authorization code if consent was already granted.
|
|
9
|
+
*
|
|
10
|
+
* The `iss` response parameter is included per RFC 9207 to prevent
|
|
11
|
+
* mix-up attacks.
|
|
12
|
+
*
|
|
13
|
+
* @see https://datatracker.ietf.org/doc/html/rfc6749#section-3.1
|
|
14
|
+
* @see https://datatracker.ietf.org/doc/html/rfc7636
|
|
15
|
+
* @see https://datatracker.ietf.org/doc/html/rfc9207
|
|
16
|
+
*/
|
|
17
|
+
export default class AuthorizeController {
|
|
18
|
+
#private;
|
|
19
|
+
static validator: import("@vinejs/vine").VineValidator<import("@vinejs/vine").VineObject<{
|
|
20
|
+
client_id: import("@vinejs/vine").VineString;
|
|
21
|
+
response_type: import("@vinejs/vine").VineString;
|
|
22
|
+
redirect_uri: import("@vinejs/vine").VineString;
|
|
23
|
+
scope: import("@vinejs/vine/schema/base/literal").OptionalModifier<import("@vinejs/vine").VineString>;
|
|
24
|
+
state: import("@vinejs/vine/schema/base/literal").OptionalModifier<import("@vinejs/vine").VineString>;
|
|
25
|
+
code_challenge: import("@vinejs/vine/schema/base/literal").OptionalModifier<import("@vinejs/vine").VineString>;
|
|
26
|
+
code_challenge_method: import("@vinejs/vine/schema/base/literal").OptionalModifier<import("@vinejs/vine").VineString>;
|
|
27
|
+
}, {
|
|
28
|
+
scope?: string | null | undefined;
|
|
29
|
+
state?: string | null | undefined;
|
|
30
|
+
code_challenge?: string | null | undefined;
|
|
31
|
+
code_challenge_method?: string | null | undefined;
|
|
32
|
+
redirect_uri: string;
|
|
33
|
+
client_id: string;
|
|
34
|
+
response_type: string;
|
|
35
|
+
}, {
|
|
36
|
+
scope?: string | undefined;
|
|
37
|
+
state?: string | undefined;
|
|
38
|
+
code_challenge?: string | undefined;
|
|
39
|
+
code_challenge_method?: string | undefined;
|
|
40
|
+
redirect_uri: string;
|
|
41
|
+
client_id: string;
|
|
42
|
+
response_type: string;
|
|
43
|
+
}, {
|
|
44
|
+
scope?: string | undefined;
|
|
45
|
+
state?: string | undefined;
|
|
46
|
+
code_challenge?: string | undefined;
|
|
47
|
+
code_challenge_method?: string | undefined;
|
|
48
|
+
redirect_uri: string;
|
|
49
|
+
client_id: string;
|
|
50
|
+
response_type: string;
|
|
51
|
+
}>, Record<string, any> | undefined>;
|
|
52
|
+
handle(ctx: HttpContext): Promise<void>;
|
|
53
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { HttpContext } from '@adonisjs/core/http';
|
|
2
|
+
/**
|
|
3
|
+
* Returns public information about an OAuth client.
|
|
4
|
+
* Used by the consent page to display the client's name
|
|
5
|
+
* from server-side data rather than query parameters
|
|
6
|
+
* (RFC 6819 §4.4.1.4 — prevent client identity spoofing).
|
|
7
|
+
*/
|
|
8
|
+
export default class ClientInfoController {
|
|
9
|
+
static validator: import("@vinejs/vine").VineValidator<import("@vinejs/vine").VineObject<{
|
|
10
|
+
client_id: import("@vinejs/vine").VineString;
|
|
11
|
+
}, {
|
|
12
|
+
client_id: string;
|
|
13
|
+
}, {
|
|
14
|
+
client_id: string;
|
|
15
|
+
}, {
|
|
16
|
+
client_id: string;
|
|
17
|
+
}>, Record<string, any> | undefined>;
|
|
18
|
+
handle(ctx: HttpContext): Promise<{
|
|
19
|
+
client_id: string;
|
|
20
|
+
client_name: string;
|
|
21
|
+
}>;
|
|
22
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import type { HttpContext } from '@adonisjs/core/http';
|
|
2
|
+
/**
|
|
3
|
+
* Handles user consent submission for the OAuth authorization flow.
|
|
4
|
+
*
|
|
5
|
+
* When a user approves access, this controller stores or updates
|
|
6
|
+
* the consent record and issues an authorization code via redirect.
|
|
7
|
+
* When the user denies access, it redirects back to the client
|
|
8
|
+
* with an `access_denied` error.
|
|
9
|
+
*
|
|
10
|
+
* Consent records are persisted so that returning users are not
|
|
11
|
+
* prompted again for previously approved scopes.
|
|
12
|
+
*
|
|
13
|
+
* @see https://datatracker.ietf.org/doc/html/rfc6749#section-4.1.1
|
|
14
|
+
*/
|
|
15
|
+
export default class ConsentController {
|
|
16
|
+
#private;
|
|
17
|
+
static validator: import("@vinejs/vine").VineValidator<import("@vinejs/vine").VineObject<{
|
|
18
|
+
auth_token: import("@vinejs/vine").VineString;
|
|
19
|
+
}, {
|
|
20
|
+
auth_token: string;
|
|
21
|
+
}, {
|
|
22
|
+
auth_token: string;
|
|
23
|
+
}, {
|
|
24
|
+
auth_token: string;
|
|
25
|
+
}>, Record<string, any> | undefined>;
|
|
26
|
+
handle(ctx: HttpContext): Promise<void>;
|
|
27
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import type { HttpContext } from '@adonisjs/core/http';
|
|
2
|
+
/**
|
|
3
|
+
* Handles the OAuth 2.0 Token Introspection Endpoint (RFC 7662).
|
|
4
|
+
*
|
|
5
|
+
* Allows an authenticated client to determine the active state and
|
|
6
|
+
* metadata of a token (access token or refresh token). The response
|
|
7
|
+
* always includes at least `{ active: boolean }`.
|
|
8
|
+
*
|
|
9
|
+
* Supports the `token_type_hint` parameter to optimize lookup order.
|
|
10
|
+
* Both access tokens and refresh tokens are opaque values looked up
|
|
11
|
+
* by their SHA-256 hash in the database.
|
|
12
|
+
*
|
|
13
|
+
* @see https://datatracker.ietf.org/doc/html/rfc7662
|
|
14
|
+
*/
|
|
15
|
+
export default class IntrospectController {
|
|
16
|
+
handle(ctx: HttpContext): Promise<{
|
|
17
|
+
active: boolean;
|
|
18
|
+
} | {
|
|
19
|
+
active: boolean;
|
|
20
|
+
token_type: string;
|
|
21
|
+
client_id: string;
|
|
22
|
+
sub: string | undefined;
|
|
23
|
+
scope: string;
|
|
24
|
+
iss: string;
|
|
25
|
+
iat: number;
|
|
26
|
+
exp: number;
|
|
27
|
+
}>;
|
|
28
|
+
}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import type { HttpContext } from '@adonisjs/core/http';
|
|
2
|
+
import type { AuthServerMetadata, ResourceServerMetadata } from '../types.ts';
|
|
3
|
+
/**
|
|
4
|
+
* Serves OAuth 2.0 discovery metadata documents.
|
|
5
|
+
*
|
|
6
|
+
* Exposes three well-known endpoints:
|
|
7
|
+
* - `authServer()` — OAuth Authorization Server Metadata (RFC 8414)
|
|
8
|
+
* - `oidc()` — OpenID Connect Discovery 1.0 (extends authServer metadata)
|
|
9
|
+
* - `protectedResource()` — OAuth Protected Resource Metadata (RFC 9728)
|
|
10
|
+
*
|
|
11
|
+
* @see https://datatracker.ietf.org/doc/html/rfc8414
|
|
12
|
+
* @see https://datatracker.ietf.org/doc/html/rfc9728
|
|
13
|
+
* @see https://openid.net/specs/openid-connect-discovery-1_0.html
|
|
14
|
+
*/
|
|
15
|
+
export default class MetadataController {
|
|
16
|
+
/**
|
|
17
|
+
* OAuth 2.0 Authorization Server Metadata (RFC 8414).
|
|
18
|
+
*
|
|
19
|
+
* Returns a JSON document describing the server's endpoints,
|
|
20
|
+
* supported grant types, response types, authentication methods,
|
|
21
|
+
* and PKCE support.
|
|
22
|
+
*
|
|
23
|
+
* @see https://datatracker.ietf.org/doc/html/rfc8414#section-2
|
|
24
|
+
*/
|
|
25
|
+
authServer(ctx: HttpContext): Promise<AuthServerMetadata>;
|
|
26
|
+
/**
|
|
27
|
+
* OpenID Connect Discovery 1.0 metadata.
|
|
28
|
+
*
|
|
29
|
+
* Extends the authorization server metadata with OIDC-specific
|
|
30
|
+
* fields like `subject_types_supported` and
|
|
31
|
+
* `id_token_signing_alg_values_supported`.
|
|
32
|
+
*
|
|
33
|
+
* @see https://openid.net/specs/openid-connect-discovery-1_0.html#ProviderMetadata
|
|
34
|
+
*/
|
|
35
|
+
oidc(ctx: HttpContext): Promise<{
|
|
36
|
+
subject_types_supported: string[];
|
|
37
|
+
scopes_supported: string[];
|
|
38
|
+
issuer: string;
|
|
39
|
+
authorization_endpoint: string;
|
|
40
|
+
token_endpoint: string;
|
|
41
|
+
registration_endpoint?: string;
|
|
42
|
+
introspection_endpoint?: string;
|
|
43
|
+
revocation_endpoint?: string;
|
|
44
|
+
response_types_supported: string[];
|
|
45
|
+
response_modes_supported: string[];
|
|
46
|
+
grant_types_supported: string[];
|
|
47
|
+
token_endpoint_auth_methods_supported: string[];
|
|
48
|
+
introspection_endpoint_auth_methods_supported?: string[];
|
|
49
|
+
revocation_endpoint_auth_methods_supported?: string[];
|
|
50
|
+
code_challenge_methods_supported: string[];
|
|
51
|
+
authorization_response_iss_parameter_supported: boolean;
|
|
52
|
+
}>;
|
|
53
|
+
/**
|
|
54
|
+
* OAuth 2.0 Protected Resource Metadata (RFC 9728).
|
|
55
|
+
*
|
|
56
|
+
* Returns a JSON document that tells clients which authorization
|
|
57
|
+
* servers protect this resource, which scopes are available, and
|
|
58
|
+
* how to present bearer tokens. Used by MCP clients to discover
|
|
59
|
+
* the authorization server.
|
|
60
|
+
*
|
|
61
|
+
* @see https://datatracker.ietf.org/doc/html/rfc9728
|
|
62
|
+
*/
|
|
63
|
+
protectedResource(ctx: HttpContext): Promise<ResourceServerMetadata>;
|
|
64
|
+
}
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import type { HttpContext } from '@adonisjs/core/http';
|
|
2
|
+
/**
|
|
3
|
+
* Handles the OAuth 2.0 Dynamic Client Registration Endpoint (RFC 7591).
|
|
4
|
+
*
|
|
5
|
+
* Allows clients to register themselves with the authorization server
|
|
6
|
+
* by providing metadata such as `redirect_uris`, `grant_types`, and
|
|
7
|
+
* `token_endpoint_auth_method`. Returns the assigned `client_id` and
|
|
8
|
+
* optionally a `client_secret` for confidential clients.
|
|
9
|
+
*
|
|
10
|
+
* Can be configured to require authentication or allow public
|
|
11
|
+
* registration (useful for MCP where clients self-register).
|
|
12
|
+
*
|
|
13
|
+
* @see https://datatracker.ietf.org/doc/html/rfc7591
|
|
14
|
+
*/
|
|
15
|
+
export default class RegisterController {
|
|
16
|
+
static validator: import("@vinejs/vine").VineValidator<import("@vinejs/vine").VineObject<{
|
|
17
|
+
redirect_uris: import("@vinejs/vine").VineArray<import("@vinejs/vine").VineString>;
|
|
18
|
+
token_endpoint_auth_method: import("@vinejs/vine/schema/base/literal").OptionalModifier<import("@vinejs/vine").VineString>;
|
|
19
|
+
grant_types: import("@vinejs/vine").OptionalModifier<import("@vinejs/vine").VineArray<import("@vinejs/vine").VineString>>;
|
|
20
|
+
response_types: import("@vinejs/vine").OptionalModifier<import("@vinejs/vine").VineArray<import("@vinejs/vine").VineString>>;
|
|
21
|
+
scope: import("@vinejs/vine/schema/base/literal").OptionalModifier<import("@vinejs/vine").VineString>;
|
|
22
|
+
client_name: import("@vinejs/vine/schema/base/literal").OptionalModifier<import("@vinejs/vine").VineString>;
|
|
23
|
+
client_uri: import("@vinejs/vine/schema/base/literal").OptionalModifier<import("@vinejs/vine").VineString>;
|
|
24
|
+
logo_uri: import("@vinejs/vine/schema/base/literal").OptionalModifier<import("@vinejs/vine").VineString>;
|
|
25
|
+
tos_uri: import("@vinejs/vine/schema/base/literal").OptionalModifier<import("@vinejs/vine").VineString>;
|
|
26
|
+
policy_uri: import("@vinejs/vine/schema/base/literal").OptionalModifier<import("@vinejs/vine").VineString>;
|
|
27
|
+
contacts: import("@vinejs/vine").OptionalModifier<import("@vinejs/vine").VineArray<import("@vinejs/vine").VineString>>;
|
|
28
|
+
software_id: import("@vinejs/vine/schema/base/literal").OptionalModifier<import("@vinejs/vine").VineString>;
|
|
29
|
+
software_version: import("@vinejs/vine/schema/base/literal").OptionalModifier<import("@vinejs/vine").VineString>;
|
|
30
|
+
}, {
|
|
31
|
+
scope?: string | null | undefined;
|
|
32
|
+
token_endpoint_auth_method?: string | null | undefined;
|
|
33
|
+
grant_types?: string[] | null | undefined;
|
|
34
|
+
response_types?: string[] | null | undefined;
|
|
35
|
+
client_name?: string | null | undefined;
|
|
36
|
+
client_uri?: string | null | undefined;
|
|
37
|
+
logo_uri?: string | null | undefined;
|
|
38
|
+
tos_uri?: string | null | undefined;
|
|
39
|
+
policy_uri?: string | null | undefined;
|
|
40
|
+
contacts?: string[] | null | undefined;
|
|
41
|
+
software_id?: string | null | undefined;
|
|
42
|
+
software_version?: string | null | undefined;
|
|
43
|
+
redirect_uris: string[];
|
|
44
|
+
}, {
|
|
45
|
+
scope?: string | undefined;
|
|
46
|
+
token_endpoint_auth_method?: string | undefined;
|
|
47
|
+
grant_types?: string[] | undefined;
|
|
48
|
+
response_types?: string[] | undefined;
|
|
49
|
+
client_name?: string | undefined;
|
|
50
|
+
client_uri?: string | undefined;
|
|
51
|
+
logo_uri?: string | undefined;
|
|
52
|
+
tos_uri?: string | undefined;
|
|
53
|
+
policy_uri?: string | undefined;
|
|
54
|
+
contacts?: string[] | undefined;
|
|
55
|
+
software_id?: string | undefined;
|
|
56
|
+
software_version?: string | undefined;
|
|
57
|
+
redirect_uris: string[];
|
|
58
|
+
}, {
|
|
59
|
+
scope?: string | undefined;
|
|
60
|
+
token_endpoint_auth_method?: string | undefined;
|
|
61
|
+
grant_types?: string[] | undefined;
|
|
62
|
+
response_types?: string[] | undefined;
|
|
63
|
+
client_name?: string | undefined;
|
|
64
|
+
client_uri?: string | undefined;
|
|
65
|
+
logo_uri?: string | undefined;
|
|
66
|
+
tos_uri?: string | undefined;
|
|
67
|
+
policy_uri?: string | undefined;
|
|
68
|
+
contacts?: string[] | undefined;
|
|
69
|
+
software_id?: string | undefined;
|
|
70
|
+
software_version?: string | undefined;
|
|
71
|
+
redirect_uris: string[];
|
|
72
|
+
}>, Record<string, any> | undefined>;
|
|
73
|
+
handle(ctx: HttpContext): Promise<{
|
|
74
|
+
software_version?: string | undefined;
|
|
75
|
+
software_id?: string | undefined;
|
|
76
|
+
policy_uri?: string | undefined;
|
|
77
|
+
tos_uri?: string | undefined;
|
|
78
|
+
contacts?: string[] | undefined;
|
|
79
|
+
logo_uri?: string | undefined;
|
|
80
|
+
client_uri?: string | undefined;
|
|
81
|
+
token_endpoint_auth_method: string;
|
|
82
|
+
response_types: string[];
|
|
83
|
+
client_secret_expires_at: number;
|
|
84
|
+
client_name: string;
|
|
85
|
+
redirect_uris: string[];
|
|
86
|
+
grant_types: string[];
|
|
87
|
+
scope: string;
|
|
88
|
+
client_secret?: string | undefined;
|
|
89
|
+
client_id: string;
|
|
90
|
+
}>;
|
|
91
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { HttpContext } from '@adonisjs/core/http';
|
|
2
|
+
/**
|
|
3
|
+
* Handles the OAuth 2.0 Token Revocation Endpoint (RFC 7009).
|
|
4
|
+
*
|
|
5
|
+
* Allows an authenticated client to revoke an access token or
|
|
6
|
+
* refresh token. Always responds with HTTP 200, even if the token
|
|
7
|
+
* was already revoked or not found (to prevent information leakage).
|
|
8
|
+
*
|
|
9
|
+
* When revoking a refresh token, the associated access token is
|
|
10
|
+
* also revoked as recommended by RFC 7009 §2.1.
|
|
11
|
+
*
|
|
12
|
+
* @see https://datatracker.ietf.org/doc/html/rfc7009
|
|
13
|
+
*/
|
|
14
|
+
export default class RevokeController {
|
|
15
|
+
handle(ctx: HttpContext): Promise<void>;
|
|
16
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { HttpContext } from '@adonisjs/core/http';
|
|
2
|
+
/**
|
|
3
|
+
* Handles the OAuth 2.0 Token Endpoint (RFC 6749 §3.2).
|
|
4
|
+
*
|
|
5
|
+
* Dispatches to the appropriate grant handler based on the
|
|
6
|
+
* `grant_type` parameter. Sets `Cache-Control: no-store` and
|
|
7
|
+
* `Pragma: no-cache` headers on all token responses as required
|
|
8
|
+
* by the spec.
|
|
9
|
+
*
|
|
10
|
+
* @see https://datatracker.ietf.org/doc/html/rfc6749#section-3.2
|
|
11
|
+
* @see https://datatracker.ietf.org/doc/html/rfc6749#section-5.1
|
|
12
|
+
*/
|
|
13
|
+
export default class TokenController {
|
|
14
|
+
static validator: import("@vinejs/vine").VineValidator<import("@vinejs/vine").VineObject<{
|
|
15
|
+
grant_type: import("@vinejs/vine").VineString;
|
|
16
|
+
}, {
|
|
17
|
+
grant_type: string;
|
|
18
|
+
}, {
|
|
19
|
+
grant_type: string;
|
|
20
|
+
}, {
|
|
21
|
+
grant_type: string;
|
|
22
|
+
}>, Record<string, any> | undefined>;
|
|
23
|
+
handle(ctx: HttpContext): Promise<any>;
|
|
24
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { column } from '@adonisjs/lucid/orm';
|
|
2
|
+
/**
|
|
3
|
+
* Column decorator for JSON values (arrays, objects).
|
|
4
|
+
*
|
|
5
|
+
* Lucid ORM doesn't handle JSON serialization automatically —
|
|
6
|
+
* `prepare` stringifies before INSERT/UPDATE, `consume` parses
|
|
7
|
+
* after SELECT. The typeof check in consume handles both drivers
|
|
8
|
+
* that return strings (SQLite, MySQL) and parsed objects (PostgreSQL JSONB).
|
|
9
|
+
*/
|
|
10
|
+
export declare function json(options?: Parameters<typeof column>[0]): import("@adonisjs/lucid/types/model").DecoratorFn;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { SesameConfig, ResolvedSesameConfig } from './types.ts';
|
|
2
|
+
/**
|
|
3
|
+
* Resolve user-supplied `SesameConfig` into a `ResolvedSesameConfig`
|
|
4
|
+
* by applying sensible defaults for all optional fields.
|
|
5
|
+
*
|
|
6
|
+
* Defaults:
|
|
7
|
+
* - `scopes`: `{}`
|
|
8
|
+
* - `defaultScopes`: `[]`
|
|
9
|
+
* - `grantTypes`: `['authorization_code', 'refresh_token']`
|
|
10
|
+
* - `accessTokenTtl`: `'1h'`
|
|
11
|
+
* - `refreshTokenTtl`: `'30d'`
|
|
12
|
+
* - `authorizationCodeTtl`: `'10m'`
|
|
13
|
+
* - `allowDynamicRegistration`: `false`
|
|
14
|
+
* - `allowPublicRegistration`: `false`
|
|
15
|
+
*/
|
|
16
|
+
export declare function defineConfig(config: SesameConfig): ResolvedSesameConfig;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import type { HttpContext } from '@adonisjs/core/http';
|
|
2
|
+
import type { SesameManager } from '../sesame_manager.ts';
|
|
3
|
+
/**
|
|
4
|
+
* Handle the Authorization Code Grant (RFC 6749 §4.1.3).
|
|
5
|
+
*
|
|
6
|
+
* Exchanges an authorization code for an access token (and optionally
|
|
7
|
+
* a refresh token if the `offline_access` scope was granted).
|
|
8
|
+
*
|
|
9
|
+
* Performs the following validations:
|
|
10
|
+
* - Client authentication (Basic header or POST body credentials)
|
|
11
|
+
* - Authorization code existence, expiration, and single-use enforcement
|
|
12
|
+
* - Redirect URI matching against the original authorization request
|
|
13
|
+
* - PKCE code_verifier verification using S256 (RFC 7636 §4.6)
|
|
14
|
+
*
|
|
15
|
+
* All tokens (access tokens, refresh tokens, authorization codes)
|
|
16
|
+
* are opaque values stored as SHA-256 hashes.
|
|
17
|
+
*
|
|
18
|
+
* @see https://datatracker.ietf.org/doc/html/rfc6749#section-4.1.3
|
|
19
|
+
* @see https://datatracker.ietf.org/doc/html/rfc7636#section-4.6
|
|
20
|
+
*/
|
|
21
|
+
export declare function handleAuthorizationCodeGrant(ctx: HttpContext, manager: SesameManager): Promise<{
|
|
22
|
+
refresh_token?: string | undefined;
|
|
23
|
+
access_token: string;
|
|
24
|
+
token_type: string;
|
|
25
|
+
expires_in: number;
|
|
26
|
+
scope: string;
|
|
27
|
+
}>;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import type { HttpContext } from '@adonisjs/core/http';
|
|
2
|
+
import type { SesameManager } from '../sesame_manager.ts';
|
|
3
|
+
/**
|
|
4
|
+
* Handle the Refresh Token Grant (RFC 6749 §6).
|
|
5
|
+
*
|
|
6
|
+
* Exchanges a refresh token for a new access token and a new
|
|
7
|
+
* refresh token (rotation). The old refresh token is revoked
|
|
8
|
+
* immediately after use.
|
|
9
|
+
*
|
|
10
|
+
* Implements replay detection: if a revoked refresh token is
|
|
11
|
+
* presented, all tokens for that client+user pair are nuked
|
|
12
|
+
* (both access and refresh tokens) to mitigate stolen token
|
|
13
|
+
* reuse attacks.
|
|
14
|
+
*
|
|
15
|
+
* Scope narrowing is supported: the client may request a subset
|
|
16
|
+
* of the originally granted scopes, but cannot request new ones.
|
|
17
|
+
*
|
|
18
|
+
* @see https://datatracker.ietf.org/doc/html/rfc6749#section-6
|
|
19
|
+
* @see https://datatracker.ietf.org/doc/html/draft-ietf-oauth-security-topics#section-4.14.2
|
|
20
|
+
*/
|
|
21
|
+
export declare function handleRefreshTokenGrant(ctx: HttpContext, manager: SesameManager): Promise<{
|
|
22
|
+
access_token: string;
|
|
23
|
+
token_type: string;
|
|
24
|
+
expires_in: number;
|
|
25
|
+
scope: string;
|
|
26
|
+
refresh_token: string;
|
|
27
|
+
}>;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import type { HttpContext } from '@adonisjs/core/http';
|
|
2
|
+
import type { EmitterLike } from '@adonisjs/core/types/events';
|
|
3
|
+
import { symbols } from '@adonisjs/auth';
|
|
4
|
+
import type { AuthClientResponse, GuardContract } from '@adonisjs/auth/types';
|
|
5
|
+
import type { SesameManager } from '../sesame_manager.ts';
|
|
6
|
+
import type { OAuthGuardEvents, OAuthUserProviderContract } from './types.ts';
|
|
7
|
+
/**
|
|
8
|
+
* OAuth 2.0 guard for `@adonisjs/auth`.
|
|
9
|
+
*
|
|
10
|
+
* Verifies opaque Bearer tokens against the database,
|
|
11
|
+
* checks revocation and expiry, loads the real User model
|
|
12
|
+
* via the provider, and exposes OAuth-specific data (scopes, clientId).
|
|
13
|
+
*/
|
|
14
|
+
export declare class OAuthGuard<UserProvider extends OAuthUserProviderContract<unknown>> implements GuardContract<UserProvider[typeof symbols.PROVIDER_REAL_USER]> {
|
|
15
|
+
#private;
|
|
16
|
+
[symbols.GUARD_KNOWN_EVENTS]: OAuthGuardEvents<UserProvider[typeof symbols.PROVIDER_REAL_USER]>;
|
|
17
|
+
driverName: "oauth";
|
|
18
|
+
authenticationAttempted: boolean;
|
|
19
|
+
isAuthenticated: boolean;
|
|
20
|
+
user?: UserProvider[typeof symbols.PROVIDER_REAL_USER];
|
|
21
|
+
scopes: string[];
|
|
22
|
+
clientId?: string;
|
|
23
|
+
constructor(name: string, ctx: HttpContext, emitter: EmitterLike<OAuthGuardEvents<UserProvider[typeof symbols.PROVIDER_REAL_USER]>>, userProvider: UserProvider, manager: SesameManager, resource?: string);
|
|
24
|
+
getUserOrFail(): UserProvider[typeof symbols.PROVIDER_REAL_USER];
|
|
25
|
+
authenticate(): Promise<UserProvider[typeof symbols.PROVIDER_REAL_USER]>;
|
|
26
|
+
check(): Promise<boolean>;
|
|
27
|
+
hasScope(...scopes: string[]): boolean;
|
|
28
|
+
hasAnyScope(...scopes: string[]): boolean;
|
|
29
|
+
authenticateAsClient(user: UserProvider[typeof symbols.PROVIDER_REAL_USER]): Promise<AuthClientResponse>;
|
|
30
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { HttpContext } from '@adonisjs/core/http';
|
|
2
|
+
import type { GuardConfigProvider } from '@adonisjs/auth/types';
|
|
3
|
+
import type { LucidModel } from '@adonisjs/lucid/types/model';
|
|
4
|
+
import { OAuthGuard } from './guard.ts';
|
|
5
|
+
import { OAuthLucidUserProvider } from './user_provider.ts';
|
|
6
|
+
import type { OAuthLucidUserProviderOptions, OAuthUserProviderContract } from './types.ts';
|
|
7
|
+
export { OAuthGuard } from './guard.ts';
|
|
8
|
+
export { OAuthLucidUserProvider } from './user_provider.ts';
|
|
9
|
+
export type { OAuthGuardUser, OAuthGuardEvents, OAuthUserProviderContract, OAuthLucidUserProviderOptions, } from './types.ts';
|
|
10
|
+
/**
|
|
11
|
+
* Configure the OAuth guard for `@adonisjs/auth`.
|
|
12
|
+
*/
|
|
13
|
+
export declare function oauthGuard<UserProvider extends OAuthUserProviderContract<unknown>>(config: {
|
|
14
|
+
provider: UserProvider;
|
|
15
|
+
resource?: string;
|
|
16
|
+
}): GuardConfigProvider<(ctx: HttpContext) => OAuthGuard<UserProvider>>;
|
|
17
|
+
/**
|
|
18
|
+
* Create a Lucid-based user provider for the OAuth guard.
|
|
19
|
+
*/
|
|
20
|
+
export declare function oauthUserProvider<Model extends LucidModel>(options: OAuthLucidUserProviderOptions<Model>): OAuthLucidUserProvider<Model>;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import "../../decorate-2_8Ex77k.js";
|
|
2
|
+
import "../../oauth_access_token-BpG8sq-c.js";
|
|
3
|
+
import "../../oauth_client-eh0e5ql-.js";
|
|
4
|
+
import "../../token_service-Czz9v5GI.js";
|
|
5
|
+
import { n as OAuthGuard, t as OAuthLucidUserProvider } from "../../user_provider-B3rXEUT3.js";
|
|
6
|
+
function oauthGuard(config) {
|
|
7
|
+
return { async resolver(name, app) {
|
|
8
|
+
const emitter = await app.container.make("emitter");
|
|
9
|
+
const { SesameManager } = await import("../../sesame_manager-B4tO2PLO.js").then((n) => n.n);
|
|
10
|
+
const manager = await app.container.make(SesameManager);
|
|
11
|
+
return (ctx) => new OAuthGuard(name, ctx, emitter, config.provider, manager, config.resource);
|
|
12
|
+
} };
|
|
13
|
+
}
|
|
14
|
+
function oauthUserProvider(options) {
|
|
15
|
+
return new OAuthLucidUserProvider(options);
|
|
16
|
+
}
|
|
17
|
+
export { OAuthGuard, OAuthLucidUserProvider, oauthGuard, oauthUserProvider };
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import type { HttpContext } from '@adonisjs/core/http';
|
|
2
|
+
import type { Exception } from '@adonisjs/core/exceptions';
|
|
3
|
+
import type { LucidModel } from '@adonisjs/lucid/types/model';
|
|
4
|
+
import { symbols } from '@adonisjs/auth';
|
|
5
|
+
/**
|
|
6
|
+
* Guard user adapter between the user provider and the guard.
|
|
7
|
+
*/
|
|
8
|
+
export type OAuthGuardUser<RealUser> = {
|
|
9
|
+
getId(): string | number | BigInt;
|
|
10
|
+
getOriginal(): RealUser;
|
|
11
|
+
};
|
|
12
|
+
/**
|
|
13
|
+
* Contract for user providers used by the OAuth guard.
|
|
14
|
+
*/
|
|
15
|
+
export interface OAuthUserProviderContract<RealUser> {
|
|
16
|
+
[symbols.PROVIDER_REAL_USER]: RealUser;
|
|
17
|
+
createUserForGuard(user: RealUser): Promise<OAuthGuardUser<RealUser>>;
|
|
18
|
+
findById(identifier: string | number | BigInt): Promise<OAuthGuardUser<RealUser> | null>;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Options for the Lucid-based OAuth user provider.
|
|
22
|
+
*/
|
|
23
|
+
export type OAuthLucidUserProviderOptions<Model extends LucidModel> = {
|
|
24
|
+
model: () => Promise<{
|
|
25
|
+
default: Model;
|
|
26
|
+
}>;
|
|
27
|
+
};
|
|
28
|
+
/**
|
|
29
|
+
* Events emitted by the OAuth guard during authentication.
|
|
30
|
+
*/
|
|
31
|
+
export type OAuthGuardEvents<RealUser> = {
|
|
32
|
+
'oauth_auth:authentication_attempted': {
|
|
33
|
+
ctx: HttpContext;
|
|
34
|
+
guardName: string;
|
|
35
|
+
};
|
|
36
|
+
'oauth_auth:authentication_succeeded': {
|
|
37
|
+
ctx: HttpContext;
|
|
38
|
+
guardName: string;
|
|
39
|
+
user: RealUser;
|
|
40
|
+
};
|
|
41
|
+
'oauth_auth:authentication_failed': {
|
|
42
|
+
ctx: HttpContext;
|
|
43
|
+
guardName: string;
|
|
44
|
+
error: Exception;
|
|
45
|
+
};
|
|
46
|
+
};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { symbols } from '@adonisjs/auth';
|
|
2
|
+
import type { LucidModel } from '@adonisjs/lucid/types/model';
|
|
3
|
+
import type { OAuthGuardUser, OAuthLucidUserProviderOptions, OAuthUserProviderContract } from './types.ts';
|
|
4
|
+
/**
|
|
5
|
+
* Lucid-based user provider for the OAuth guard.
|
|
6
|
+
* Lazily loads the model and wraps instances as guard users.
|
|
7
|
+
*/
|
|
8
|
+
export declare class OAuthLucidUserProvider<Model extends LucidModel> implements OAuthUserProviderContract<InstanceType<Model>> {
|
|
9
|
+
#private;
|
|
10
|
+
[symbols.PROVIDER_REAL_USER]: InstanceType<Model>;
|
|
11
|
+
constructor(options: OAuthLucidUserProviderOptions<Model>);
|
|
12
|
+
createUserForGuard(user: InstanceType<Model>): Promise<OAuthGuardUser<InstanceType<Model>>>;
|
|
13
|
+
findById(identifier: string | number | BigInt): Promise<OAuthGuardUser<InstanceType<Model>> | null>;
|
|
14
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { DateTime } from 'luxon';
|
|
2
|
+
import { BaseModel } from '@adonisjs/lucid/orm';
|
|
3
|
+
/**
|
|
4
|
+
* Database record for an issued OAuth 2.0 access token.
|
|
5
|
+
*
|
|
6
|
+
* Access tokens are opaque random values. Only the SHA-256 hash
|
|
7
|
+
* is stored so raw tokens cannot be reconstructed from a DB leak.
|
|
8
|
+
* A token is considered revoked when `revokedAt` is set.
|
|
9
|
+
*
|
|
10
|
+
* @see https://datatracker.ietf.org/doc/html/rfc7662
|
|
11
|
+
*/
|
|
12
|
+
export declare class OAuthAccessToken extends BaseModel {
|
|
13
|
+
static table: string;
|
|
14
|
+
id: string;
|
|
15
|
+
tokenHash: string;
|
|
16
|
+
clientId: string;
|
|
17
|
+
userId: string | null;
|
|
18
|
+
scopes: string[];
|
|
19
|
+
expiresAt: DateTime;
|
|
20
|
+
revokedAt: DateTime | null;
|
|
21
|
+
createdAt: DateTime;
|
|
22
|
+
updatedAt: DateTime;
|
|
23
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { DateTime } from 'luxon';
|
|
2
|
+
import { BaseModel } from '@adonisjs/lucid/orm';
|
|
3
|
+
/**
|
|
4
|
+
* Database record for an OAuth 2.0 authorization code (RFC 6749 §4.1.2).
|
|
5
|
+
*
|
|
6
|
+
* Authorization codes are short-lived, single-use tokens issued
|
|
7
|
+
* during the authorization flow. The `code` column stores the
|
|
8
|
+
* SHA-256 hash of the raw code value sent to the client.
|
|
9
|
+
*
|
|
10
|
+
* When PKCE (RFC 7636) is used, the `codeChallenge` and
|
|
11
|
+
* `codeChallengeMethod` (always S256) are stored alongside the
|
|
12
|
+
* code for verification at the token endpoint.
|
|
13
|
+
*
|
|
14
|
+
* @see https://datatracker.ietf.org/doc/html/rfc6749#section-4.1.2
|
|
15
|
+
* @see https://datatracker.ietf.org/doc/html/rfc7636
|
|
16
|
+
*/
|
|
17
|
+
export declare class OAuthAuthorizationCode extends BaseModel {
|
|
18
|
+
static table: string;
|
|
19
|
+
id: string;
|
|
20
|
+
code: string;
|
|
21
|
+
clientId: string;
|
|
22
|
+
userId: string;
|
|
23
|
+
scopes: string[];
|
|
24
|
+
redirectUri: string;
|
|
25
|
+
codeChallenge: string | null;
|
|
26
|
+
codeChallengeMethod: string | null;
|
|
27
|
+
expiresAt: DateTime;
|
|
28
|
+
createdAt: DateTime;
|
|
29
|
+
updatedAt: DateTime;
|
|
30
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { DateTime } from 'luxon';
|
|
2
|
+
import { BaseModel } from '@adonisjs/lucid/orm';
|
|
3
|
+
/**
|
|
4
|
+
* Represents a registered OAuth 2.0 client (RFC 6749 §2).
|
|
5
|
+
*
|
|
6
|
+
* Clients can be either confidential (with a hashed secret) or
|
|
7
|
+
* public (no secret, e.g. SPAs, native apps). Public clients must
|
|
8
|
+
* use PKCE (RFC 7636) for authorization code exchanges.
|
|
9
|
+
*
|
|
10
|
+
* Clients may be created manually or via dynamic client registration
|
|
11
|
+
* (RFC 7591) through the `/oauth/register` endpoint.
|
|
12
|
+
*
|
|
13
|
+
* @see https://datatracker.ietf.org/doc/html/rfc6749#section-2
|
|
14
|
+
* @see https://datatracker.ietf.org/doc/html/rfc7591
|
|
15
|
+
*/
|
|
16
|
+
export declare class OAuthClient extends BaseModel {
|
|
17
|
+
static table: string;
|
|
18
|
+
id: string;
|
|
19
|
+
clientId: string;
|
|
20
|
+
clientSecret: string | null;
|
|
21
|
+
name: string;
|
|
22
|
+
redirectUris: string[];
|
|
23
|
+
scopes: string[];
|
|
24
|
+
grantTypes: string[];
|
|
25
|
+
isPublic: boolean;
|
|
26
|
+
isDisabled: boolean;
|
|
27
|
+
requirePkce: boolean;
|
|
28
|
+
type: string | null;
|
|
29
|
+
metadata: Record<string, any> | null;
|
|
30
|
+
userId: string | null;
|
|
31
|
+
createdAt: DateTime;
|
|
32
|
+
updatedAt: DateTime;
|
|
33
|
+
}
|