@adonisjs/auth 8.2.3 → 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
@@ -1,146 +0,0 @@
1
- "use strict";
2
- /*
3
- * @adonisjs/auth
4
- *
5
- * (c) Harminder Virk <virk@adonisjs.com>
6
- *
7
- * For the full copyright and license information, please view the LICENSE
8
- * file that was distributed with this source code.
9
- */
10
- Object.defineProperty(exports, "__esModule", { value: true });
11
- exports.LucidProvider = void 0;
12
- const hooks_1 = require("@poppinss/hooks");
13
- const utils_1 = require("@poppinss/utils");
14
- const User_1 = require("./User");
15
- /**
16
- * Lucid provider uses Lucid models to lookup a users
17
- */
18
- class LucidProvider {
19
- constructor(application, config) {
20
- this.application = application;
21
- this.config = config;
22
- /**
23
- * Hooks reference
24
- */
25
- this.hooks = new hooks_1.Hooks();
26
- }
27
- /**
28
- * The models options for constructing a query
29
- */
30
- getModelOptions() {
31
- if (typeof this.connection === 'string') {
32
- return { connection: this.connection };
33
- }
34
- if (this.connection) {
35
- return { client: this.connection };
36
- }
37
- return this.config.connection ? { connection: this.config.connection } : {};
38
- }
39
- /**
40
- * Returns the auth model
41
- */
42
- async getModel() {
43
- const model = await this.config.model();
44
- return (0, utils_1.esmResolver)(model);
45
- }
46
- /**
47
- * Returns query instance for the user model
48
- */
49
- async getModelQuery(model) {
50
- model = model || (await this.getModel());
51
- return {
52
- query: model.query(this.getModelOptions()),
53
- };
54
- }
55
- /**
56
- * Executes the query to find the user, calls the registered hooks
57
- * and wraps the result inside [[ProviderUserContract]]
58
- */
59
- async findUser(query) {
60
- await this.hooks.exec('before', 'findUser', query);
61
- const user = await query.first();
62
- if (user) {
63
- await this.hooks.exec('after', 'findUser', user);
64
- }
65
- return this.getUserFor(user);
66
- }
67
- /**
68
- * Returns an instance of the [[ProviderUser]] by wrapping lucid model
69
- * inside it
70
- */
71
- async getUserFor(user) {
72
- const UserBuilder = this.config.user ? (0, utils_1.esmResolver)(await this.config.user()) : User_1.LucidUser;
73
- return this.application.container.makeAsync(UserBuilder, [user, this.config]);
74
- }
75
- /**
76
- * Define custom connection
77
- */
78
- setConnection(connection) {
79
- this.connection = connection;
80
- return this;
81
- }
82
- /**
83
- * Define before hooks. Check interface for exact type information
84
- */
85
- before(event, callback) {
86
- this.hooks.add('before', event, callback);
87
- return this;
88
- }
89
- /**
90
- * Define after hooks. Check interface for exact type information
91
- */
92
- after(event, callback) {
93
- this.hooks.add('after', event, callback);
94
- return this;
95
- }
96
- /**
97
- * Returns a user instance using the primary key value
98
- */
99
- async findById(id) {
100
- const { query } = await this.getModelQuery();
101
- return this.findUser(query.where(this.config.identifierKey, id));
102
- }
103
- /**
104
- * Returns a user instance using a specific token type and value
105
- */
106
- async findByRememberMeToken(id, value) {
107
- const { query } = await this.getModelQuery();
108
- return this.findUser(query.where(this.config.identifierKey, id).where('rememberMeToken', value));
109
- }
110
- /**
111
- * Returns the user instance by searching the uidValue against
112
- * their defined uids.
113
- */
114
- async findByUid(uidValue) {
115
- const model = await this.getModel();
116
- /**
117
- * Use custom function on the model. This time, we do not emit
118
- * an event, since the user custom lookup may not even
119
- * run a query at all.
120
- */
121
- if (typeof model.findForAuth === 'function') {
122
- const user = await model.findForAuth(this.config.uids, uidValue);
123
- return this.getUserFor(user);
124
- }
125
- /**
126
- * Lookup by running a custom query.
127
- */
128
- const { query } = await this.getModelQuery();
129
- this.config.uids.forEach((uid) => query.orWhere(uid, uidValue));
130
- return this.findUser(query);
131
- }
132
- /**
133
- * Updates the user remember me token. The guard must called `setRememberMeToken`
134
- * before invoking this method.
135
- */
136
- async updateRememberMeToken(providerUser) {
137
- /**
138
- * Extra check to find malformed guards
139
- */
140
- if (!providerUser.user.$dirty.rememberMeToken) {
141
- throw new Error('The guard must called "setRememberMeToken" before calling "updateRememberMeToken" on the Lucid provider');
142
- }
143
- await providerUser.user.save();
144
- }
145
- }
146
- exports.LucidProvider = LucidProvider;
@@ -1 +0,0 @@
1
- export { AuthenticationException } from './src/Exceptions/AuthenticationException';
@@ -1,13 +0,0 @@
1
- "use strict";
2
- /*
3
- * @adonisjs/auth
4
- *
5
- * (c) Harminder Virk <virk@adonisjs.com>
6
- *
7
- * For the full copyright and license information, please view the LICENSE
8
- * file that was distributed with this source code.
9
- */
10
- Object.defineProperty(exports, "__esModule", { value: true });
11
- exports.AuthenticationException = void 0;
12
- var AuthenticationException_1 = require("./src/Exceptions/AuthenticationException");
13
- Object.defineProperty(exports, "AuthenticationException", { enumerable: true, get: function () { return AuthenticationException_1.AuthenticationException; } });
@@ -1,34 +0,0 @@
1
- /**
2
- * Config source: https://git.io/JY0mp
3
- *
4
- * Feel free to let us know via PR, if you find something broken in this config
5
- * file.
6
- */
7
-
8
- import type { AuthConfig } from '@ioc:Adonis/Addons/Auth'
9
-
10
- /*
11
- |--------------------------------------------------------------------------
12
- | Authentication Mapping
13
- |--------------------------------------------------------------------------
14
- |
15
- | List of available authentication mapping. You must first define them
16
- | inside the `contracts/auth.ts` file before mentioning them here.
17
- |
18
- */
19
- const authConfig: AuthConfig = {
20
- guard: '{{ guards.0 }}',
21
- guards: {
22
- {{#hasGuard.web}}
23
- {{> web_guard}}
24
- {{/hasGuard.web}}
25
- {{#hasGuard.api}}
26
- {{> api_guard}}
27
- {{/hasGuard.api}}
28
- {{#hasGuard.basic}}
29
- {{> basic_guard}}
30
- {{/hasGuard.basic}}
31
- },
32
- }
33
-
34
- export default authConfig
@@ -1,22 +0,0 @@
1
- /*
2
- |--------------------------------------------------------------------------
3
- | OAT Guard
4
- |--------------------------------------------------------------------------
5
- |
6
- | OAT (Opaque access tokens) guard uses database backed tokens to authenticate
7
- | HTTP request. This guard DOES NOT rely on sessions or cookies and uses
8
- | Authorization header value for authentication.
9
- |
10
- | Use this guard to authenticate mobile apps or web clients that cannot rely
11
- | on cookies/sessions.
12
- |
13
- */
14
- api: {
15
- driver: 'oat',
16
-
17
- {{> token_provider}}
18
-
19
- provider: {
20
- {{> provider}}
21
- },
22
- },
@@ -1,19 +0,0 @@
1
- /*
2
- |--------------------------------------------------------------------------
3
- | Basic Auth Guard
4
- |--------------------------------------------------------------------------
5
- |
6
- | Uses Basic auth to authenticate an HTTP request. There is no concept of
7
- | "login" and "logout" with basic auth. You just authenticate the requests
8
- | using a middleware and browser will prompt the user to enter their login
9
- | details
10
- |
11
- */
12
- basic: {
13
- driver: 'basic',
14
- realm: 'Login',
15
-
16
- provider: {
17
- {{> provider}}
18
- },
19
- },
@@ -1,19 +0,0 @@
1
- /*
2
- |--------------------------------------------------------------------------
3
- | Tokens provider
4
- |--------------------------------------------------------------------------
5
- |
6
- | Uses SQL database for managing tokens. Use the "database" driver, when
7
- | tokens are the secondary mode of authentication.
8
- | For example: The Github personal tokens
9
- |
10
- | The foreignKey column is used to make the relationship between the user
11
- | and the token. You are free to use any column name here.
12
- |
13
- */
14
- tokenProvider: {
15
- type: 'api',
16
- driver: 'database',
17
- table: 'api_tokens',
18
- foreignKey: 'user_id',
19
- },
@@ -1,22 +0,0 @@
1
- /*
2
- |--------------------------------------------------------------------------
3
- | Redis provider for managing tokens
4
- |--------------------------------------------------------------------------
5
- |
6
- | Uses Redis for managing tokens. We recommend using the "redis" driver
7
- | over the "database" driver when the tokens based auth is the
8
- | primary authentication mode.
9
- |
10
- | Redis ensure that all the expired tokens gets cleaned up automatically.
11
- | Whereas with SQL, you have to cleanup expired tokens manually.
12
- |
13
- | The foreignKey column is used to make the relationship between the user
14
- | and the token. You are free to use any column name here.
15
- |
16
- */
17
- tokenProvider: {
18
- type: 'api',
19
- driver: 'redis',
20
- redisConnection: 'local',
21
- foreignKey: 'user_id',
22
- },
@@ -1,43 +0,0 @@
1
- /*
2
- |--------------------------------------------------------------------------
3
- | Driver
4
- |--------------------------------------------------------------------------
5
- |
6
- | Name of the driver
7
- |
8
- */
9
- driver: 'database',
10
-
11
- /*
12
- |--------------------------------------------------------------------------
13
- | Identifier key
14
- |--------------------------------------------------------------------------
15
- |
16
- | The identifier key is the unique key inside the defined database table.
17
- | In most cases specifying the primary key is the right choice.
18
- |
19
- */
20
- identifierKey: 'id',
21
-
22
- /*
23
- |--------------------------------------------------------------------------
24
- | Uids
25
- |--------------------------------------------------------------------------
26
- |
27
- | Uids are used to search a user against one of the mentioned columns. During
28
- | login, the auth module will search the user mentioned value against one
29
- | of the mentioned columns to find their user record.
30
- |
31
- */
32
- uids: ['email'],
33
-
34
- /*
35
- |--------------------------------------------------------------------------
36
- | Database table
37
- |--------------------------------------------------------------------------
38
- |
39
- | The database table to query. Make sure the database table has a `password`
40
- | field and `remember_me_token` column.
41
- |
42
- */
43
- usersTable: '{{ usersTableName }}',
@@ -1,45 +0,0 @@
1
- /*
2
- |--------------------------------------------------------------------------
3
- | Driver
4
- |--------------------------------------------------------------------------
5
- |
6
- | Name of the driver
7
- |
8
- */
9
- driver: 'lucid',
10
-
11
- /*
12
- |--------------------------------------------------------------------------
13
- | Identifier key
14
- |--------------------------------------------------------------------------
15
- |
16
- | The identifier key is the unique key on the model. In most cases specifying
17
- | the primary key is the right choice.
18
- |
19
- */
20
- identifierKey: 'id',
21
-
22
- /*
23
- |--------------------------------------------------------------------------
24
- | Uids
25
- |--------------------------------------------------------------------------
26
- |
27
- | Uids are used to search a user against one of the mentioned columns. During
28
- | login, the auth module will search the user mentioned value against one
29
- | of the mentioned columns to find their user record.
30
- |
31
- */
32
- uids: ['email'],
33
-
34
- /*
35
- |--------------------------------------------------------------------------
36
- | Model
37
- |--------------------------------------------------------------------------
38
- |
39
- | The model to use for fetching or finding users. The model is imported
40
- | lazily since the config files are read way earlier in the lifecycle
41
- | of booting the app and the models may not be in a usable state at
42
- | that time.
43
- |
44
- */
45
- model: () => import('{{{ modelNamespace }}}'),
@@ -1,17 +0,0 @@
1
- /*
2
- |--------------------------------------------------------------------------
3
- | Web Guard
4
- |--------------------------------------------------------------------------
5
- |
6
- | Web guard uses classic old school sessions for authenticating users.
7
- | If you are building a standard web application, it is recommended to
8
- | use web guard with session driver
9
- |
10
- */
11
- web: {
12
- driver: 'session',
13
-
14
- provider: {
15
- {{> provider}}
16
- },
17
- },
@@ -1,55 +0,0 @@
1
- /**
2
- * Contract source: https://git.io/JOdz5
3
- *
4
- * Feel free to let us know via PR, if you find something broken in this
5
- * file.
6
- */
7
- {{#modelNamespace}}
8
-
9
- import {{ modelName }} from '{{{ modelNamespace }}}'
10
- {{/modelNamespace}}
11
-
12
- declare module '@ioc:Adonis/Addons/Auth' {
13
- /*
14
- |--------------------------------------------------------------------------
15
- | Providers
16
- |--------------------------------------------------------------------------
17
- |
18
- | The providers are used to fetch users. The Auth module comes pre-bundled
19
- | with two providers that are `Lucid` and `Database`. Both uses database
20
- | to fetch user details.
21
- |
22
- | You can also create and register your own custom providers.
23
- |
24
- */
25
- interface ProvidersList {
26
- {{> provider}}
27
- }
28
-
29
- /*
30
- |--------------------------------------------------------------------------
31
- | Guards
32
- |--------------------------------------------------------------------------
33
- |
34
- | The guards are used for authenticating users using different drivers.
35
- | The auth module comes with 3 different guards.
36
- |
37
- | - SessionGuardContract
38
- | - BasicAuthGuardContract
39
- | - OATGuardContract ( Opaque access token )
40
- |
41
- | Every guard needs a provider for looking up users from the database.
42
- |
43
- */
44
- interface GuardsList {
45
- {{#hasGuard.web}}
46
- {{> web_guard}}
47
- {{/hasGuard.web}}
48
- {{#hasGuard.api}}
49
- {{> api_guard}}
50
- {{/hasGuard.api}}
51
- {{#hasGuard.basic}}
52
- {{> basic_guard}}
53
- {{/hasGuard.basic}}
54
- }
55
- }
@@ -1,14 +0,0 @@
1
- /*
2
- |--------------------------------------------------------------------------
3
- | OAT Guard
4
- |--------------------------------------------------------------------------
5
- |
6
- | OAT, stands for (Opaque access tokens) guard uses database backed tokens
7
- | to authenticate requests.
8
- |
9
- */
10
- api: {
11
- implementation: OATGuardContract<'user', 'api'>
12
- config: OATGuardConfig<'user'>
13
- client: OATClientContract<'user'>
14
- }
@@ -1,14 +0,0 @@
1
- /*
2
- |--------------------------------------------------------------------------
3
- | Basic Auth Guard
4
- |--------------------------------------------------------------------------
5
- |
6
- | The basic guard uses basic auth for maintaining user login state. It uses
7
- | the `user` provider for fetching user details.
8
- |
9
- */
10
- basic: {
11
- implementation: BasicAuthGuardContract<'user', 'basic'>
12
- config: BasicAuthGuardConfig<'user'>
13
- client: BasicAuthClientContract<'user'>
14
- }
@@ -1,16 +0,0 @@
1
- /*
2
- |--------------------------------------------------------------------------
3
- | User Provider
4
- |--------------------------------------------------------------------------
5
- |
6
- | The following provider directlly uses Database query builder for fetching
7
- | user details from the database for authentication.
8
- |
9
- | You can create multiple providers using the same underlying driver with
10
- | different database tables.
11
- |
12
- */
13
- user: {
14
- implementation: DatabaseProviderContract<DatabaseProviderRow>
15
- config: DatabaseProviderConfig
16
- }
@@ -1,16 +0,0 @@
1
- /*
2
- |--------------------------------------------------------------------------
3
- | User Provider
4
- |--------------------------------------------------------------------------
5
- |
6
- | The following provider uses Lucid models as a driver for fetching user
7
- | details from the database for authentication.
8
- |
9
- | You can create multiple providers using the same underlying driver with
10
- | different Lucid models.
11
- |
12
- */
13
- user: {
14
- implementation: LucidProviderContract<typeof {{ modelName }}>
15
- config: LucidProviderConfig<typeof {{ modelName }}>
16
- }
@@ -1,14 +0,0 @@
1
- /*
2
- |--------------------------------------------------------------------------
3
- | Web Guard
4
- |--------------------------------------------------------------------------
5
- |
6
- | The web guard uses sessions for maintaining user login state. It uses
7
- | the `user` provider for fetching user details.
8
- |
9
- */
10
- web: {
11
- implementation: SessionGuardContract<'user', 'web'>
12
- config: SessionGuardConfig<'user'>
13
- client: SessionClientContract<'user'>
14
- }
@@ -1,76 +0,0 @@
1
- import { AuthenticationException } from '@adonisjs/auth/build/standalone'
2
- import type { GuardsList } from '@ioc:Adonis/Addons/Auth'
3
- import type { HttpContextContract } from '@ioc:Adonis/Core/HttpContext'
4
-
5
- /**
6
- * Auth middleware is meant to restrict un-authenticated access to a given route
7
- * or a group of routes.
8
- *
9
- * You must register this middleware inside `start/kernel.ts` file under the list
10
- * of named middleware.
11
- */
12
- export default class AuthMiddleware {
13
- /**
14
- * The URL to redirect to when request is Unauthorized
15
- */
16
- protected redirectTo = '/login'
17
-
18
- /**
19
- * Authenticates the current HTTP request against a custom set of defined
20
- * guards.
21
- *
22
- * The authentication loop stops as soon as the user is authenticated using any
23
- * of the mentioned guards and that guard will be used by the rest of the code
24
- * during the current request.
25
- */
26
- protected async authenticate(auth: HttpContextContract['auth'], guards: (keyof GuardsList)[]) {
27
- /**
28
- * Hold reference to the guard last attempted within the for loop. We pass
29
- * the reference of the guard to the "AuthenticationException", so that
30
- * it can decide the correct response behavior based upon the guard
31
- * driver
32
- */
33
- let guardLastAttempted: string | undefined
34
-
35
- for (let guard of guards) {
36
- guardLastAttempted = guard
37
-
38
- if (await auth.use(guard).check()) {
39
- /**
40
- * Instruct auth to use the given guard as the default guard for
41
- * the rest of the request, since the user authenticated
42
- * succeeded here
43
- */
44
- auth.defaultGuard = guard
45
- return true
46
- }
47
- }
48
-
49
- /**
50
- * Unable to authenticate using any guard
51
- */
52
- throw new AuthenticationException(
53
- 'Unauthorized access',
54
- 'E_UNAUTHORIZED_ACCESS',
55
- guardLastAttempted,
56
- this.redirectTo,
57
- )
58
- }
59
-
60
- /**
61
- * Handle request
62
- */
63
- public async handle (
64
- { auth }: HttpContextContract,
65
- next: () => Promise<void>,
66
- customGuards: (keyof GuardsList)[]
67
- ) {
68
- /**
69
- * Uses the user defined guards or the default guard mentioned in
70
- * the config file
71
- */
72
- const guards = customGuards.length ? customGuards : [auth.name]
73
- await this.authenticate(auth, guards)
74
- await next()
75
- }
76
- }
@@ -1,21 +0,0 @@
1
- import type { HttpContextContract } from '@ioc:Adonis/Core/HttpContext'
2
-
3
- /**
4
- * Silent auth middleware can be used as a global middleware to silent check
5
- * if the user is logged-in or not.
6
- *
7
- * The request continues as usual, even when the user is not logged-in.
8
- */
9
- export default class SilentAuthMiddleware {
10
- /**
11
- * Handle request
12
- */
13
- public async handle({ auth }: HttpContextContract, next: () => Promise<void>) {
14
- /**
15
- * Check if user is logged-in or not. If yes, then `ctx.auth.user` will be
16
- * set to the instance of the currently logged in user.
17
- */
18
- await auth.check()
19
- await next()
20
- }
21
- }
@@ -1,25 +0,0 @@
1
- import BaseSchema from '@ioc:Adonis/Lucid/Schema'
2
-
3
- export default class extends BaseSchema {
4
- protected tableName = '{{ tokensTableName }}'
5
-
6
- public async up() {
7
- this.schema.createTable(this.tableName, (table) => {
8
- table.increments('id').primary()
9
- table.integer('user_id').unsigned().references('id').inTable('{{ usersTableName }}').onDelete('CASCADE')
10
- table.string('name').notNullable()
11
- table.string('type').notNullable()
12
- table.string('token', 64).notNullable().unique()
13
-
14
- /**
15
- * Uses timestampz for PostgreSQL and DATETIME2 for MSSQL
16
- */
17
- table.timestamp('expires_at', { useTz: true }).nullable()
18
- table.timestamp('created_at', { useTz: true }).notNullable()
19
- })
20
- }
21
-
22
- public async down() {
23
- this.schema.dropTable(this.tableName)
24
- }
25
- }
@@ -1,24 +0,0 @@
1
- import BaseSchema from '@ioc:Adonis/Lucid/Schema'
2
-
3
- export default class extends BaseSchema {
4
- protected tableName = '{{ usersTableName }}'
5
-
6
- public async up() {
7
- this.schema.createTable(this.tableName, (table) => {
8
- table.increments('id').primary()
9
- table.string('email', 255).notNullable().unique()
10
- table.string('password', 180).notNullable()
11
- table.string('remember_me_token').nullable()
12
-
13
- /**
14
- * Uses timestampz for PostgreSQL and DATETIME2 for MSSQL
15
- */
16
- table.timestamp('created_at', { useTz: true }).notNullable()
17
- table.timestamp('updated_at', { useTz: true }).notNullable()
18
- })
19
- }
20
-
21
- public async down() {
22
- this.schema.dropTable(this.tableName)
23
- }
24
- }