@adonisjs/auth 8.2.2 → 9.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.
Files changed (134) hide show
  1. package/LICENSE.md +1 -1
  2. package/README.md +19 -40
  3. package/build/configure.d.ts +5 -0
  4. package/build/configure.js +41 -0
  5. package/build/factories/database_token_factory.d.ts +36 -0
  6. package/build/factories/database_token_factory.js +54 -0
  7. package/build/factories/database_user_provider.d.ts +14 -0
  8. package/build/factories/database_user_provider.js +27 -0
  9. package/build/factories/lucid_user_provider.d.ts +28 -0
  10. package/build/factories/lucid_user_provider.js +68 -0
  11. package/build/factories/main.d.ts +4 -0
  12. package/build/factories/main.js +12 -0
  13. package/build/factories/session_guard_factory.d.ts +13 -0
  14. package/build/factories/session_guard_factory.js +24 -0
  15. package/build/index.d.ts +7 -0
  16. package/build/index.js +15 -0
  17. package/build/providers/auth_provider.d.ts +12 -0
  18. package/build/providers/auth_provider.js +27 -0
  19. package/build/services/auth.d.ts +3 -0
  20. package/build/services/auth.js +17 -0
  21. package/build/src/auth/auth_manager.d.ts +18 -0
  22. package/build/src/auth/auth_manager.js +28 -0
  23. package/build/src/auth/authenticator.d.ts +18 -0
  24. package/build/src/auth/authenticator.js +55 -0
  25. package/build/src/auth/debug.d.ts +3 -0
  26. package/build/{adonis-typings/container.js → src/auth/debug.js} +3 -1
  27. package/build/src/auth/define_config.d.ts +30 -0
  28. package/build/src/auth/define_config.js +54 -0
  29. package/build/src/auth/errors.d.ts +8 -0
  30. package/build/src/auth/errors.js +17 -0
  31. package/build/src/auth/symbols.d.ts +9 -0
  32. package/build/src/auth/symbols.js +17 -0
  33. package/build/src/auth/types.d.ts +52 -0
  34. package/build/{adonis-typings/context.js → src/auth/types.js} +2 -1
  35. package/build/src/auth/user_providers/main.d.ts +15 -0
  36. package/build/src/auth/user_providers/main.js +22 -0
  37. package/build/src/core/guard_user.d.ts +26 -0
  38. package/build/src/core/guard_user.js +29 -0
  39. package/build/src/core/token.d.ts +86 -0
  40. package/build/src/core/token.js +112 -0
  41. package/build/src/core/token_providers/database.d.ts +77 -0
  42. package/build/src/core/token_providers/database.js +113 -0
  43. package/build/src/core/types.d.ts +178 -0
  44. package/build/{adonis-typings/auth.js → src/core/types.js} +2 -1
  45. package/build/src/core/user_providers/database.d.ts +78 -0
  46. package/build/src/core/user_providers/database.js +117 -0
  47. package/build/src/core/user_providers/lucid.d.ts +61 -0
  48. package/build/src/core/user_providers/lucid.js +122 -0
  49. package/build/src/guards/session/define_config.d.ts +23 -0
  50. package/build/src/guards/session/define_config.js +56 -0
  51. package/build/src/guards/session/guard.d.ts +92 -0
  52. package/build/src/guards/session/guard.js +380 -0
  53. package/build/src/guards/session/main.d.ts +3 -0
  54. package/build/src/guards/session/main.js +11 -0
  55. package/build/src/guards/session/token.d.ts +57 -0
  56. package/build/src/guards/session/token.js +58 -0
  57. package/build/src/guards/session/token_providers/main.d.ts +33 -0
  58. package/build/src/guards/session/token_providers/main.js +42 -0
  59. package/build/src/guards/session/types.d.ts +97 -0
  60. package/build/{adonis-typings/events.js → src/guards/session/types.js} +2 -1
  61. package/build/stubs/config/auth_middleware.stub +12 -0
  62. package/build/stubs/config.stub +35 -0
  63. package/build/stubs/main.d.ts +1 -0
  64. package/build/{adonis-typings/tests.js → stubs/main.js} +2 -3
  65. package/package.json +96 -91
  66. package/build/adonis-typings/auth.d.ts +0 -635
  67. package/build/adonis-typings/container.d.ts +0 -6
  68. package/build/adonis-typings/context.d.ts +0 -6
  69. package/build/adonis-typings/events.d.ts +0 -10
  70. package/build/adonis-typings/index.d.ts +0 -5
  71. package/build/adonis-typings/index.js +0 -13
  72. package/build/adonis-typings/tests.d.ts +0 -23
  73. package/build/instructions.js +0 -338
  74. package/build/providers/AuthProvider.d.ts +0 -30
  75. package/build/providers/AuthProvider.js +0 -69
  76. package/build/src/Auth/index.d.ts +0 -97
  77. package/build/src/Auth/index.js +0 -155
  78. package/build/src/AuthManager/index.d.ts +0 -117
  79. package/build/src/AuthManager/index.js +0 -262
  80. package/build/src/Bindings/Tests.d.ts +0 -6
  81. package/build/src/Bindings/Tests.js +0 -69
  82. package/build/src/Clients/Oat/index.d.ts +0 -50
  83. package/build/src/Clients/Oat/index.js +0 -123
  84. package/build/src/Clients/Session/index.d.ts +0 -34
  85. package/build/src/Clients/Session/index.js +0 -72
  86. package/build/src/Exceptions/AuthenticationException.d.ts +0 -47
  87. package/build/src/Exceptions/AuthenticationException.js +0 -142
  88. package/build/src/Exceptions/InvalidCredentialsException.d.ts +0 -34
  89. package/build/src/Exceptions/InvalidCredentialsException.js +0 -112
  90. package/build/src/Guards/Base/index.d.ts +0 -75
  91. package/build/src/Guards/Base/index.js +0 -138
  92. package/build/src/Guards/BasicAuth/index.d.ts +0 -67
  93. package/build/src/Guards/BasicAuth/index.js +0 -181
  94. package/build/src/Guards/Oat/index.d.ts +0 -149
  95. package/build/src/Guards/Oat/index.js +0 -347
  96. package/build/src/Guards/Session/index.d.ts +0 -127
  97. package/build/src/Guards/Session/index.js +0 -338
  98. package/build/src/TokenProviders/Database/index.d.ts +0 -43
  99. package/build/src/TokenProviders/Database/index.js +0 -126
  100. package/build/src/TokenProviders/Redis/index.d.ts +0 -44
  101. package/build/src/TokenProviders/Redis/index.js +0 -129
  102. package/build/src/Tokens/OpaqueToken/index.d.ts +0 -46
  103. package/build/src/Tokens/OpaqueToken/index.js +0 -43
  104. package/build/src/Tokens/ProviderToken/index.d.ts +0 -23
  105. package/build/src/Tokens/ProviderToken/index.js +0 -27
  106. package/build/src/UserProviders/Database/User.d.ts +0 -28
  107. package/build/src/UserProviders/Database/User.js +0 -74
  108. package/build/src/UserProviders/Database/index.d.ts +0 -75
  109. package/build/src/UserProviders/Database/index.js +0 -141
  110. package/build/src/UserProviders/Lucid/User.d.ts +0 -28
  111. package/build/src/UserProviders/Lucid/User.js +0 -74
  112. package/build/src/UserProviders/Lucid/index.d.ts +0 -72
  113. package/build/src/UserProviders/Lucid/index.js +0 -146
  114. package/build/standalone.d.ts +0 -1
  115. package/build/standalone.js +0 -13
  116. package/build/templates/config/auth.txt +0 -34
  117. package/build/templates/config/partials/api-guard.txt +0 -22
  118. package/build/templates/config/partials/basic-guard.txt +0 -19
  119. package/build/templates/config/partials/tokens-provider-database.txt +0 -19
  120. package/build/templates/config/partials/tokens-provider-redis.txt +0 -22
  121. package/build/templates/config/partials/user-provider-database.txt +0 -43
  122. package/build/templates/config/partials/user-provider-lucid.txt +0 -45
  123. package/build/templates/config/partials/web-guard.txt +0 -17
  124. package/build/templates/contract/auth.txt +0 -55
  125. package/build/templates/contract/partials/api-guard.txt +0 -14
  126. package/build/templates/contract/partials/basic-guard.txt +0 -14
  127. package/build/templates/contract/partials/user-provider-database.txt +0 -16
  128. package/build/templates/contract/partials/user-provider-lucid.txt +0 -16
  129. package/build/templates/contract/partials/web-guard.txt +0 -14
  130. package/build/templates/middleware/Auth.txt +0 -76
  131. package/build/templates/middleware/SilentAuth.txt +0 -21
  132. package/build/templates/migrations/api_tokens.txt +0 -25
  133. package/build/templates/migrations/auth.txt +0 -24
  134. package/build/templates/model.txt +0 -30
package/LICENSE.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # The MIT License
2
2
 
3
- Copyright 2021 Harminder Virk, contributors
3
+ Copyright (c) 2023 Harminder Virk
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the 'Software'), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
6
6
 
package/README.md CHANGED
@@ -1,53 +1,32 @@
1
- <div align="center">
2
- <img src="https://res.cloudinary.com/adonisjs/image/upload/q_100/v1558612869/adonis-readme_zscycu.jpg" width="600px">
3
- </div>
1
+ # @adonisjs/auth
4
2
 
5
3
  <br />
6
4
 
7
- <div align="center">
8
- <h3>Adonis Auth</h3>
9
- <p>The official user authentication package for AdonisJS. Ships with <strong>sessions</strong>, <strong>api tokens</strong> and <strong>basic auth</strong> guards. </p>
10
- </div>
5
+ [![gh-workflow-image]][gh-workflow-url] [![npm-image]][npm-url] ![][typescript-image] [![license-image]][license-url]
11
6
 
12
- <br />
13
-
14
- <div align="center">
7
+ ## Introduction
15
8
 
16
- [![gh-workflow-image]][gh-workflow-url] [![typescript-image]][typescript-url] [![npm-image]][npm-url] [![license-image]][license-url] [![synk-image]][synk-url]
9
+ ## Official Documentation
10
+ The documentation is available on the [AdonisJS website](https://docs.adonisjs.com/guides/auth/introduction)
17
11
 
18
- </div>
12
+ ## Contributing
13
+ One of the primary goals of AdonisJS is to have a vibrant community of users and contributors who believes in the principles of the framework.
19
14
 
20
- <div align="center">
21
- <h3>
22
- <a href="https://preview.adonisjs.com">
23
- Website
24
- </a>
25
- <span> | </span>
26
- <a href="https://preview.adonisjs.com/guides/auth/introduction">
27
- Guides
28
- </a>
29
- <span> | </span>
30
- <a href="CONTRIBUTING.md">
31
- Contributing
32
- </a>
33
- </h3>
34
- </div>
15
+ We encourage you to read the [contribution guide](https://github.com/adonisjs/.github/blob/main/docs/CONTRIBUTING.md) before contributing to the framework.
35
16
 
36
- <div align="center">
37
- <sub>Built with ❤︎ by <a href="https://twitter.com/AmanVirk1">Harminder Virk</a>
38
- </div>
17
+ ## Code of Conduct
18
+ In order to ensure that the AdonisJS community is welcoming to all, please review and abide by the [Code of Conduct](https://github.com/adonisjs/.github/blob/main/docs/CODE_OF_CONDUCT.md).
39
19
 
40
- [gh-workflow-image]: https://img.shields.io/github/workflow/status/adonisjs/auth/test?style=for-the-badge
41
- [gh-workflow-url]: https://github.com/adonisjs/auth/actions/workflows/test.yml "Github action"
20
+ ## License
21
+ AdonisJS auth is open-sourced software licensed under the [MIT license](LICENSE.md).
42
22
 
43
- [typescript-image]: https://img.shields.io/badge/Typescript-294E80.svg?style=for-the-badge&logo=typescript
44
- [typescript-url]: "typescript"
23
+ [gh-workflow-image]: https://img.shields.io/github/actions/workflow/status/adonisjs/auth/checks.yml?style=for-the-badge
24
+ [gh-workflow-url]: https://github.com/adonisjs/auth/actions/workflows/checks.yml "Github action"
45
25
 
46
- [npm-image]: https://img.shields.io/npm/v/@adonisjs/auth/alpha.svg?style=for-the-badge&logo=npm
47
- [npm-url]: https://www.npmjs.com/package/@adonisjs/auth/v/alpha "npm"
26
+ [npm-image]: https://img.shields.io/npm/v/@adonisjs/auth/latest.svg?style=for-the-badge&logo=npm
27
+ [npm-url]: https://www.npmjs.com/package/@adonisjs/auth/v/latest "npm"
48
28
 
49
- [license-image]: https://img.shields.io/npm/l/@adonisjs/auth?color=blueviolet&style=for-the-badge
50
- [license-url]: LICENSE.md "license"
29
+ [typescript-image]: https://img.shields.io/badge/Typescript-294E80.svg?style=for-the-badge&logo=typescript
51
30
 
52
- [synk-image]: https://img.shields.io/snyk/vulnerabilities/github/adonisjs/auth?label=Synk%20Vulnerabilities&style=for-the-badge
53
- [synk-url]: https://snyk.io/test/github/adonisjs/auth?targetFile=package.json "synk"
31
+ [license-url]: LICENSE.md
32
+ [license-image]: https://img.shields.io/github/license/adonisjs/auth?style=for-the-badge
@@ -0,0 +1,5 @@
1
+ import type Configure from '@adonisjs/core/commands/configure';
2
+ /**
3
+ * Configures the auth package
4
+ */
5
+ export declare function configure(command: Configure): Promise<void>;
@@ -0,0 +1,41 @@
1
+ /*
2
+ * @adonisjs/auth
3
+ *
4
+ * (c) AdonisJS
5
+ *
6
+ * For the full copyright and license information, please view the LICENSE
7
+ * file that was distributed with this source code.
8
+ */
9
+ /**
10
+ * Configures the user provider to use for finding
11
+ * users
12
+ */
13
+ async function configureProvider(command) {
14
+ const provider = await command.prompt.choice('Select the user provider you want to use', [
15
+ {
16
+ name: 'lucid',
17
+ message: 'Lucid models',
18
+ },
19
+ {
20
+ name: 'db',
21
+ message: 'Database query builder',
22
+ },
23
+ ]);
24
+ /**
25
+ * Publish config file
26
+ */
27
+ await command.publishStub('config.stub', { provider });
28
+ }
29
+ /**
30
+ * Configures the auth package
31
+ */
32
+ export async function configure(command) {
33
+ await configureProvider(command);
34
+ const codemods = await command.createCodemods();
35
+ /**
36
+ * Register provider
37
+ */
38
+ await codemods.updateRcFile((rcFile) => {
39
+ rcFile.addProvider('@adonisjs/auth/auth_provider');
40
+ });
41
+ }
@@ -0,0 +1,36 @@
1
+ import { Database } from '@adonisjs/lucid/database';
2
+ import { Token } from '../src/core/token.js';
3
+ import { DatabaseTokenProvider } from '../src/core/token_providers/database.js';
4
+ /**
5
+ * Representation of token used for testing
6
+ */
7
+ export declare class TestToken extends Token {
8
+ type: string;
9
+ userId: string | number;
10
+ static create(userId: number | string, expiry: string | number, size?: number): TestToken;
11
+ }
12
+ /**
13
+ * Test implementation of the database token provider
14
+ */
15
+ export declare class TestDatabaseTokenProvider extends DatabaseTokenProvider<TestToken> {
16
+ protected prepareToken(dbRow: {
17
+ series: string;
18
+ user_id: string | number;
19
+ type: string;
20
+ token: string;
21
+ created_at: Date;
22
+ expires_at: Date | null;
23
+ }): TestToken;
24
+ protected parseToken(token: TestToken): {
25
+ series: string;
26
+ user_id: string | number;
27
+ type: string;
28
+ token: string;
29
+ created_at: Date;
30
+ updated_at: Date;
31
+ expires_at: Date | null;
32
+ };
33
+ }
34
+ export declare class DatabaseTokenProviderFactory {
35
+ create(db: Database): TestDatabaseTokenProvider;
36
+ }
@@ -0,0 +1,54 @@
1
+ /*
2
+ * @adonisjs/auth
3
+ *
4
+ * (c) AdonisJS
5
+ *
6
+ * For the full copyright and license information, please view the LICENSE
7
+ * file that was distributed with this source code.
8
+ */
9
+ import { Token } from '../src/core/token.js';
10
+ import { DatabaseTokenProvider } from '../src/core/token_providers/database.js';
11
+ /**
12
+ * Representation of token used for testing
13
+ */
14
+ export class TestToken extends Token {
15
+ type = 'test_token';
16
+ static create(userId, expiry, size) {
17
+ const { series, value, hash } = this.seed(size);
18
+ const token = new TestToken(series, value, hash);
19
+ token.setExpiry(expiry);
20
+ token.userId = userId;
21
+ return token;
22
+ }
23
+ }
24
+ /**
25
+ * Test implementation of the database token provider
26
+ */
27
+ export class TestDatabaseTokenProvider extends DatabaseTokenProvider {
28
+ prepareToken(dbRow) {
29
+ const token = new TestToken(dbRow.series, undefined, dbRow.token);
30
+ token.createdAt = dbRow.created_at;
31
+ if (dbRow.expires_at) {
32
+ token.expiresAt = dbRow.expires_at;
33
+ }
34
+ return token;
35
+ }
36
+ parseToken(token) {
37
+ return {
38
+ series: token.series,
39
+ user_id: token.userId,
40
+ type: token.type,
41
+ token: token.hash,
42
+ created_at: token.createdAt,
43
+ updated_at: token.createdAt,
44
+ expires_at: token.expiresAt || null,
45
+ };
46
+ }
47
+ }
48
+ export class DatabaseTokenProviderFactory {
49
+ create(db) {
50
+ return new TestDatabaseTokenProvider(db, {
51
+ table: 'remember_me_tokens',
52
+ });
53
+ }
54
+ }
@@ -0,0 +1,14 @@
1
+ import type { Database } from '@adonisjs/lucid/database';
2
+ import { BaseDatabaseUserProvider } from '../src/core/user_providers/database.js';
3
+ export declare class TestDatabaseUserProvider<RealUser extends Record<string, any>> extends BaseDatabaseUserProvider<RealUser> {
4
+ }
5
+ /**
6
+ * Creates an instance of the DatabaseUserProvider with sane
7
+ * defaults for testing
8
+ */
9
+ export declare class DatabaseUserProviderFactory {
10
+ create(db: Database): TestDatabaseUserProvider<{
11
+ email: any;
12
+ username: any;
13
+ }>;
14
+ }
@@ -0,0 +1,27 @@
1
+ /*
2
+ * @adonisjs/auth
3
+ *
4
+ * (c) AdonisJS
5
+ *
6
+ * For the full copyright and license information, please view the LICENSE
7
+ * file that was distributed with this source code.
8
+ */
9
+ import { Hash } from '@adonisjs/core/hash';
10
+ import { Scrypt } from '@adonisjs/core/hash/drivers/scrypt';
11
+ import { BaseDatabaseUserProvider } from '../src/core/user_providers/database.js';
12
+ export class TestDatabaseUserProvider extends BaseDatabaseUserProvider {
13
+ }
14
+ /**
15
+ * Creates an instance of the DatabaseUserProvider with sane
16
+ * defaults for testing
17
+ */
18
+ export class DatabaseUserProviderFactory {
19
+ create(db) {
20
+ return new TestDatabaseUserProvider(db, new Hash(new Scrypt({})), {
21
+ id: 'id',
22
+ table: 'users',
23
+ passwordColumnName: 'password',
24
+ uids: ['email', 'username'],
25
+ });
26
+ }
27
+ }
@@ -0,0 +1,28 @@
1
+ import { BaseModel } from '@adonisjs/lucid/orm';
2
+ import { PROVIDER_REAL_USER } from '../src/auth/symbols.js';
3
+ import { BaseLucidUserProvider } from '../src/core/user_providers/lucid.js';
4
+ import type { LucidAuthenticatable, LucidUserProviderOptions } from '../src/core/types.js';
5
+ export declare class FactoryUser extends BaseModel {
6
+ static table: string;
7
+ static createWithDefaults(attributes?: {
8
+ email?: string;
9
+ password?: string | null;
10
+ username?: string;
11
+ }): Promise<FactoryUser>;
12
+ id: number;
13
+ username: string;
14
+ email: string;
15
+ password: string | null;
16
+ verifyPasswordForAuth(plainTextPassword: string): Promise<boolean>;
17
+ }
18
+ export declare class TestLucidUserProvider<UserModel extends LucidAuthenticatable> extends BaseLucidUserProvider<UserModel> {
19
+ [PROVIDER_REAL_USER]: InstanceType<UserModel>;
20
+ }
21
+ /**
22
+ * Creates an instance of the LucidUserProvider with sane
23
+ * defaults for testing
24
+ */
25
+ export declare class LucidUserProviderFactory {
26
+ createForModel<Model extends LucidAuthenticatable>(options: LucidUserProviderOptions<Model>): TestLucidUserProvider<Model>;
27
+ create(): TestLucidUserProvider<typeof FactoryUser>;
28
+ }
@@ -0,0 +1,68 @@
1
+ /*
2
+ * @adonisjs/auth
3
+ *
4
+ * (c) AdonisJS
5
+ *
6
+ * For the full copyright and license information, please view the LICENSE
7
+ * file that was distributed with this source code.
8
+ */
9
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
10
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
11
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
12
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
13
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
14
+ };
15
+ import { Hash } from '@adonisjs/core/hash';
16
+ import { BaseModel, column } from '@adonisjs/lucid/orm';
17
+ import { Scrypt } from '@adonisjs/core/hash/drivers/scrypt';
18
+ import { PROVIDER_REAL_USER } from '../src/auth/symbols.js';
19
+ import { BaseLucidUserProvider } from '../src/core/user_providers/lucid.js';
20
+ export class FactoryUser extends BaseModel {
21
+ static table = 'users';
22
+ static createWithDefaults(attributes) {
23
+ return this.create({
24
+ email: 'foo@bar.com',
25
+ username: 'foo',
26
+ password: 'secret',
27
+ ...attributes,
28
+ });
29
+ }
30
+ async verifyPasswordForAuth(plainTextPassword) {
31
+ return new Hash(new Scrypt({})).verify(this.password, plainTextPassword);
32
+ }
33
+ }
34
+ __decorate([
35
+ column()
36
+ ], FactoryUser.prototype, "id", void 0);
37
+ __decorate([
38
+ column()
39
+ ], FactoryUser.prototype, "username", void 0);
40
+ __decorate([
41
+ column()
42
+ ], FactoryUser.prototype, "email", void 0);
43
+ __decorate([
44
+ column()
45
+ ], FactoryUser.prototype, "password", void 0);
46
+ export class TestLucidUserProvider extends BaseLucidUserProvider {
47
+ }
48
+ /**
49
+ * Creates an instance of the LucidUserProvider with sane
50
+ * defaults for testing
51
+ */
52
+ export class LucidUserProviderFactory {
53
+ createForModel(options) {
54
+ return new TestLucidUserProvider({
55
+ ...options,
56
+ });
57
+ }
58
+ create() {
59
+ return this.createForModel({
60
+ model: async () => {
61
+ return {
62
+ default: FactoryUser,
63
+ };
64
+ },
65
+ uids: ['email', 'username'],
66
+ });
67
+ }
68
+ }
@@ -0,0 +1,4 @@
1
+ export { SessionGuardFactory } from './session_guard_factory.js';
2
+ export { DatabaseUserProviderFactory, TestDatabaseUserProvider } from './database_user_provider.js';
3
+ export { FactoryUser, LucidUserProviderFactory, TestLucidUserProvider, } from './lucid_user_provider.js';
4
+ export { TestToken, TestDatabaseTokenProvider, DatabaseTokenProviderFactory, } from './database_token_factory.js';
@@ -0,0 +1,12 @@
1
+ /*
2
+ * @adonisjs/auth
3
+ *
4
+ * (c) AdonisJS
5
+ *
6
+ * For the full copyright and license information, please view the LICENSE
7
+ * file that was distributed with this source code.
8
+ */
9
+ export { SessionGuardFactory } from './session_guard_factory.js';
10
+ export { DatabaseUserProviderFactory, TestDatabaseUserProvider } from './database_user_provider.js';
11
+ export { FactoryUser, LucidUserProviderFactory, TestLucidUserProvider, } from './lucid_user_provider.js';
12
+ export { TestToken, TestDatabaseTokenProvider, DatabaseTokenProviderFactory, } from './database_token_factory.js';
@@ -0,0 +1,13 @@
1
+ import type { HttpContext } from '@adonisjs/core/http';
2
+ import { SessionGuard } from '../src/guards/session/guard.js';
3
+ import type { SessionGuardConfig, SessionUserProviderContract } from '../src/guards/session/types.js';
4
+ import { FactoryUser, TestLucidUserProvider } from './lucid_user_provider.js';
5
+ /**
6
+ * Exposes the API to create a session guard for testing. Under
7
+ * the hood configures Lucid models for looking up users
8
+ */
9
+ export declare class SessionGuardFactory {
10
+ #private;
11
+ merge(config: SessionGuardConfig): this;
12
+ create<UserProvider extends SessionUserProviderContract<unknown> = TestLucidUserProvider<typeof FactoryUser>>(ctx: HttpContext, provider?: UserProvider): SessionGuard<TestLucidUserProvider<typeof FactoryUser> | UserProvider>;
13
+ }
@@ -0,0 +1,24 @@
1
+ /*
2
+ * @adonisjs/auth
3
+ *
4
+ * (c) AdonisJS
5
+ *
6
+ * For the full copyright and license information, please view the LICENSE
7
+ * file that was distributed with this source code.
8
+ */
9
+ import { SessionGuard } from '../src/guards/session/guard.js';
10
+ import { LucidUserProviderFactory, } from './lucid_user_provider.js';
11
+ /**
12
+ * Exposes the API to create a session guard for testing. Under
13
+ * the hood configures Lucid models for looking up users
14
+ */
15
+ export class SessionGuardFactory {
16
+ #config = { rememberMeTokenAge: '5y' };
17
+ merge(config) {
18
+ this.#config = config;
19
+ return this;
20
+ }
21
+ create(ctx, provider) {
22
+ return new SessionGuard('web', this.#config, ctx, provider || new LucidUserProviderFactory().create());
23
+ }
24
+ }
@@ -0,0 +1,7 @@
1
+ export { configure } from './configure.js';
2
+ export { stubsRoot } from './stubs/main.js';
3
+ export * as errors from './src/auth/errors.js';
4
+ export * as symbols from './src/auth/symbols.js';
5
+ export { AuthManager } from './src/auth/auth_manager.js';
6
+ export { Authenticator } from './src/auth/authenticator.js';
7
+ export { defineConfig, providers } from './src/auth/define_config.js';
package/build/index.js ADDED
@@ -0,0 +1,15 @@
1
+ /*
2
+ * @adonisjs/auth
3
+ *
4
+ * (c) AdonisJS
5
+ *
6
+ * For the full copyright and license information, please view the LICENSE
7
+ * file that was distributed with this source code.
8
+ */
9
+ export { configure } from './configure.js';
10
+ export { stubsRoot } from './stubs/main.js';
11
+ export * as errors from './src/auth/errors.js';
12
+ export * as symbols from './src/auth/symbols.js';
13
+ export { AuthManager } from './src/auth/auth_manager.js';
14
+ export { Authenticator } from './src/auth/authenticator.js';
15
+ export { defineConfig, providers } from './src/auth/define_config.js';
@@ -0,0 +1,12 @@
1
+ import type { ApplicationService } from '@adonisjs/core/types';
2
+ import type { AuthService } from '../src/auth/types.js';
3
+ declare module '@adonisjs/core/types' {
4
+ interface ContainerBindings {
5
+ 'auth.manager': AuthService;
6
+ }
7
+ }
8
+ export default class AuthProvider {
9
+ protected app: ApplicationService;
10
+ constructor(app: ApplicationService);
11
+ register(): void;
12
+ }
@@ -0,0 +1,27 @@
1
+ /*
2
+ * @adonisjs/auth
3
+ *
4
+ * (c) AdonisJS
5
+ *
6
+ * For the full copyright and license information, please view the LICENSE
7
+ * file that was distributed with this source code.
8
+ */
9
+ import { configProvider } from '@adonisjs/core';
10
+ import { RuntimeException } from '@poppinss/utils';
11
+ import { AuthManager } from '../src/auth/auth_manager.js';
12
+ export default class AuthProvider {
13
+ app;
14
+ constructor(app) {
15
+ this.app = app;
16
+ }
17
+ register() {
18
+ this.app.container.singleton('auth.manager', async () => {
19
+ const authConfigProvider = this.app.config.get('auth');
20
+ const config = await configProvider.resolve(this.app, authConfigProvider);
21
+ if (!config) {
22
+ throw new RuntimeException('Invalid config exported from "config/auth.ts" file. Make sure to use the defineConfig method');
23
+ }
24
+ return new AuthManager(config);
25
+ });
26
+ }
27
+ }
@@ -0,0 +1,3 @@
1
+ import { AuthService } from '../src/auth/types.js';
2
+ declare let auth: AuthService;
3
+ export { auth as default };
@@ -0,0 +1,17 @@
1
+ /*
2
+ * @adonisjs/auth
3
+ *
4
+ * (c) AdonisJS
5
+ *
6
+ * For the full copyright and license information, please view the LICENSE
7
+ * file that was distributed with this source code.
8
+ */
9
+ import app from '@adonisjs/core/services/app';
10
+ let auth;
11
+ /**
12
+ * Returns a singleton instance of the Auth manager class
13
+ */
14
+ await app.booted(async () => {
15
+ auth = await app.container.make('auth.manager');
16
+ });
17
+ export { auth as default };
@@ -0,0 +1,18 @@
1
+ import type { HttpContext } from '@adonisjs/core/http';
2
+ import type { GuardFactory } from './types.js';
3
+ import { Authenticator } from './authenticator.js';
4
+ /**
5
+ * Auth manager exposes the API to register and manage authentication
6
+ * guards from the config
7
+ */
8
+ export declare class AuthManager<KnownGuards extends Record<string, GuardFactory>> {
9
+ #private;
10
+ constructor(config: {
11
+ default: keyof KnownGuards;
12
+ guards: KnownGuards;
13
+ });
14
+ /**
15
+ * Create an authenticator for a given HTTP request
16
+ */
17
+ createAuthenticator(ctx: HttpContext): Authenticator<KnownGuards>;
18
+ }
@@ -0,0 +1,28 @@
1
+ /*
2
+ * @adonisjs/auth
3
+ *
4
+ * (c) AdonisJS
5
+ *
6
+ * For the full copyright and license information, please view the LICENSE
7
+ * file that was distributed with this source code.
8
+ */
9
+ import { Authenticator } from './authenticator.js';
10
+ /**
11
+ * Auth manager exposes the API to register and manage authentication
12
+ * guards from the config
13
+ */
14
+ export class AuthManager {
15
+ /**
16
+ * Registered guards
17
+ */
18
+ #config;
19
+ constructor(config) {
20
+ this.#config = config;
21
+ }
22
+ /**
23
+ * Create an authenticator for a given HTTP request
24
+ */
25
+ createAuthenticator(ctx) {
26
+ return new Authenticator(ctx, this.#config);
27
+ }
28
+ }
@@ -0,0 +1,18 @@
1
+ import type { HttpContext } from '@adonisjs/core/http';
2
+ import type { GuardFactory } from './types.js';
3
+ /**
4
+ * Authenticator is an HTTP request specific implementation for using
5
+ * guards to login users and authenticate requests.
6
+ */
7
+ export declare class Authenticator<KnownGuards extends Record<string, GuardFactory>> {
8
+ #private;
9
+ constructor(ctx: HttpContext, config: {
10
+ default: keyof KnownGuards;
11
+ guards: KnownGuards;
12
+ });
13
+ /**
14
+ * Returns an instance of a known guard. Guards instances are
15
+ * cached during the lifecycle of an HTTP request.
16
+ */
17
+ use<Guard extends keyof KnownGuards>(guard?: Guard): ReturnType<KnownGuards[Guard]>;
18
+ }
@@ -0,0 +1,55 @@
1
+ /*
2
+ * @adonisjs/auth
3
+ *
4
+ * (c) AdonisJS
5
+ *
6
+ * For the full copyright and license information, please view the LICENSE
7
+ * file that was distributed with this source code.
8
+ */
9
+ import debug from './debug.js';
10
+ /**
11
+ * Authenticator is an HTTP request specific implementation for using
12
+ * guards to login users and authenticate requests.
13
+ */
14
+ export class Authenticator {
15
+ /**
16
+ * Reference to HTTP context
17
+ */
18
+ #ctx;
19
+ /**
20
+ * Registered guards
21
+ */
22
+ #config;
23
+ /**
24
+ * Cache of guards created during the HTTP request
25
+ */
26
+ #guardsCache = {};
27
+ constructor(ctx, config) {
28
+ this.#ctx = ctx;
29
+ this.#config = config;
30
+ debug('creating authenticator. config %O', this.#config);
31
+ }
32
+ /**
33
+ * Returns an instance of a known guard. Guards instances are
34
+ * cached during the lifecycle of an HTTP request.
35
+ */
36
+ use(guard) {
37
+ const guardToUse = guard || this.#config.default;
38
+ /**
39
+ * Use cached copy if exists
40
+ */
41
+ const cachedGuard = this.#guardsCache[guardToUse];
42
+ if (cachedGuard) {
43
+ debug('using guard from cache. name: "%s"', guardToUse);
44
+ return cachedGuard;
45
+ }
46
+ const guardFactory = this.#config.guards[guardToUse];
47
+ /**
48
+ * Construct guard and cache it
49
+ */
50
+ debug('creating guard. name: "%s"', guardToUse);
51
+ const guardInstance = guardFactory(this.#ctx);
52
+ this.#guardsCache[guardToUse] = guardInstance;
53
+ return guardInstance;
54
+ }
55
+ }
@@ -0,0 +1,3 @@
1
+ /// <reference types="node" resolution-mode="require"/>
2
+ declare const _default: import("util").DebugLogger;
3
+ export default _default;
@@ -1,8 +1,10 @@
1
1
  /*
2
2
  * @adonisjs/auth
3
3
  *
4
- * (c) Harminder Virk <virk@adonisjs.com>
4
+ * (c) AdonisJS
5
5
  *
6
6
  * For the full copyright and license information, please view the LICENSE
7
7
  * file that was distributed with this source code.
8
8
  */
9
+ import { debuglog } from 'node:util';
10
+ export default debuglog('adonisjs:auth');