@julr/sesame 0.5.1 → 0.7.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 +1 -1
- package/README.md +470 -64
- package/build/authorize_controller-sCZIjnc-.js +251 -0
- package/build/{client_info_controller-BucHGx4u.js → client_info_controller-B5A3tpbk.js} +11 -4
- package/build/commands/sesame_client.d.ts +20 -0
- package/build/commands/sesame_key.d.ts +12 -0
- package/build/commands/sesame_purge.d.ts +0 -2
- package/build/commands/sesame_purge.js +12 -3
- package/build/configure-t9q3KonY.js +31 -0
- package/build/configure.js +1 -24
- package/build/consent_controller-ChBboaSd.js +96 -0
- package/build/consent_retry-DMkfhmk9.js +41 -0
- package/build/{decorate-BKZEjPRg.js → decorate-RQD1h28J.js} +3 -9
- package/build/id_token_service-BtBUiL_n.js +54 -0
- package/build/index.d.ts +2 -8
- package/build/index.js +59 -10
- package/build/{introspect_controller-6bRt9sZt.js → introspect_controller-LVYGWhMj.js} +28 -10
- package/build/issue_authorization_code-Dr4-bbMp.js +39 -0
- package/build/jwks_controller-4HUVS_HC.js +22 -0
- package/build/{main-EbeMS5S9.js → main-Dx9kZv07.js} +35 -43
- package/build/{metadata_controller-DeaMRnUr.js → metadata_controller-hwfmxlF7.js} +81 -6
- package/build/oauth_error-CvxtZvjp.js +189 -0
- package/build/providers/sesame_provider.d.ts +1 -1
- package/build/providers/sesame_provider.js +17 -6
- package/build/{register_controller-sIJ1rxdM.js → register_controller-Cdk3c32j.js} +44 -8
- package/build/revoke_controller-Daz4Yqfs.js +48 -0
- package/build/services/main.js +3 -3
- package/build/sesame_manager-CeEmlzba.js +515 -0
- package/build/sesame_manager-DQxvsTEq.js +2 -0
- package/build/src/actions/authorize.d.ts +46 -0
- package/build/src/actions/exchange_authorization_code.d.ts +34 -0
- package/build/src/actions/exchange_client_credentials.d.ts +28 -0
- package/build/src/actions/exchange_refresh_token.d.ts +59 -0
- package/build/src/actions/issue_authorization_code.d.ts +26 -0
- package/build/src/controllers/authorize_controller.d.ts +18 -17
- package/build/src/controllers/consent_controller.d.ts +5 -0
- package/build/src/controllers/jwks_controller.d.ts +14 -0
- package/build/src/controllers/metadata_controller.d.ts +10 -3
- package/build/src/controllers/register_controller.d.ts +30 -30
- package/build/src/controllers/token_controller.d.ts +8 -5
- package/build/src/controllers/userinfo_controller.d.ts +14 -0
- package/build/src/guard/guard.d.ts +1 -1
- package/build/src/guard/lucid.d.ts +8 -0
- package/build/src/guard/lucid.js +46 -0
- package/build/src/guard/main.d.ts +2 -9
- package/build/src/guard/main.js +2 -6
- package/build/src/guard/types.d.ts +0 -9
- package/build/src/guard/user_provider.d.ts +9 -1
- package/build/src/middleware/any_scope_middleware.js +10 -1
- package/build/src/middleware/scope_middleware.js +10 -1
- package/build/src/models/oauth_authorization_code.d.ts +1 -0
- package/build/src/models/oauth_pending_authorization_request.d.ts +1 -0
- package/build/src/oauth_error.d.ts +74 -74
- package/build/src/routes.d.ts +3 -1
- package/build/src/services/client_service.d.ts +5 -2
- package/build/src/services/id_token_service.d.ts +30 -0
- package/build/src/services/key_service.d.ts +20 -0
- package/build/src/sesame_manager.d.ts +56 -4
- package/build/src/storage/consent_retry.d.ts +4 -0
- package/build/src/storage/drivers/kysely.d.ts +166 -0
- package/build/src/storage/drivers/kysely.js +480 -0
- package/build/src/storage/drivers/lucid.d.ts +162 -0
- package/build/src/storage/drivers/lucid.js +549 -0
- package/build/src/storage/migrations/kysely.d.ts +6 -0
- package/build/src/storage/types.d.ts +197 -0
- package/build/src/storage/types.js +1 -0
- package/build/src/stores.d.ts +21 -0
- package/build/src/types.d.ts +120 -0
- package/build/src/types.js +2 -0
- package/build/stubs/config/sesame.stub +4 -1
- package/build/stubs/config/sesame_kysely.stub +35 -0
- package/build/stubs/main.ts +5 -0
- package/build/stubs/migrations/create_oauth_authorization_codes_table.stub +1 -0
- package/build/stubs/migrations/create_oauth_pending_authorization_requests_table.stub +1 -0
- package/build/stubs/migrations/create_oauth_refresh_tokens_table.stub +1 -1
- package/build/stubs/migrations/kysely/create_oauth_tables.stub +151 -0
- package/build/taze.config.d.ts +2 -0
- package/build/token_controller-DRatCQNT.js +492 -0
- package/build/token_service-DDQ3Dxaj.js +59 -0
- package/build/types-DEtn2Zdb.js +75 -0
- package/build/userinfo_controller-YwN26wK-.js +37 -0
- package/build/vite.config.d.ts +2 -0
- package/package.json +55 -54
- package/build/authorize_controller-YUfAy-R2.js +0 -138
- package/build/client_service-WTNMqWzY.js +0 -65
- package/build/consent_controller-Dprwd1ed.js +0 -85
- package/build/oauth_access_token-bsoM5KeU.js +0 -18
- package/build/oauth_client-BIoY5jBR.js +0 -24
- package/build/oauth_error-CnJ3L8tf.js +0 -94
- package/build/revoke_controller-D6isoQCi.js +0 -41
- package/build/sesame_manager-Bu4MHqZV.js +0 -4
- package/build/sesame_manager-DwDZy5Vy.js +0 -167
- package/build/src/grants/authorization_code_grant.d.ts +0 -23
- package/build/src/grants/client_credentials_grant.d.ts +0 -23
- package/build/src/grants/refresh_token_grant.d.ts +0 -27
- package/build/token_controller-DzcrLMyS.js +0 -194
- package/build/token_service-fhoA4slP.js +0 -31
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type { SesameManager } from '../sesame_manager.ts';
|
|
2
|
+
import type { OAuthClientRecord } from '../storage/types.ts';
|
|
3
|
+
export interface AuthorizationCodeInput {
|
|
4
|
+
client: OAuthClientRecord;
|
|
5
|
+
userId: string;
|
|
6
|
+
scopes: string[];
|
|
7
|
+
redirectUri: string;
|
|
8
|
+
codeChallenge?: string;
|
|
9
|
+
codeChallengeMethod?: string;
|
|
10
|
+
nonce?: string;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Create and persist an authorization code in the database.
|
|
14
|
+
* Returns the raw (unhashed) code to be sent to the client.
|
|
15
|
+
*
|
|
16
|
+
* Shared between the authorize and consent flows to avoid
|
|
17
|
+
* duplicating the code-issuance logic.
|
|
18
|
+
*/
|
|
19
|
+
export declare class IssueAuthorizationCodeAction {
|
|
20
|
+
/**
|
|
21
|
+
* Generate an opaque authorization code, store its SHA-256
|
|
22
|
+
* hash in the database, and return the raw value for the
|
|
23
|
+
* client redirect.
|
|
24
|
+
*/
|
|
25
|
+
execute(manager: SesameManager, input: AuthorizationCodeInput): Promise<string>;
|
|
26
|
+
}
|
|
@@ -2,17 +2,10 @@ import type { HttpContext } from '@adonisjs/core/http';
|
|
|
2
2
|
/**
|
|
3
3
|
* Handles the OAuth 2.0 Authorization Endpoint (RFC 6749 §3.1).
|
|
4
4
|
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
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.
|
|
5
|
+
* Validates HTTP parameters, delegates business logic to
|
|
6
|
+
* AuthorizeAction, and interprets the result as redirects.
|
|
12
7
|
*
|
|
13
8
|
* @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
9
|
*/
|
|
17
10
|
export default class AuthorizeController {
|
|
18
11
|
#private;
|
|
@@ -24,30 +17,38 @@ export default class AuthorizeController {
|
|
|
24
17
|
state: import("@vinejs/vine/schema/base/literal").OptionalModifier<import("@vinejs/vine").VineString>;
|
|
25
18
|
code_challenge: import("@vinejs/vine/schema/base/literal").OptionalModifier<import("@vinejs/vine").VineString>;
|
|
26
19
|
code_challenge_method: import("@vinejs/vine/schema/base/literal").OptionalModifier<import("@vinejs/vine").VineString>;
|
|
20
|
+
nonce: import("@vinejs/vine/schema/base/literal").OptionalModifier<import("@vinejs/vine").VineString>;
|
|
27
21
|
}, {
|
|
28
|
-
|
|
29
|
-
state?: string | null | undefined;
|
|
22
|
+
client_id: string;
|
|
30
23
|
code_challenge?: string | null | undefined;
|
|
31
24
|
code_challenge_method?: string | null | undefined;
|
|
25
|
+
nonce?: string | null | undefined;
|
|
32
26
|
redirect_uri: string;
|
|
33
|
-
client_id: string;
|
|
34
27
|
response_type: string;
|
|
28
|
+
scope?: string | null | undefined;
|
|
29
|
+
state?: string | null | undefined;
|
|
35
30
|
}, {
|
|
36
|
-
|
|
37
|
-
state?: string | undefined;
|
|
31
|
+
client_id: string;
|
|
38
32
|
code_challenge?: string | undefined;
|
|
39
33
|
code_challenge_method?: string | undefined;
|
|
34
|
+
nonce?: string | undefined;
|
|
40
35
|
redirect_uri: string;
|
|
41
|
-
client_id: string;
|
|
42
36
|
response_type: string;
|
|
43
|
-
}, {
|
|
44
37
|
scope?: string | undefined;
|
|
45
38
|
state?: string | undefined;
|
|
39
|
+
}, {
|
|
40
|
+
client_id: string;
|
|
46
41
|
code_challenge?: string | undefined;
|
|
47
42
|
code_challenge_method?: string | undefined;
|
|
43
|
+
nonce?: string | undefined;
|
|
48
44
|
redirect_uri: string;
|
|
49
|
-
client_id: string;
|
|
50
45
|
response_type: string;
|
|
46
|
+
scope?: string | undefined;
|
|
47
|
+
state?: string | undefined;
|
|
51
48
|
}>, Record<string, any> | undefined>;
|
|
49
|
+
/**
|
|
50
|
+
* Validate the authorization request query params, run the
|
|
51
|
+
* authorize action, and redirect based on the result.
|
|
52
|
+
*/
|
|
52
53
|
handle(ctx: HttpContext): Promise<void>;
|
|
53
54
|
}
|
|
@@ -23,5 +23,10 @@ export default class ConsentController {
|
|
|
23
23
|
}, {
|
|
24
24
|
auth_token: string;
|
|
25
25
|
}>, Record<string, any> | undefined>;
|
|
26
|
+
/**
|
|
27
|
+
* Validate the consent submission, consume the pending
|
|
28
|
+
* request, and redirect back to the client with either
|
|
29
|
+
* an authorization code or an access_denied error.
|
|
30
|
+
*/
|
|
26
31
|
handle(ctx: HttpContext): Promise<void>;
|
|
27
32
|
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { HttpContext } from '@adonisjs/core/http';
|
|
2
|
+
/**
|
|
3
|
+
* Serves the JSON Web Key Set (JWKS) containing public keys
|
|
4
|
+
* used to verify ID token signatures.
|
|
5
|
+
*
|
|
6
|
+
* @see https://datatracker.ietf.org/doc/html/rfc7517
|
|
7
|
+
*/
|
|
8
|
+
export default class JwksController {
|
|
9
|
+
handle(ctx: HttpContext): Promise<{
|
|
10
|
+
keys: import("jose").JWK[];
|
|
11
|
+
} | {
|
|
12
|
+
error: string;
|
|
13
|
+
}>;
|
|
14
|
+
}
|
|
@@ -34,15 +34,14 @@ export default class MetadataController {
|
|
|
34
34
|
* @see https://openid.net/specs/openid-connect-discovery-1_0.html#ProviderMetadata
|
|
35
35
|
*/
|
|
36
36
|
oidc(ctx: HttpContext): Promise<{
|
|
37
|
-
|
|
38
|
-
|
|
37
|
+
error: string;
|
|
38
|
+
} | {
|
|
39
39
|
issuer: string;
|
|
40
40
|
authorization_endpoint: string;
|
|
41
41
|
token_endpoint: string;
|
|
42
42
|
registration_endpoint?: string;
|
|
43
43
|
introspection_endpoint?: string;
|
|
44
44
|
revocation_endpoint?: string;
|
|
45
|
-
response_types_supported: string[];
|
|
46
45
|
response_modes_supported: string[];
|
|
47
46
|
grant_types_supported: string[];
|
|
48
47
|
token_endpoint_auth_methods_supported: string[];
|
|
@@ -50,6 +49,14 @@ export default class MetadataController {
|
|
|
50
49
|
revocation_endpoint_auth_methods_supported?: string[];
|
|
51
50
|
code_challenge_methods_supported: string[];
|
|
52
51
|
authorization_response_iss_parameter_supported: boolean;
|
|
52
|
+
error?: undefined;
|
|
53
|
+
userinfo_endpoint: string;
|
|
54
|
+
jwks_uri: string;
|
|
55
|
+
subject_types_supported: string[];
|
|
56
|
+
id_token_signing_alg_values_supported: string[];
|
|
57
|
+
scopes_supported: string[];
|
|
58
|
+
claims_supported: string[];
|
|
59
|
+
response_types_supported: string[];
|
|
53
60
|
}>;
|
|
54
61
|
/**
|
|
55
62
|
* OAuth 2.0 Protected Resource Metadata (RFC 9728).
|
|
@@ -28,70 +28,70 @@ export default class RegisterController {
|
|
|
28
28
|
software_id: import("@vinejs/vine/schema/base/literal").OptionalModifier<import("@vinejs/vine").VineString>;
|
|
29
29
|
software_version: import("@vinejs/vine/schema/base/literal").OptionalModifier<import("@vinejs/vine").VineString>;
|
|
30
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
31
|
client_name?: string | null | undefined;
|
|
36
32
|
client_uri?: string | null | undefined;
|
|
33
|
+
contacts?: string[] | null | undefined;
|
|
34
|
+
grant_types?: string[] | null | undefined;
|
|
37
35
|
logo_uri?: string | null | undefined;
|
|
38
|
-
tos_uri?: string | null | undefined;
|
|
39
36
|
policy_uri?: string | null | undefined;
|
|
40
|
-
|
|
37
|
+
redirect_uris: string[];
|
|
38
|
+
response_types?: string[] | null | undefined;
|
|
39
|
+
scope?: string | null | undefined;
|
|
41
40
|
software_id?: string | null | undefined;
|
|
42
41
|
software_version?: string | null | undefined;
|
|
43
|
-
|
|
42
|
+
token_endpoint_auth_method?: string | null | undefined;
|
|
43
|
+
tos_uri?: string | null | undefined;
|
|
44
44
|
} & {
|
|
45
45
|
[K: string]: unknown;
|
|
46
46
|
}, {
|
|
47
|
-
scope?: string | undefined;
|
|
48
|
-
token_endpoint_auth_method?: string | undefined;
|
|
49
|
-
grant_types?: string[] | undefined;
|
|
50
|
-
response_types?: string[] | undefined;
|
|
51
47
|
client_name?: string | undefined;
|
|
52
48
|
client_uri?: string | undefined;
|
|
49
|
+
contacts?: string[] | undefined;
|
|
50
|
+
grant_types?: string[] | undefined;
|
|
53
51
|
logo_uri?: string | undefined;
|
|
54
|
-
tos_uri?: string | undefined;
|
|
55
52
|
policy_uri?: string | undefined;
|
|
56
|
-
|
|
53
|
+
redirect_uris: string[];
|
|
54
|
+
response_types?: string[] | undefined;
|
|
55
|
+
scope?: string | undefined;
|
|
57
56
|
software_id?: string | undefined;
|
|
58
57
|
software_version?: string | undefined;
|
|
59
|
-
|
|
58
|
+
token_endpoint_auth_method?: string | undefined;
|
|
59
|
+
tos_uri?: string | undefined;
|
|
60
60
|
} & {
|
|
61
61
|
[K: string]: unknown;
|
|
62
62
|
}, {
|
|
63
|
-
grantTypes?: string[] | undefined;
|
|
64
|
-
scope?: string | undefined;
|
|
65
|
-
contacts?: string[] | undefined;
|
|
66
|
-
tokenEndpointAuthMethod?: string | undefined;
|
|
67
|
-
responseTypes?: string[] | undefined;
|
|
68
63
|
clientName?: string | undefined;
|
|
69
64
|
clientUri?: string | undefined;
|
|
65
|
+
contacts?: string[] | undefined;
|
|
66
|
+
grantTypes?: string[] | undefined;
|
|
70
67
|
logoUri?: string | undefined;
|
|
71
|
-
tosUri?: string | undefined;
|
|
72
68
|
policyUri?: string | undefined;
|
|
69
|
+
redirectUris: string[];
|
|
70
|
+
responseTypes?: string[] | undefined;
|
|
71
|
+
scope?: string | undefined;
|
|
73
72
|
softwareId?: string | undefined;
|
|
74
73
|
softwareVersion?: string | undefined;
|
|
75
|
-
|
|
74
|
+
tokenEndpointAuthMethod?: string | undefined;
|
|
75
|
+
tosUri?: string | undefined;
|
|
76
76
|
} & {
|
|
77
77
|
[K: string]: unknown;
|
|
78
78
|
}>, Record<string, any> | undefined>;
|
|
79
79
|
handle(ctx: HttpContext): Promise<{
|
|
80
|
-
software_version?: string | undefined;
|
|
81
|
-
software_id?: string | undefined;
|
|
82
|
-
policy_uri?: string | undefined;
|
|
83
|
-
tos_uri?: string | undefined;
|
|
84
|
-
contacts?: string[] | undefined;
|
|
85
|
-
logo_uri?: string | undefined;
|
|
86
|
-
client_uri?: string | undefined;
|
|
87
80
|
token_endpoint_auth_method: string;
|
|
88
81
|
response_types: string[];
|
|
82
|
+
client_uri?: string | undefined;
|
|
83
|
+
logo_uri?: string | undefined;
|
|
84
|
+
contacts?: string[] | undefined;
|
|
85
|
+
tos_uri?: string | undefined;
|
|
86
|
+
policy_uri?: string | undefined;
|
|
87
|
+
software_id?: string | undefined;
|
|
88
|
+
software_version?: string | undefined;
|
|
89
|
+
client_id: string;
|
|
90
|
+
client_secret?: string | undefined;
|
|
89
91
|
client_secret_expires_at: number;
|
|
90
92
|
client_name: string;
|
|
91
93
|
redirect_uris: string[];
|
|
92
94
|
grant_types: string[];
|
|
93
95
|
scope: string;
|
|
94
|
-
client_secret?: string | undefined;
|
|
95
|
-
client_id: string;
|
|
96
96
|
}>;
|
|
97
97
|
}
|
|
@@ -2,15 +2,14 @@ import type { HttpContext } from '@adonisjs/core/http';
|
|
|
2
2
|
/**
|
|
3
3
|
* Handles the OAuth 2.0 Token Endpoint (RFC 6749 §3.2).
|
|
4
4
|
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
* by the spec.
|
|
5
|
+
* Authenticates the client, extracts grant-specific params,
|
|
6
|
+
* and dispatches to the appropriate action. Sets required
|
|
7
|
+
* cache headers on all token responses.
|
|
9
8
|
*
|
|
10
9
|
* @see https://datatracker.ietf.org/doc/html/rfc6749#section-3.2
|
|
11
|
-
* @see https://datatracker.ietf.org/doc/html/rfc6749#section-5.1
|
|
12
10
|
*/
|
|
13
11
|
export default class TokenController {
|
|
12
|
+
#private;
|
|
14
13
|
static validator: import("@vinejs/vine").VineValidator<import("@vinejs/vine").VineObject<{
|
|
15
14
|
grant_type: import("@vinejs/vine").VineString;
|
|
16
15
|
}, {
|
|
@@ -20,5 +19,9 @@ export default class TokenController {
|
|
|
20
19
|
}, {
|
|
21
20
|
grant_type: string;
|
|
22
21
|
}>, Record<string, any> | undefined>;
|
|
22
|
+
/**
|
|
23
|
+
* Validate the grant type, authenticate the client,
|
|
24
|
+
* and dispatch to the appropriate grant action.
|
|
25
|
+
*/
|
|
23
26
|
handle(ctx: HttpContext): Promise<any>;
|
|
24
27
|
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { HttpContext } from '@adonisjs/core/http';
|
|
2
|
+
/**
|
|
3
|
+
* OpenID Connect UserInfo endpoint (OIDC Core §5.3).
|
|
4
|
+
*
|
|
5
|
+
* Returns claims about the authenticated user based on the
|
|
6
|
+
* access token's scopes. Supports both GET and POST.
|
|
7
|
+
*
|
|
8
|
+
* @see https://openid.net/specs/openid-connect-core-1_0.html#UserInfo
|
|
9
|
+
*/
|
|
10
|
+
export default class UserinfoController {
|
|
11
|
+
handle(ctx: HttpContext): Promise<{
|
|
12
|
+
sub: string | null;
|
|
13
|
+
}>;
|
|
14
|
+
}
|
|
@@ -15,7 +15,7 @@ import type { OAuthGuardEvents, OAuthUserProviderContract } from './types.ts';
|
|
|
15
15
|
export declare class OAuthGuard<UserProvider extends OAuthUserProviderContract<unknown>> implements GuardContract<UserProvider[typeof symbols.PROVIDER_REAL_USER]> {
|
|
16
16
|
#private;
|
|
17
17
|
[symbols.GUARD_KNOWN_EVENTS]: OAuthGuardEvents<UserProvider[typeof symbols.PROVIDER_REAL_USER]>;
|
|
18
|
-
driverName:
|
|
18
|
+
driverName: 'oauth';
|
|
19
19
|
authenticationAttempted: boolean;
|
|
20
20
|
isAuthenticated: boolean;
|
|
21
21
|
user?: UserProvider[typeof symbols.PROVIDER_REAL_USER];
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { LucidModel } from '@adonisjs/lucid/types/model';
|
|
2
|
+
import { OAuthLucidUserProvider, type OAuthLucidUserProviderOptions } from './user_provider.ts';
|
|
3
|
+
export { OAuthLucidUserProvider } from './user_provider.ts';
|
|
4
|
+
export type { OAuthLucidUserProviderOptions } from './user_provider.ts';
|
|
5
|
+
/**
|
|
6
|
+
* Create a Lucid-based user provider for the OAuth guard.
|
|
7
|
+
*/
|
|
8
|
+
export declare function oauthUserProvider<Model extends LucidModel>(options: OAuthLucidUserProviderOptions<Model>): OAuthLucidUserProvider<Model>;
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { RuntimeException } from "@adonisjs/core/exceptions";
|
|
2
|
+
//#region src/guard/user_provider.ts
|
|
3
|
+
/**
|
|
4
|
+
* Lucid-based user provider for the OAuth guard.
|
|
5
|
+
* Lazily loads the model and wraps instances as guard users.
|
|
6
|
+
*/
|
|
7
|
+
var OAuthLucidUserProvider = class {
|
|
8
|
+
#model;
|
|
9
|
+
#options;
|
|
10
|
+
constructor(options) {
|
|
11
|
+
this.#options = options;
|
|
12
|
+
}
|
|
13
|
+
async #getModel() {
|
|
14
|
+
if (this.#model && !("hot" in import.meta)) return this.#model;
|
|
15
|
+
this.#model = (await this.#options.model()).default;
|
|
16
|
+
return this.#model;
|
|
17
|
+
}
|
|
18
|
+
async createUserForGuard(user) {
|
|
19
|
+
const model = await this.#getModel();
|
|
20
|
+
if (user instanceof model === false) throw new RuntimeException(`Invalid user object. It must be an instance of the "${model.name}" model`);
|
|
21
|
+
return {
|
|
22
|
+
getId() {
|
|
23
|
+
if (!user.$primaryKeyValue) throw new RuntimeException(`Cannot use "${model.name}" model for authentication. The value of column "${model.primaryKey}" is undefined or null`);
|
|
24
|
+
return user.$primaryKeyValue;
|
|
25
|
+
},
|
|
26
|
+
getOriginal() {
|
|
27
|
+
return user;
|
|
28
|
+
}
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
async findById(identifier) {
|
|
32
|
+
const user = await (await this.#getModel()).find(identifier);
|
|
33
|
+
if (!user) return null;
|
|
34
|
+
return this.createUserForGuard(user);
|
|
35
|
+
}
|
|
36
|
+
};
|
|
37
|
+
//#endregion
|
|
38
|
+
//#region src/guard/lucid.ts
|
|
39
|
+
/**
|
|
40
|
+
* Create a Lucid-based user provider for the OAuth guard.
|
|
41
|
+
*/
|
|
42
|
+
function oauthUserProvider(options) {
|
|
43
|
+
return new OAuthLucidUserProvider(options);
|
|
44
|
+
}
|
|
45
|
+
//#endregion
|
|
46
|
+
export { OAuthLucidUserProvider, oauthUserProvider };
|
|
@@ -1,12 +1,9 @@
|
|
|
1
1
|
import type { HttpContext } from '@adonisjs/core/http';
|
|
2
2
|
import type { GuardConfigProvider } from '@adonisjs/auth/types';
|
|
3
|
-
import type { LucidModel } from '@adonisjs/lucid/types/model';
|
|
4
3
|
import { OAuthGuard } from './guard.ts';
|
|
5
|
-
import {
|
|
6
|
-
import type { OAuthLucidUserProviderOptions, OAuthUserProviderContract } from './types.ts';
|
|
4
|
+
import type { OAuthUserProviderContract } from './types.ts';
|
|
7
5
|
export { OAuthGuard } from './guard.ts';
|
|
8
|
-
export {
|
|
9
|
-
export type { OAuthGuardUser, OAuthGuardEvents, OAuthUserProviderContract, OAuthLucidUserProviderOptions, } from './types.ts';
|
|
6
|
+
export type { OAuthGuardUser, OAuthGuardEvents, OAuthUserProviderContract } from './types.ts';
|
|
10
7
|
/**
|
|
11
8
|
* Configure the OAuth guard for `@adonisjs/auth`.
|
|
12
9
|
*/
|
|
@@ -14,7 +11,3 @@ export declare function oauthGuard<UserProvider extends OAuthUserProviderContrac
|
|
|
14
11
|
provider: UserProvider;
|
|
15
12
|
resource?: string;
|
|
16
13
|
}): 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>;
|
package/build/src/guard/main.js
CHANGED
|
@@ -1,6 +1,2 @@
|
|
|
1
|
-
import "../../
|
|
2
|
-
|
|
3
|
-
import "../../oauth_client-BIoY5jBR.js";
|
|
4
|
-
import "../../token_service-fhoA4slP.js";
|
|
5
|
-
import { i as OAuthGuard, n as oauthUserProvider, r as OAuthLucidUserProvider, t as oauthGuard } from "../../main-EbeMS5S9.js";
|
|
6
|
-
export { OAuthGuard, OAuthLucidUserProvider, oauthGuard, oauthUserProvider };
|
|
1
|
+
import { n as OAuthGuard, t as oauthGuard } from "../../main-Dx9kZv07.js";
|
|
2
|
+
export { OAuthGuard, oauthGuard };
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import type { HttpContext } from '@adonisjs/core/http';
|
|
2
2
|
import type { Exception } from '@adonisjs/core/exceptions';
|
|
3
|
-
import type { LucidModel } from '@adonisjs/lucid/types/model';
|
|
4
3
|
import { symbols } from '@adonisjs/auth';
|
|
5
4
|
/**
|
|
6
5
|
* Guard user adapter between the user provider and the guard.
|
|
@@ -17,14 +16,6 @@ export interface OAuthUserProviderContract<RealUser> {
|
|
|
17
16
|
createUserForGuard(user: RealUser): Promise<OAuthGuardUser<RealUser>>;
|
|
18
17
|
findById(identifier: string | number | BigInt): Promise<OAuthGuardUser<RealUser> | null>;
|
|
19
18
|
}
|
|
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
19
|
/**
|
|
29
20
|
* Events emitted by the OAuth guard during authentication.
|
|
30
21
|
*/
|
|
@@ -1,6 +1,14 @@
|
|
|
1
1
|
import { symbols } from '@adonisjs/auth';
|
|
2
2
|
import type { LucidModel } from '@adonisjs/lucid/types/model';
|
|
3
|
-
import type { OAuthGuardUser,
|
|
3
|
+
import type { OAuthGuardUser, OAuthUserProviderContract } from './types.ts';
|
|
4
|
+
/**
|
|
5
|
+
* Options for the Lucid-based OAuth user provider.
|
|
6
|
+
*/
|
|
7
|
+
export type OAuthLucidUserProviderOptions<Model extends LucidModel> = {
|
|
8
|
+
model: () => Promise<{
|
|
9
|
+
default: Model;
|
|
10
|
+
}>;
|
|
11
|
+
};
|
|
4
12
|
/**
|
|
5
13
|
* Lucid-based user provider for the OAuth guard.
|
|
6
14
|
* Lazily loads the model and wraps instances as guard users.
|
|
@@ -1,4 +1,12 @@
|
|
|
1
|
-
import { n as E_INSUFFICIENT_SCOPE } from "../../oauth_error-
|
|
1
|
+
import { n as E_INSUFFICIENT_SCOPE } from "../../oauth_error-CvxtZvjp.js";
|
|
2
|
+
//#region src/middleware/any_scope_middleware.ts
|
|
3
|
+
/**
|
|
4
|
+
* Any-scope middleware requires ANY of the listed scopes on the
|
|
5
|
+
* authenticated OAuth token. Throws 403 if none match.
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* router.get('/data', [DataController]).use(middleware.anyScope({ scopes: ['read', 'read-all'] }))
|
|
9
|
+
*/
|
|
2
10
|
var AnyScopeMiddleware = class {
|
|
3
11
|
async handle(ctx, next, options) {
|
|
4
12
|
const guard = ctx.auth.use("oauth");
|
|
@@ -15,4 +23,5 @@ var AnyScopeMiddleware = class {
|
|
|
15
23
|
await guard.authenticate();
|
|
16
24
|
}
|
|
17
25
|
};
|
|
26
|
+
//#endregion
|
|
18
27
|
export { AnyScopeMiddleware as default };
|
|
@@ -1,4 +1,12 @@
|
|
|
1
|
-
import { n as E_INSUFFICIENT_SCOPE } from "../../oauth_error-
|
|
1
|
+
import { n as E_INSUFFICIENT_SCOPE } from "../../oauth_error-CvxtZvjp.js";
|
|
2
|
+
//#region src/middleware/scope_middleware.ts
|
|
3
|
+
/**
|
|
4
|
+
* Scope middleware requires ALL listed scopes on the authenticated
|
|
5
|
+
* OAuth token. Throws 403 if any scope is missing.
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* router.get('/admin', [AdminController]).use(middleware.scopes({ scopes: ['admin', 'manage'] }))
|
|
9
|
+
*/
|
|
2
10
|
var ScopeMiddleware = class {
|
|
3
11
|
async handle(ctx, next, options) {
|
|
4
12
|
const guard = ctx.auth.use("oauth");
|
|
@@ -15,4 +23,5 @@ var ScopeMiddleware = class {
|
|
|
15
23
|
await guard.authenticate();
|
|
16
24
|
}
|
|
17
25
|
};
|
|
26
|
+
//#endregion
|
|
18
27
|
export { ScopeMiddleware as default };
|