@adonisjs/auth 8.2.3 → 9.0.0-1

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 (137) 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 +55 -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 +22 -0
  22. package/build/src/auth/auth_manager.js +34 -0
  23. package/build/src/auth/authenticator.d.ts +56 -0
  24. package/build/src/auth/authenticator.js +122 -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 +82 -0
  30. package/build/src/auth/errors.js +181 -0
  31. package/build/src/auth/middleware/auth_middleware.d.ts +13 -0
  32. package/build/src/auth/middleware/auth_middleware.js +6 -0
  33. package/build/src/auth/middleware/initialize_auth_middleware.d.ts +18 -0
  34. package/build/src/auth/middleware/initialize_auth_middleware.js +25 -0
  35. package/build/src/auth/symbols.d.ts +9 -0
  36. package/build/src/auth/symbols.js +17 -0
  37. package/build/src/auth/types.d.ts +75 -0
  38. package/build/{adonis-typings/context.js → src/auth/types.js} +2 -1
  39. package/build/src/auth/user_providers/main.d.ts +15 -0
  40. package/build/src/auth/user_providers/main.js +22 -0
  41. package/build/src/core/guard_user.d.ts +26 -0
  42. package/build/src/core/guard_user.js +29 -0
  43. package/build/src/core/token.d.ts +89 -0
  44. package/build/src/core/token.js +114 -0
  45. package/build/src/core/token_providers/database.d.ts +77 -0
  46. package/build/src/core/token_providers/database.js +113 -0
  47. package/build/src/core/types.d.ts +178 -0
  48. package/build/{adonis-typings/auth.js → src/core/types.js} +2 -1
  49. package/build/src/core/user_providers/database.d.ts +78 -0
  50. package/build/src/core/user_providers/database.js +117 -0
  51. package/build/src/core/user_providers/lucid.d.ts +61 -0
  52. package/build/src/core/user_providers/lucid.js +122 -0
  53. package/build/src/guards/session/define_config.d.ts +23 -0
  54. package/build/src/guards/session/define_config.js +56 -0
  55. package/build/src/guards/session/guard.d.ts +112 -0
  56. package/build/src/guards/session/guard.js +454 -0
  57. package/build/src/guards/session/main.d.ts +3 -0
  58. package/build/src/guards/session/main.js +11 -0
  59. package/build/src/guards/session/token.d.ts +57 -0
  60. package/build/src/guards/session/token.js +58 -0
  61. package/build/src/guards/session/token_providers/main.d.ts +33 -0
  62. package/build/src/guards/session/token_providers/main.js +42 -0
  63. package/build/src/guards/session/types.d.ts +96 -0
  64. package/build/{adonis-typings/events.js → src/guards/session/types.js} +2 -1
  65. package/build/stubs/config.stub +35 -0
  66. package/build/stubs/main.d.ts +1 -0
  67. package/build/{adonis-typings/tests.js → stubs/main.js} +2 -3
  68. package/package.json +99 -91
  69. package/build/adonis-typings/auth.d.ts +0 -635
  70. package/build/adonis-typings/container.d.ts +0 -6
  71. package/build/adonis-typings/context.d.ts +0 -6
  72. package/build/adonis-typings/events.d.ts +0 -10
  73. package/build/adonis-typings/index.d.ts +0 -5
  74. package/build/adonis-typings/index.js +0 -13
  75. package/build/adonis-typings/tests.d.ts +0 -23
  76. package/build/instructions.js +0 -338
  77. package/build/providers/AuthProvider.d.ts +0 -30
  78. package/build/providers/AuthProvider.js +0 -69
  79. package/build/src/Auth/index.d.ts +0 -97
  80. package/build/src/Auth/index.js +0 -155
  81. package/build/src/AuthManager/index.d.ts +0 -117
  82. package/build/src/AuthManager/index.js +0 -262
  83. package/build/src/Bindings/Tests.d.ts +0 -6
  84. package/build/src/Bindings/Tests.js +0 -69
  85. package/build/src/Clients/Oat/index.d.ts +0 -50
  86. package/build/src/Clients/Oat/index.js +0 -123
  87. package/build/src/Clients/Session/index.d.ts +0 -34
  88. package/build/src/Clients/Session/index.js +0 -72
  89. package/build/src/Exceptions/AuthenticationException.d.ts +0 -47
  90. package/build/src/Exceptions/AuthenticationException.js +0 -142
  91. package/build/src/Exceptions/InvalidCredentialsException.d.ts +0 -34
  92. package/build/src/Exceptions/InvalidCredentialsException.js +0 -112
  93. package/build/src/Guards/Base/index.d.ts +0 -75
  94. package/build/src/Guards/Base/index.js +0 -138
  95. package/build/src/Guards/BasicAuth/index.d.ts +0 -67
  96. package/build/src/Guards/BasicAuth/index.js +0 -181
  97. package/build/src/Guards/Oat/index.d.ts +0 -149
  98. package/build/src/Guards/Oat/index.js +0 -347
  99. package/build/src/Guards/Session/index.d.ts +0 -127
  100. package/build/src/Guards/Session/index.js +0 -338
  101. package/build/src/TokenProviders/Database/index.d.ts +0 -43
  102. package/build/src/TokenProviders/Database/index.js +0 -126
  103. package/build/src/TokenProviders/Redis/index.d.ts +0 -44
  104. package/build/src/TokenProviders/Redis/index.js +0 -129
  105. package/build/src/Tokens/OpaqueToken/index.d.ts +0 -46
  106. package/build/src/Tokens/OpaqueToken/index.js +0 -43
  107. package/build/src/Tokens/ProviderToken/index.d.ts +0 -23
  108. package/build/src/Tokens/ProviderToken/index.js +0 -27
  109. package/build/src/UserProviders/Database/User.d.ts +0 -28
  110. package/build/src/UserProviders/Database/User.js +0 -74
  111. package/build/src/UserProviders/Database/index.d.ts +0 -75
  112. package/build/src/UserProviders/Database/index.js +0 -141
  113. package/build/src/UserProviders/Lucid/User.d.ts +0 -28
  114. package/build/src/UserProviders/Lucid/User.js +0 -74
  115. package/build/src/UserProviders/Lucid/index.d.ts +0 -72
  116. package/build/src/UserProviders/Lucid/index.js +0 -146
  117. package/build/standalone.d.ts +0 -1
  118. package/build/standalone.js +0 -13
  119. package/build/templates/config/auth.txt +0 -34
  120. package/build/templates/config/partials/api-guard.txt +0 -22
  121. package/build/templates/config/partials/basic-guard.txt +0 -19
  122. package/build/templates/config/partials/tokens-provider-database.txt +0 -19
  123. package/build/templates/config/partials/tokens-provider-redis.txt +0 -22
  124. package/build/templates/config/partials/user-provider-database.txt +0 -43
  125. package/build/templates/config/partials/user-provider-lucid.txt +0 -45
  126. package/build/templates/config/partials/web-guard.txt +0 -17
  127. package/build/templates/contract/auth.txt +0 -55
  128. package/build/templates/contract/partials/api-guard.txt +0 -14
  129. package/build/templates/contract/partials/basic-guard.txt +0 -14
  130. package/build/templates/contract/partials/user-provider-database.txt +0 -16
  131. package/build/templates/contract/partials/user-provider-lucid.txt +0 -16
  132. package/build/templates/contract/partials/web-guard.txt +0 -14
  133. package/build/templates/middleware/Auth.txt +0 -76
  134. package/build/templates/middleware/SilentAuth.txt +0 -21
  135. package/build/templates/migrations/api_tokens.txt +0 -25
  136. package/build/templates/migrations/auth.txt +0 -24
  137. package/build/templates/model.txt +0 -30
@@ -1,23 +0,0 @@
1
- import '@japa/api-client';
2
- import { GuardsList, ProvidersList, AuthManagerContract, GetProviderRealUser } from '@ioc:Adonis/Addons/Auth';
3
- declare module '@japa/api-client' {
4
- interface ApiRequest {
5
- /**
6
- * Auth manager reference
7
- */
8
- authManager: AuthManagerContract;
9
- /**
10
- * Switch guard to login during the request
11
- */
12
- guard<K extends keyof GuardsList, Self>(this: Self, guard: K): {
13
- /**
14
- * Login as a user
15
- */
16
- loginAs(...args: Parameters<GuardsList[K]['client']['login']>): Self;
17
- };
18
- /**
19
- * Login as a user
20
- */
21
- loginAs(user: GetProviderRealUser<keyof ProvidersList>): this;
22
- }
23
- }
@@ -1,338 +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
- const path_1 = require("path");
12
- const helpers_1 = require("@poppinss/utils/build/helpers");
13
- // const USER_MIGRATION_TIME_PREFIX = '1587988332388'
14
- // const TOKENS_MIGRATION_TIME_PREFIX = '1592489784670'
15
- /**
16
- * Base path to contract stub partials
17
- */
18
- const CONTRACTS_PARTIALS_BASE = './contract/partials';
19
- /**
20
- * Base path to config stub partials
21
- */
22
- const CONFIG_PARTIALS_BASE = './config/partials';
23
- /**
24
- * Prompt choices for the provider selection
25
- */
26
- const PROVIDER_PROMPT_CHOICES = [
27
- {
28
- name: 'lucid',
29
- message: 'Lucid',
30
- hint: ' (Uses Data Models)',
31
- },
32
- {
33
- name: 'database',
34
- message: 'Database',
35
- hint: ' (Uses Database QueryBuilder)',
36
- },
37
- ];
38
- /**
39
- * Prompt choices for the guard selection
40
- */
41
- const GUARD_PROMPT_CHOICES = [
42
- {
43
- name: 'web',
44
- message: 'Web',
45
- hint: ' (Uses sessions for managing auth state)',
46
- },
47
- {
48
- name: 'api',
49
- message: 'API tokens',
50
- hint: ' (Uses database backed opaque tokens)',
51
- },
52
- {
53
- name: 'basic',
54
- message: 'Basic Auth',
55
- hint: ' (Uses HTTP Basic auth for authenticating requests)',
56
- },
57
- ];
58
- /**
59
- * Prompt choices for the tokens provider selection
60
- */
61
- const TOKENS_PROVIDER_PROMPT_CHOICES = [
62
- {
63
- name: 'database',
64
- message: 'Database',
65
- hint: ' (Uses SQL table for storing API tokens)',
66
- },
67
- {
68
- name: 'redis',
69
- message: 'Redis',
70
- hint: ' (Uses Redis for storing API tokens)',
71
- },
72
- ];
73
- /**
74
- * Returns absolute path to the stub relative from the templates
75
- * directory
76
- */
77
- function getStub(...relativePaths) {
78
- return (0, path_1.join)(__dirname, 'templates', ...relativePaths);
79
- }
80
- /**
81
- * Creates the model file
82
- */
83
- function makeModel(projectRoot, app, sink, state) {
84
- const modelsDirectory = app.resolveNamespaceDirectory('models') || 'app/Models';
85
- const modelPath = (0, path_1.join)(modelsDirectory, `${state.modelName}.ts`);
86
- const template = new sink.files.MustacheFile(projectRoot, modelPath, getStub('model.txt'));
87
- if (template.exists()) {
88
- sink.logger.action('create').skipped(`${modelPath} file already exists`);
89
- return;
90
- }
91
- template.apply(state).commit();
92
- sink.logger.action('create').succeeded(modelPath);
93
- }
94
- /**
95
- * Create the migration file
96
- */
97
- function makeUsersMigration(projectRoot, app, sink, state) {
98
- const migrationsDirectory = app.directoriesMap.get('migrations') || 'database';
99
- const migrationPath = (0, path_1.join)(migrationsDirectory, `${Date.now()}_${state.usersTableName}.ts`);
100
- const template = new sink.files.MustacheFile(projectRoot, migrationPath, getStub('migrations/auth.txt'));
101
- if (template.exists()) {
102
- sink.logger.action('create').skipped(`${migrationPath} file already exists`);
103
- return;
104
- }
105
- template.apply(state).commit();
106
- sink.logger.action('create').succeeded(migrationPath);
107
- }
108
- /**
109
- * Create the migration file
110
- */
111
- function makeTokensMigration(projectRoot, app, sink, state) {
112
- const migrationsDirectory = app.directoriesMap.get('migrations') || 'database';
113
- const migrationPath = (0, path_1.join)(migrationsDirectory, `${Date.now()}_${state.tokensTableName}.ts`);
114
- const template = new sink.files.MustacheFile(projectRoot, migrationPath, getStub('migrations/api_tokens.txt'));
115
- if (template.exists()) {
116
- sink.logger.action('create').skipped(`${migrationPath} file already exists`);
117
- return;
118
- }
119
- template.apply(state).commit();
120
- sink.logger.action('create').succeeded(migrationPath);
121
- }
122
- /**
123
- * Create the middleware(s)
124
- */
125
- function makeMiddleware(projectRoot, app, sink, state) {
126
- const middlewareDirectory = app.resolveNamespaceDirectory('middleware') || 'app/Middleware';
127
- /**
128
- * Auth middleware
129
- */
130
- const authPath = (0, path_1.join)(middlewareDirectory, 'Auth.ts');
131
- const authTemplate = new sink.files.MustacheFile(projectRoot, authPath, getStub('middleware/Auth.txt'));
132
- if (authTemplate.exists()) {
133
- sink.logger.action('create').skipped(`${authPath} file already exists`);
134
- }
135
- else {
136
- authTemplate.apply(state).commit();
137
- sink.logger.action('create').succeeded(authPath);
138
- }
139
- /**
140
- * Silent auth middleware
141
- */
142
- const silentAuthPath = (0, path_1.join)(middlewareDirectory, 'SilentAuth.ts');
143
- const silentAuthTemplate = new sink.files.MustacheFile(projectRoot, silentAuthPath, getStub('middleware/SilentAuth.txt'));
144
- if (silentAuthTemplate.exists()) {
145
- sink.logger.action('create').skipped(`${silentAuthPath} file already exists`);
146
- }
147
- else {
148
- silentAuthTemplate.apply(state).commit();
149
- sink.logger.action('create').succeeded(silentAuthPath);
150
- }
151
- }
152
- /**
153
- * Creates the contract file
154
- */
155
- function makeContract(projectRoot, app, sink, state) {
156
- const contractsDirectory = app.directoriesMap.get('contracts') || 'contracts';
157
- const contractPath = (0, path_1.join)(contractsDirectory, 'auth.ts');
158
- const template = new sink.files.MustacheFile(projectRoot, contractPath, getStub('contract/auth.txt'));
159
- template.overwrite = true;
160
- const partials = {
161
- provider: getStub(CONTRACTS_PARTIALS_BASE, `user-provider-${state.provider}.txt`),
162
- };
163
- state.guards.forEach((guard) => {
164
- partials[`${guard}_guard`] = getStub(CONTRACTS_PARTIALS_BASE, `${guard}-guard.txt`);
165
- });
166
- template.apply(state).partials(partials).commit();
167
- sink.logger.action('create').succeeded(contractPath);
168
- }
169
- /**
170
- * Makes the auth config file
171
- */
172
- function makeConfig(projectRoot, app, sink, state) {
173
- const configDirectory = app.directoriesMap.get('config') || 'config';
174
- const configPath = (0, path_1.join)(configDirectory, 'auth.ts');
175
- const template = new sink.files.MustacheFile(projectRoot, configPath, getStub('config/auth.txt'));
176
- template.overwrite = true;
177
- const partials = {
178
- provider: getStub(CONFIG_PARTIALS_BASE, `user-provider-${state.provider}.txt`),
179
- token_provider: getStub(CONFIG_PARTIALS_BASE, `tokens-provider-${state.tokensProvider}.txt`),
180
- };
181
- state.guards.forEach((guard) => {
182
- partials[`${guard}_guard`] = getStub(CONFIG_PARTIALS_BASE, `${guard}-guard.txt`);
183
- });
184
- template.apply(state).partials(partials).commit();
185
- sink.logger.action('create').succeeded(configPath);
186
- }
187
- /**
188
- * Prompts user to select the provider
189
- */
190
- async function getProvider(sink) {
191
- return sink.getPrompt().choice('Select provider for finding users', PROVIDER_PROMPT_CHOICES, {
192
- validate(choice) {
193
- return choice && choice.length ? true : 'Select the provider for finding users';
194
- },
195
- });
196
- }
197
- /**
198
- * Prompts user to select the tokens provider
199
- */
200
- async function getTokensProvider(sink) {
201
- return sink
202
- .getPrompt()
203
- .choice('Select the provider for storing API tokens', TOKENS_PROVIDER_PROMPT_CHOICES, {
204
- validate(choice) {
205
- return choice && choice.length ? true : 'Select the provider for storing API tokens';
206
- },
207
- });
208
- }
209
- /**
210
- * Prompts user to select one or more guards
211
- */
212
- async function getGuard(sink) {
213
- return sink
214
- .getPrompt()
215
- .multiple('Select which guard you need for authentication (select using space)', GUARD_PROMPT_CHOICES, {
216
- validate(choices) {
217
- return choices && choices.length
218
- ? true
219
- : 'Select one or more guards for authenticating users';
220
- },
221
- });
222
- }
223
- /**
224
- * Prompts user for the model name
225
- */
226
- async function getModelName(sink) {
227
- return sink.getPrompt().ask('Enter model name to be used for authentication', {
228
- validate(value) {
229
- return !!value.trim().length;
230
- },
231
- });
232
- }
233
- /**
234
- * Prompts user for the table name
235
- */
236
- async function getTableName(sink) {
237
- return sink.getPrompt().ask('Enter the database table name to look up users', {
238
- validate(value) {
239
- return !!value.trim().length;
240
- },
241
- });
242
- }
243
- /**
244
- * Prompts user for the table name
245
- */
246
- async function getMigrationConsent(sink, tableName) {
247
- return sink
248
- .getPrompt()
249
- .confirm(`Create migration for the ${sink.logger.colors.underline(tableName)} table?`);
250
- }
251
- /**
252
- * Instructions to be executed when setting up the package.
253
- */
254
- async function instructions(projectRoot, app, sink) {
255
- const state = {
256
- usersTableName: '',
257
- tokensTableName: 'api_tokens',
258
- tokensSchemaName: 'ApiTokens',
259
- usersSchemaName: '',
260
- provider: 'lucid',
261
- tokensProvider: 'database',
262
- guards: [],
263
- hasGuard: {
264
- web: false,
265
- api: false,
266
- basic: false,
267
- },
268
- };
269
- state.provider = await getProvider(sink);
270
- state.guards = await getGuard(sink);
271
- /**
272
- * Need booleans for mustache templates
273
- */
274
- state.guards.forEach((guard) => (state.hasGuard[guard] = true));
275
- /**
276
- * Make model when provider is lucid otherwise prompt for the database
277
- * table name
278
- */
279
- if (state.provider === 'lucid') {
280
- const modelName = await getModelName(sink);
281
- state.modelName = helpers_1.string.pascalCase(helpers_1.string.singularize(modelName.replace(/(\.ts|\.js)$/, '')));
282
- state.usersTableName = helpers_1.string.pluralize(helpers_1.string.snakeCase(state.modelName));
283
- state.modelReference = helpers_1.string.camelCase(helpers_1.string.singularize(state.modelName));
284
- state.modelNamespace = `${app.namespacesMap.get('models') || 'App/Models'}/${state.modelName}`;
285
- }
286
- else {
287
- state.usersTableName = await getTableName(sink);
288
- }
289
- const usersMigrationConsent = await getMigrationConsent(sink, state.usersTableName);
290
- let tokensMigrationConsent = false;
291
- /**
292
- * Only ask for the consent when using the api guard
293
- */
294
- if (state.hasGuard.api) {
295
- state.tokensProvider = await getTokensProvider(sink);
296
- if (state.tokensProvider === 'database') {
297
- tokensMigrationConsent = await getMigrationConsent(sink, state.tokensTableName);
298
- }
299
- }
300
- /**
301
- * Pascal case
302
- */
303
- const camelCaseSchemaName = helpers_1.string.camelCase(`${state.usersTableName}_schema`);
304
- state.usersSchemaName = `${camelCaseSchemaName
305
- .charAt(0)
306
- .toUpperCase()}${camelCaseSchemaName.slice(1)}`;
307
- /**
308
- * Make model when prompted for it
309
- */
310
- if (state.modelName) {
311
- makeModel(projectRoot, app, sink, state);
312
- }
313
- /**
314
- * Make users migration file
315
- */
316
- if (usersMigrationConsent) {
317
- makeUsersMigration(projectRoot, app, sink, state);
318
- }
319
- /**
320
- * Make tokens migration file
321
- */
322
- if (tokensMigrationConsent) {
323
- makeTokensMigration(projectRoot, app, sink, state);
324
- }
325
- /**
326
- * Make contract file
327
- */
328
- makeContract(projectRoot, app, sink, state);
329
- /**
330
- * Make config file
331
- */
332
- makeConfig(projectRoot, app, sink, state);
333
- /**
334
- * Make middleware
335
- */
336
- makeMiddleware(projectRoot, app, sink, state);
337
- }
338
- exports.default = instructions;
@@ -1,30 +0,0 @@
1
- /// <reference types="@adonisjs/application/build/adonis-typings/application" />
2
- import { ApplicationContract } from '@ioc:Adonis/Core/Application';
3
- /**
4
- * Auth provider to register the auth binding
5
- */
6
- export default class AuthProvider {
7
- protected application: ApplicationContract;
8
- constructor(application: ApplicationContract);
9
- static needsApplication: boolean;
10
- /**
11
- * Register auth binding
12
- */
13
- register(): void;
14
- /**
15
- * Sharing the auth object with HTTP context
16
- */
17
- protected registerAuthWithHttpContext(): void;
18
- /**
19
- * Sharing auth with all the templates
20
- */
21
- protected shareAuthWithViews(): void;
22
- /**
23
- * Register test bindings
24
- */
25
- protected registerTestBindings(): void;
26
- /**
27
- * Hook into boot to register auth macro
28
- */
29
- boot(): Promise<void>;
30
- }
@@ -1,69 +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
- /**
12
- * Auth provider to register the auth binding
13
- */
14
- class AuthProvider {
15
- constructor(application) {
16
- this.application = application;
17
- }
18
- /**
19
- * Register auth binding
20
- */
21
- register() {
22
- this.application.container.singleton('Adonis/Addons/Auth', () => {
23
- const authConfig = this.application.container
24
- .resolveBinding('Adonis/Core/Config')
25
- .get('auth', {});
26
- const { AuthManager } = require('../src/AuthManager');
27
- return new AuthManager(this.application, authConfig);
28
- });
29
- }
30
- /**
31
- * Sharing the auth object with HTTP context
32
- */
33
- registerAuthWithHttpContext() {
34
- this.application.container.withBindings(['Adonis/Core/HttpContext', 'Adonis/Addons/Auth'], (HttpContext, Auth) => {
35
- HttpContext.getter('auth', function auth() {
36
- return Auth.getAuthForRequest(this);
37
- }, true);
38
- });
39
- }
40
- /**
41
- * Sharing auth with all the templates
42
- */
43
- shareAuthWithViews() {
44
- this.application.container.withBindings(['Adonis/Core/Server', 'Adonis/Core/View'], (Server) => {
45
- Server.hooks.before(async (ctx) => {
46
- ctx['view'].share({ auth: ctx.auth });
47
- });
48
- });
49
- }
50
- /**
51
- * Register test bindings
52
- */
53
- registerTestBindings() {
54
- this.application.container.withBindings(['Japa/Preset/ApiRequest', 'Japa/Preset/ApiClient', 'Adonis/Addons/Auth'], (ApiRequest, ApiClient, Auth) => {
55
- const { defineTestsBindings } = require('../src/Bindings/Tests');
56
- return defineTestsBindings(ApiRequest, ApiClient, Auth);
57
- });
58
- }
59
- /**
60
- * Hook into boot to register auth macro
61
- */
62
- async boot() {
63
- this.registerAuthWithHttpContext();
64
- this.shareAuthWithViews();
65
- this.registerTestBindings();
66
- }
67
- }
68
- exports.default = AuthProvider;
69
- AuthProvider.needsApplication = true;
@@ -1,97 +0,0 @@
1
- import { HttpContextContract } from '@ioc:Adonis/Core/HttpContext';
2
- import { AuthContract, AuthManagerContract } from '@ioc:Adonis/Addons/Auth';
3
- /**
4
- * Auth class exposes the API to obtain guard instances for a given
5
- * HTTP request.
6
- */
7
- export declare class Auth implements AuthContract {
8
- private manager;
9
- private ctx;
10
- /**
11
- * We keep a per request singleton instances for each instantiated mapping
12
- */
13
- private mappingsCache;
14
- /**
15
- * The default guard is always the one defined inside the config, until
16
- * manually overwritten by the user
17
- */
18
- defaultGuard: string;
19
- constructor(manager: AuthManagerContract, ctx: HttpContextContract);
20
- /**
21
- * Returns an instance of a named or the default mapping
22
- */
23
- use(mapping?: string): any;
24
- /**
25
- * Guard name for the default mapping
26
- */
27
- get name(): any;
28
- /**
29
- * Reference to the logged in user
30
- */
31
- get user(): any;
32
- /**
33
- * Reference to the default guard config
34
- */
35
- get config(): any;
36
- /**
37
- * Find if the user has been logged out in the current request
38
- */
39
- get isLoggedOut(): any;
40
- /**
41
- * A boolean to know if user is a guest or not. It is
42
- * always opposite of [[isLoggedIn]]
43
- */
44
- get isGuest(): any;
45
- /**
46
- * A boolean to know if user is logged in or not
47
- */
48
- get isLoggedIn(): any;
49
- /**
50
- * A boolean to know if user is retrieved by authenticating
51
- * the current request or not.
52
- */
53
- get isAuthenticated(): any;
54
- /**
55
- * Whether or not the authentication has been attempted
56
- * for the current request
57
- */
58
- get authenticationAttempted(): any;
59
- /**
60
- * Reference to the provider for looking up the user
61
- */
62
- get provider(): any;
63
- /**
64
- * Verify user credentials.
65
- */
66
- verifyCredentials(uid: string, password: string): Promise<any>;
67
- /**
68
- * Attempt to verify user credentials and perform login
69
- */
70
- attempt(uid: string, password: string, ...args: any[]): Promise<any>;
71
- /**
72
- * Login a user without any verification
73
- */
74
- login(user: any, ...args: any[]): Promise<any>;
75
- /**
76
- * Login a user using their id
77
- */
78
- loginViaId(id: string | number, ...args: any[]): Promise<any>;
79
- /**
80
- * Attempts to authenticate the user for the current HTTP request. An exception
81
- * is raised when unable to do so
82
- */
83
- authenticate(): Promise<any>;
84
- /**
85
- * Attempts to authenticate the user for the current HTTP request and supresses
86
- * exceptions raised by the [[authenticate]] method and returns a boolean
87
- */
88
- check(): Promise<any>;
89
- /**
90
- * Logout user
91
- */
92
- logout(...args: any[]): Promise<any>;
93
- /**
94
- * Serialize toJSON
95
- */
96
- toJSON(): any;
97
- }