@julr/sesame 0.6.0 → 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.
Files changed (70) hide show
  1. package/README.md +69 -6
  2. package/build/{authorize_controller-BiycO4be.js → authorize_controller-sCZIjnc-.js} +10 -10
  3. package/build/{client_info_controller-AcOG8lWu.js → client_info_controller-B5A3tpbk.js} +3 -4
  4. package/build/commands/sesame_key.d.ts +1 -1
  5. package/build/commands/sesame_purge.js +2 -5
  6. package/build/{configure-DkDkIlt8.js → configure-t9q3KonY.js} +7 -3
  7. package/build/configure.js +1 -2
  8. package/build/{consent_controller-Dsdhv6-f.js → consent_controller-ChBboaSd.js} +17 -29
  9. package/build/consent_retry-DMkfhmk9.js +41 -0
  10. package/build/decorate-RQD1h28J.js +9 -0
  11. package/build/{id_token_service-CpTzOUDe.js → id_token_service-BtBUiL_n.js} +1 -1
  12. package/build/index.d.ts +2 -8
  13. package/build/index.js +38 -9
  14. package/build/{introspect_controller-DvOp9scr.js → introspect_controller-LVYGWhMj.js} +13 -9
  15. package/build/{issue_authorization_code-B9ERu1uO.js → issue_authorization_code-Dr4-bbMp.js} +2 -3
  16. package/build/{jwks_controller-keo4kBZc.js → jwks_controller-4HUVS_HC.js} +1 -5
  17. package/build/{main-DGBJhq3E.js → main-Dx9kZv07.js} +14 -52
  18. package/build/{metadata_controller-BVsTo0Gp.js → metadata_controller-hwfmxlF7.js} +4 -6
  19. package/build/providers/sesame_provider.d.ts +1 -1
  20. package/build/providers/sesame_provider.js +8 -8
  21. package/build/{register_controller-gbq7p8a5.js → register_controller-Cdk3c32j.js} +3 -6
  22. package/build/{revoke_controller-z_ghrEB7.js → revoke_controller-Daz4Yqfs.js} +15 -21
  23. package/build/services/main.js +1 -5
  24. package/build/{sesame_manager-DYUSZ0NC.js → sesame_manager-CeEmlzba.js} +78 -256
  25. package/build/sesame_manager-DQxvsTEq.js +2 -0
  26. package/build/src/actions/exchange_authorization_code.d.ts +5 -5
  27. package/build/src/actions/exchange_client_credentials.d.ts +3 -3
  28. package/build/src/actions/exchange_refresh_token.d.ts +4 -4
  29. package/build/src/actions/issue_authorization_code.d.ts +2 -2
  30. package/build/src/controllers/authorize_controller.d.ts +11 -11
  31. package/build/src/controllers/metadata_controller.d.ts +7 -7
  32. package/build/src/controllers/register_controller.d.ts +30 -30
  33. package/build/src/guard/guard.d.ts +1 -1
  34. package/build/src/guard/lucid.d.ts +8 -0
  35. package/build/src/guard/lucid.js +46 -0
  36. package/build/src/guard/main.d.ts +2 -9
  37. package/build/src/guard/main.js +2 -6
  38. package/build/src/guard/types.d.ts +0 -9
  39. package/build/src/guard/user_provider.d.ts +9 -1
  40. package/build/src/middleware/any_scope_middleware.js +1 -2
  41. package/build/src/middleware/scope_middleware.js +1 -2
  42. package/build/src/oauth_error.d.ts +74 -74
  43. package/build/src/services/client_service.d.ts +5 -2
  44. package/build/src/sesame_manager.d.ts +6 -5
  45. package/build/src/storage/consent_retry.d.ts +4 -0
  46. package/build/src/storage/drivers/kysely.d.ts +166 -0
  47. package/build/src/storage/drivers/kysely.js +480 -0
  48. package/build/src/storage/drivers/lucid.d.ts +162 -0
  49. package/build/src/storage/drivers/lucid.js +549 -0
  50. package/build/src/storage/migrations/kysely.d.ts +6 -0
  51. package/build/src/storage/types.d.ts +197 -0
  52. package/build/src/storage/types.js +1 -0
  53. package/build/src/stores.d.ts +21 -0
  54. package/build/src/types.d.ts +9 -1
  55. package/build/src/types.js +2 -0
  56. package/build/stubs/config/sesame.stub +4 -1
  57. package/build/stubs/config/sesame_kysely.stub +35 -0
  58. package/build/stubs/migrations/kysely/create_oauth_tables.stub +151 -0
  59. package/build/taze.config.d.ts +2 -0
  60. package/build/{token_controller-DyI7oy-U.js → token_controller-DRatCQNT.js} +74 -63
  61. package/build/types-DEtn2Zdb.js +75 -0
  62. package/build/{userinfo_controller-RLk8cN_o.js → userinfo_controller-YwN26wK-.js} +5 -8
  63. package/build/vite.config.d.ts +1 -1
  64. package/package.json +33 -17
  65. package/build/chunk-DF48asd8.js +0 -9
  66. package/build/oauth_access_token-Cz_5gNBx.js +0 -29
  67. package/build/oauth_client-BSanvSql.js +0 -63
  68. package/build/sesame_manager-B1Jgq1v2.js +0 -6
  69. /package/build/{oauth_error-C7UhDb2q.js → oauth_error-CvxtZvjp.js} +0 -0
  70. /package/build/{token_service-DwnfAR9F.js → token_service-DDQ3Dxaj.js} +0 -0
@@ -1,7 +1,7 @@
1
1
  import type { SesameManager } from '../sesame_manager.ts';
2
- import type { OAuthClient } from '../models/oauth_client.ts';
2
+ import type { OAuthClientRecord } from '../storage/types.ts';
3
3
  export interface ExchangeRefreshTokenInput {
4
- client: OAuthClient;
4
+ client: OAuthClientRecord;
5
5
  refreshToken: string;
6
6
  scope?: string;
7
7
  }
@@ -49,11 +49,11 @@ export declare class ExchangeRefreshTokenAction {
49
49
  * is present.
50
50
  */
51
51
  execute(manager: SesameManager, input: ExchangeRefreshTokenInput): Promise<{
52
- id_token?: string | undefined;
53
52
  access_token: string;
54
- token_type: "Bearer";
53
+ token_type: 'Bearer';
55
54
  expires_in: number;
56
55
  scope: string;
57
56
  refresh_token: string;
57
+ id_token?: string | undefined;
58
58
  }>;
59
59
  }
@@ -1,7 +1,7 @@
1
1
  import type { SesameManager } from '../sesame_manager.ts';
2
- import type { OAuthClient } from '../models/oauth_client.ts';
2
+ import type { OAuthClientRecord } from '../storage/types.ts';
3
3
  export interface AuthorizationCodeInput {
4
- client: OAuthClient;
4
+ client: OAuthClientRecord;
5
5
  userId: string;
6
6
  scopes: string[];
7
7
  redirectUri: string;
@@ -19,32 +19,32 @@ export default class AuthorizeController {
19
19
  code_challenge_method: import("@vinejs/vine/schema/base/literal").OptionalModifier<import("@vinejs/vine").VineString>;
20
20
  nonce: import("@vinejs/vine/schema/base/literal").OptionalModifier<import("@vinejs/vine").VineString>;
21
21
  }, {
22
- nonce?: string | null | undefined;
23
- scope?: string | null | undefined;
24
- state?: string | null | undefined;
22
+ client_id: string;
25
23
  code_challenge?: string | null | undefined;
26
24
  code_challenge_method?: string | null | undefined;
27
- client_id: string;
25
+ nonce?: string | null | undefined;
28
26
  redirect_uri: string;
29
27
  response_type: string;
28
+ scope?: string | null | undefined;
29
+ state?: string | null | undefined;
30
30
  }, {
31
- nonce?: string | undefined;
32
- scope?: string | undefined;
33
- state?: string | undefined;
31
+ client_id: string;
34
32
  code_challenge?: string | undefined;
35
33
  code_challenge_method?: string | undefined;
36
- client_id: string;
34
+ nonce?: string | undefined;
37
35
  redirect_uri: string;
38
36
  response_type: string;
39
- }, {
40
- nonce?: string | undefined;
41
37
  scope?: string | undefined;
42
38
  state?: string | undefined;
39
+ }, {
40
+ client_id: string;
43
41
  code_challenge?: string | undefined;
44
42
  code_challenge_method?: string | undefined;
45
- client_id: string;
43
+ nonce?: string | undefined;
46
44
  redirect_uri: string;
47
45
  response_type: string;
46
+ scope?: string | undefined;
47
+ state?: string | undefined;
48
48
  }>, Record<string, any> | undefined>;
49
49
  /**
50
50
  * Validate the authorization request query params, run the
@@ -36,13 +36,6 @@ export default class MetadataController {
36
36
  oidc(ctx: HttpContext): Promise<{
37
37
  error: string;
38
38
  } | {
39
- userinfo_endpoint: string;
40
- jwks_uri: string;
41
- subject_types_supported: string[];
42
- id_token_signing_alg_values_supported: string[];
43
- scopes_supported: string[];
44
- claims_supported: string[];
45
- response_types_supported: string[];
46
39
  issuer: string;
47
40
  authorization_endpoint: string;
48
41
  token_endpoint: string;
@@ -57,6 +50,13 @@ export default class MetadataController {
57
50
  code_challenge_methods_supported: string[];
58
51
  authorization_response_iss_parameter_supported: boolean;
59
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[];
60
60
  }>;
61
61
  /**
62
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
- contacts?: string[] | null | undefined;
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
- redirect_uris: string[];
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
- contacts?: string[] | undefined;
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
- redirect_uris: string[];
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
- redirectUris: string[];
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
  }
@@ -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: "oauth";
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 { OAuthLucidUserProvider } from './user_provider.ts';
6
- import type { OAuthLucidUserProviderOptions, OAuthUserProviderContract } from './types.ts';
4
+ import type { OAuthUserProviderContract } from './types.ts';
7
5
  export { OAuthGuard } from './guard.ts';
8
- export { OAuthLucidUserProvider } from './user_provider.ts';
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>;
@@ -1,6 +1,2 @@
1
- import "../../chunk-DF48asd8.js";
2
- import "../../oauth_client-BSanvSql.js";
3
- import "../../oauth_access_token-Cz_5gNBx.js";
4
- import "../../token_service-DwnfAR9F.js";
5
- import { i as OAuthGuard, n as oauthUserProvider, r as OAuthLucidUserProvider, t as oauthGuard } from "../../main-DGBJhq3E.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, OAuthLucidUserProviderOptions, OAuthUserProviderContract } from './types.ts';
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,5 +1,4 @@
1
- import "../../chunk-DF48asd8.js";
2
- import { n as E_INSUFFICIENT_SCOPE } from "../../oauth_error-C7UhDb2q.js";
1
+ import { n as E_INSUFFICIENT_SCOPE } from "../../oauth_error-CvxtZvjp.js";
3
2
  //#region src/middleware/any_scope_middleware.ts
4
3
  /**
5
4
  * Any-scope middleware requires ANY of the listed scopes on the
@@ -1,5 +1,4 @@
1
- import "../../chunk-DF48asd8.js";
2
- import { n as E_INSUFFICIENT_SCOPE } from "../../oauth_error-C7UhDb2q.js";
1
+ import { n as E_INSUFFICIENT_SCOPE } from "../../oauth_error-CvxtZvjp.js";
3
2
  //#region src/middleware/scope_middleware.ts
4
3
  /**
5
4
  * Scope middleware requires ALL listed scopes on the authenticated