@adonisjs/auth 9.0.0-9 → 9.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 (125) hide show
  1. package/build/chunk-3HZHOWKL.js +8 -0
  2. package/build/chunk-3HZHOWKL.js.map +1 -0
  3. package/build/chunk-CZCFTIBB.js +21 -0
  4. package/build/chunk-CZCFTIBB.js.map +1 -0
  5. package/build/chunk-OL2Z3AO5.js +246 -0
  6. package/build/chunk-OL2Z3AO5.js.map +1 -0
  7. package/build/chunk-UGHJLKDI.js +197 -0
  8. package/build/chunk-UGHJLKDI.js.map +1 -0
  9. package/build/index.d.ts +7 -6
  10. package/build/index.js +149 -15
  11. package/build/index.js.map +1 -0
  12. package/build/modules/access_tokens_guard/access_token.d.ts +137 -0
  13. package/build/modules/access_tokens_guard/crc32.d.ts +16 -0
  14. package/build/modules/access_tokens_guard/define_config.d.ts +17 -0
  15. package/build/modules/access_tokens_guard/guard.d.ts +81 -0
  16. package/build/modules/access_tokens_guard/main.d.ts +5 -0
  17. package/build/modules/access_tokens_guard/main.js +929 -0
  18. package/build/modules/access_tokens_guard/main.js.map +1 -0
  19. package/build/modules/access_tokens_guard/token_providers/db.d.ts +76 -0
  20. package/build/modules/access_tokens_guard/types.d.ts +208 -0
  21. package/build/modules/access_tokens_guard/types.js +1 -0
  22. package/build/modules/access_tokens_guard/types.js.map +1 -0
  23. package/build/modules/access_tokens_guard/user_providers/lucid.d.ts +53 -0
  24. package/build/modules/session_guard/define_config.d.ts +17 -0
  25. package/build/modules/session_guard/guard.d.ts +98 -0
  26. package/build/modules/session_guard/main.d.ts +5 -0
  27. package/build/modules/session_guard/main.js +741 -0
  28. package/build/modules/session_guard/main.js.map +1 -0
  29. package/build/modules/session_guard/remember_me_token.d.ts +88 -0
  30. package/build/modules/session_guard/token_providers/db.d.ts +69 -0
  31. package/build/modules/session_guard/types.d.ts +243 -0
  32. package/build/modules/session_guard/types.js +1 -0
  33. package/build/modules/session_guard/types.js.map +1 -0
  34. package/build/modules/session_guard/user_providers/lucid.d.ts +57 -0
  35. package/build/providers/auth_provider.d.ts +1 -1
  36. package/build/providers/auth_provider.js +31 -27
  37. package/build/providers/auth_provider.js.map +1 -0
  38. package/build/services/auth.d.ts +1 -1
  39. package/build/services/auth.js +10 -15
  40. package/build/services/auth.js.map +1 -0
  41. package/build/src/{auth/auth_manager.d.ts → auth_manager.d.ts} +8 -3
  42. package/build/src/authenticator.d.ts +81 -0
  43. package/build/src/{auth/authenticator_client.d.ts → authenticator_client.d.ts} +4 -4
  44. package/build/src/{auth/define_config.d.ts → define_config.d.ts} +0 -10
  45. package/build/src/errors.d.ts +105 -0
  46. package/build/src/{auth/middleware → middleware}/initialize_auth_middleware.d.ts +3 -2
  47. package/build/src/middleware/initialize_auth_middleware.js +17 -0
  48. package/build/src/middleware/initialize_auth_middleware.js.map +1 -0
  49. package/build/src/mixins/with_auth_finder.d.ts +156 -0
  50. package/build/src/{auth/plugins → plugins}/japa/api_client.d.ts +8 -8
  51. package/build/src/plugins/japa/api_client.js +59 -0
  52. package/build/src/plugins/japa/api_client.js.map +1 -0
  53. package/build/src/{auth/plugins → plugins}/japa/browser_client.d.ts +10 -7
  54. package/build/src/plugins/japa/browser_client.js +67 -0
  55. package/build/src/plugins/japa/browser_client.js.map +1 -0
  56. package/build/src/{auth/types.d.ts → types.d.ts} +31 -26
  57. package/build/src/types.js +1 -0
  58. package/build/src/types.js.map +1 -0
  59. package/package.json +88 -68
  60. package/build/configure.js +0 -47
  61. package/build/factories/basic_auth_guard_factory.d.ts +0 -12
  62. package/build/factories/basic_auth_guard_factory.js +0 -22
  63. package/build/factories/database_token_factory.d.ts +0 -36
  64. package/build/factories/database_token_factory.js +0 -54
  65. package/build/factories/database_user_provider.d.ts +0 -14
  66. package/build/factories/database_user_provider.js +0 -27
  67. package/build/factories/lucid_user_provider.d.ts +0 -28
  68. package/build/factories/lucid_user_provider.js +0 -68
  69. package/build/factories/main.d.ts +0 -4
  70. package/build/factories/main.js +0 -12
  71. package/build/factories/session_guard_factory.d.ts +0 -13
  72. package/build/factories/session_guard_factory.js +0 -24
  73. package/build/src/auth/auth_manager.js +0 -41
  74. package/build/src/auth/authenticator.d.ts +0 -63
  75. package/build/src/auth/authenticator.js +0 -129
  76. package/build/src/auth/authenticator_client.js +0 -59
  77. package/build/src/auth/debug.js +0 -10
  78. package/build/src/auth/define_config.js +0 -54
  79. package/build/src/auth/errors.d.ts +0 -90
  80. package/build/src/auth/errors.js +0 -201
  81. package/build/src/auth/middleware/initialize_auth_middleware.js +0 -25
  82. package/build/src/auth/plugins/japa/api_client.js +0 -63
  83. package/build/src/auth/plugins/japa/browser_client.js +0 -64
  84. package/build/src/auth/symbols.js +0 -17
  85. package/build/src/auth/types.js +0 -9
  86. package/build/src/auth/user_providers/main.d.ts +0 -15
  87. package/build/src/auth/user_providers/main.js +0 -22
  88. package/build/src/core/guard_user.d.ts +0 -26
  89. package/build/src/core/guard_user.js +0 -29
  90. package/build/src/core/token.d.ts +0 -89
  91. package/build/src/core/token.js +0 -114
  92. package/build/src/core/token_providers/database.d.ts +0 -77
  93. package/build/src/core/token_providers/database.js +0 -113
  94. package/build/src/core/types.d.ts +0 -178
  95. package/build/src/core/types.js +0 -9
  96. package/build/src/core/user_providers/database.d.ts +0 -78
  97. package/build/src/core/user_providers/database.js +0 -117
  98. package/build/src/core/user_providers/lucid.d.ts +0 -61
  99. package/build/src/core/user_providers/lucid.js +0 -122
  100. package/build/src/guards/basic_auth/define_config.d.ts +0 -16
  101. package/build/src/guards/basic_auth/define_config.js +0 -38
  102. package/build/src/guards/basic_auth/guard.d.ts +0 -70
  103. package/build/src/guards/basic_auth/guard.js +0 -190
  104. package/build/src/guards/basic_auth/main.d.ts +0 -2
  105. package/build/src/guards/basic_auth/main.js +0 -10
  106. package/build/src/guards/basic_auth/types.d.ts +0 -35
  107. package/build/src/guards/basic_auth/types.js +0 -9
  108. package/build/src/guards/session/define_config.d.ts +0 -23
  109. package/build/src/guards/session/define_config.js +0 -56
  110. package/build/src/guards/session/guard.d.ts +0 -123
  111. package/build/src/guards/session/guard.js +0 -510
  112. package/build/src/guards/session/main.d.ts +0 -3
  113. package/build/src/guards/session/main.js +0 -11
  114. package/build/src/guards/session/token.d.ts +0 -57
  115. package/build/src/guards/session/token.js +0 -58
  116. package/build/src/guards/session/token_providers/main.d.ts +0 -33
  117. package/build/src/guards/session/token_providers/main.js +0 -42
  118. package/build/src/guards/session/types.d.ts +0 -104
  119. package/build/src/guards/session/types.js +0 -9
  120. package/build/stubs/main.d.ts +0 -1
  121. package/build/stubs/main.js +0 -10
  122. package/build/stubs/middleware/auth_middleware.stub +0 -30
  123. package/build/stubs/middleware/guest_middleware.stub +0 -36
  124. /package/build/src/{auth/debug.d.ts → debug.d.ts} +0 -0
  125. /package/build/src/{auth/symbols.d.ts → symbols.d.ts} +0 -0
@@ -1,28 +0,0 @@
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
- }
@@ -1,68 +0,0 @@
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
- }
@@ -1,4 +0,0 @@
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';
@@ -1,12 +0,0 @@
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';
@@ -1,13 +0,0 @@
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
- }
@@ -1,24 +0,0 @@
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
- }
@@ -1,41 +0,0 @@
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
- import { AuthenticatorClient } from './authenticator_client.js';
11
- /**
12
- * Auth manager exposes the API to register and manage authentication
13
- * guards from the config
14
- */
15
- export class AuthManager {
16
- /**
17
- * Registered guards
18
- */
19
- #config;
20
- /**
21
- * Name of the default guard
22
- */
23
- get defaultGuard() {
24
- return this.#config.default;
25
- }
26
- constructor(config) {
27
- this.#config = config;
28
- }
29
- /**
30
- * Create an authenticator for a given HTTP request
31
- */
32
- createAuthenticator(ctx) {
33
- return new Authenticator(ctx, this.#config);
34
- }
35
- /**
36
- * Creates an instance of the authenticator client
37
- */
38
- createAuthenticatorClient() {
39
- return new AuthenticatorClient(this.#config);
40
- }
41
- }
@@ -1,63 +0,0 @@
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
- /**
10
- * Name of the default guard
11
- */
12
- get defaultGuard(): keyof KnownGuards;
13
- /**
14
- * Reference to the guard using which the current
15
- * request has been authenticated.
16
- */
17
- get authenticatedViaGuard(): keyof KnownGuards | undefined;
18
- /**
19
- * A boolean to know if the current request has
20
- * been authenticated
21
- */
22
- get isAuthenticated(): boolean;
23
- /**
24
- * Reference to the currently authenticated user
25
- */
26
- get user(): {
27
- [K in keyof KnownGuards]: ReturnType<KnownGuards[K]>['user'];
28
- }[keyof KnownGuards];
29
- /**
30
- * Whether or not the authentication has been attempted
31
- * during the current request
32
- */
33
- get authenticationAttempted(): boolean;
34
- constructor(ctx: HttpContext, config: {
35
- default: keyof KnownGuards;
36
- guards: KnownGuards;
37
- });
38
- /**
39
- * Returns an instance of the logged-in user or throws an
40
- * exception
41
- */
42
- getUserOrFail(): {
43
- [K in keyof KnownGuards]: ReturnType<ReturnType<KnownGuards[K]>['getUserOrFail']>;
44
- }[keyof KnownGuards];
45
- /**
46
- * Returns an instance of a known guard. Guards instances are
47
- * cached during the lifecycle of an HTTP request.
48
- */
49
- use<Guard extends keyof KnownGuards>(guard?: Guard): ReturnType<KnownGuards[Guard]>;
50
- /**
51
- * Authenticate the request using all of the mentioned
52
- * guards or the default guard.
53
- *
54
- * The authentication process will stop after any of the
55
- * mentioned guards is able to authenticate the request
56
- * successfully.
57
- *
58
- * Otherwise, "AuthenticationException" will be raised.
59
- */
60
- authenticateUsing(guards?: (keyof KnownGuards)[], options?: {
61
- loginRoute?: string;
62
- }): Promise<boolean>;
63
- }
@@ -1,129 +0,0 @@
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
- import { AuthenticationException } from './errors.js';
11
- /**
12
- * Authenticator is an HTTP request specific implementation for using
13
- * guards to login users and authenticate requests.
14
- */
15
- export class Authenticator {
16
- /**
17
- * Name of the guard using which the request has
18
- * been authenticated
19
- */
20
- #authenticatedViaGuard;
21
- /**
22
- * Reference to HTTP context
23
- */
24
- #ctx;
25
- /**
26
- * Registered guards
27
- */
28
- #config;
29
- /**
30
- * Cache of guards created during the HTTP request
31
- */
32
- #guardsCache = {};
33
- /**
34
- * Name of the default guard
35
- */
36
- get defaultGuard() {
37
- return this.#config.default;
38
- }
39
- /**
40
- * Reference to the guard using which the current
41
- * request has been authenticated.
42
- */
43
- get authenticatedViaGuard() {
44
- return this.#authenticatedViaGuard;
45
- }
46
- /**
47
- * A boolean to know if the current request has
48
- * been authenticated
49
- */
50
- get isAuthenticated() {
51
- return this.use(this.#authenticatedViaGuard || this.defaultGuard).isAuthenticated;
52
- }
53
- /**
54
- * Reference to the currently authenticated user
55
- */
56
- get user() {
57
- return this.use(this.#authenticatedViaGuard || this.defaultGuard).user;
58
- }
59
- /**
60
- * Whether or not the authentication has been attempted
61
- * during the current request
62
- */
63
- get authenticationAttempted() {
64
- return this.use(this.#authenticatedViaGuard || this.defaultGuard).authenticationAttempted;
65
- }
66
- constructor(ctx, config) {
67
- this.#ctx = ctx;
68
- this.#config = config;
69
- debug('creating authenticator. config %O', this.#config);
70
- }
71
- /**
72
- * Returns an instance of the logged-in user or throws an
73
- * exception
74
- */
75
- getUserOrFail() {
76
- return this.use(this.#authenticatedViaGuard || this.defaultGuard).getUserOrFail();
77
- }
78
- /**
79
- * Returns an instance of a known guard. Guards instances are
80
- * cached during the lifecycle of an HTTP request.
81
- */
82
- use(guard) {
83
- const guardToUse = guard || this.#config.default;
84
- /**
85
- * Use cached copy if exists
86
- */
87
- const cachedGuard = this.#guardsCache[guardToUse];
88
- if (cachedGuard) {
89
- debug('using guard from cache. name: "%s"', guardToUse);
90
- return cachedGuard;
91
- }
92
- const guardFactory = this.#config.guards[guardToUse];
93
- /**
94
- * Construct guard and cache it
95
- */
96
- debug('creating guard. name: "%s"', guardToUse);
97
- const guardInstance = guardFactory(this.#ctx);
98
- this.#guardsCache[guardToUse] = guardInstance;
99
- return guardInstance;
100
- }
101
- /**
102
- * Authenticate the request using all of the mentioned
103
- * guards or the default guard.
104
- *
105
- * The authentication process will stop after any of the
106
- * mentioned guards is able to authenticate the request
107
- * successfully.
108
- *
109
- * Otherwise, "AuthenticationException" will be raised.
110
- */
111
- async authenticateUsing(guards, options) {
112
- const guardsToUse = guards || [this.defaultGuard];
113
- let lastUsedGuardDriver;
114
- for (let guardName of guardsToUse) {
115
- debug('attempting to authenticate using guard "%s"', guardName);
116
- const guard = this.use(guardName);
117
- lastUsedGuardDriver = guard.driverName;
118
- if (await guard.check()) {
119
- this.#authenticatedViaGuard = guardName;
120
- return true;
121
- }
122
- }
123
- throw new AuthenticationException('Unauthorized access', {
124
- code: 'E_UNAUTHORIZED_ACCESS',
125
- guardDriverName: lastUsedGuardDriver,
126
- redirectTo: options?.loginRoute,
127
- });
128
- }
129
- }
@@ -1,59 +0,0 @@
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
- import { HttpContextFactory } from '@adonisjs/core/factories/http';
11
- /**
12
- * Authenticator client is used to create guard instances for
13
- * testing. It passes a fake HTTPContext to the guards, so
14
- * make sure to not call server side APIs that might be
15
- * relying on a real HTTPContext instance
16
- */
17
- export class AuthenticatorClient {
18
- /**
19
- * Registered guards
20
- */
21
- #config;
22
- /**
23
- * Cache of guards
24
- */
25
- #guardsCache = {};
26
- /**
27
- * Name of the default guard
28
- */
29
- get defaultGuard() {
30
- return this.#config.default;
31
- }
32
- constructor(config) {
33
- this.#config = config;
34
- debug('creating authenticator client. config %O', this.#config);
35
- }
36
- /**
37
- * Returns an instance of a known guard. Guards instances are
38
- * cached during the lifecycle of an HTTP request.
39
- */
40
- use(guard) {
41
- const guardToUse = guard || this.#config.default;
42
- /**
43
- * Use cached copy if exists
44
- */
45
- const cachedGuard = this.#guardsCache[guardToUse];
46
- if (cachedGuard) {
47
- debug('using guard from cache. name: "%s"', guardToUse);
48
- return cachedGuard;
49
- }
50
- const guardFactory = this.#config.guards[guardToUse];
51
- /**
52
- * Construct guard and cache it
53
- */
54
- debug('creating guard. name: "%s"', guardToUse);
55
- const guardInstance = guardFactory(new HttpContextFactory().create());
56
- this.#guardsCache[guardToUse] = guardInstance;
57
- return guardInstance;
58
- }
59
- }
@@ -1,10 +0,0 @@
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 { debuglog } from 'node:util';
10
- export default debuglog('adonisjs:auth');
@@ -1,54 +0,0 @@
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
- /// <reference types="@adonisjs/lucid/database_provider" />
10
- import { configProvider } from '@adonisjs/core';
11
- /**
12
- * Define configuration for the auth package. The function returns
13
- * a config provider that is invoked inside the auth service
14
- * provider
15
- */
16
- export function defineConfig(config) {
17
- return configProvider.create(async (app) => {
18
- const guardsList = Object.keys(config.guards);
19
- const guards = {};
20
- for (let guardName of guardsList) {
21
- const guard = config.guards[guardName];
22
- if (typeof guard === 'function') {
23
- guards[guardName] = guard;
24
- }
25
- else {
26
- guards[guardName] = await guard.resolver(guardName, app);
27
- }
28
- }
29
- return {
30
- default: config.default,
31
- guards: guards,
32
- };
33
- });
34
- }
35
- /**
36
- * Providers helper to configure user providers for
37
- * finding users for authentication
38
- */
39
- export const providers = {
40
- db(config) {
41
- return configProvider.create(async (app) => {
42
- const db = await app.container.make('lucid.db');
43
- const hasher = await app.container.make('hash');
44
- const { DatabaseUserProvider } = await import('./user_providers/main.js');
45
- return new DatabaseUserProvider(db, hasher.use(), config);
46
- });
47
- },
48
- lucid(config) {
49
- return configProvider.create(async () => {
50
- const { LucidUserProvider } = await import('./user_providers/main.js');
51
- return new LucidUserProvider(config);
52
- });
53
- },
54
- };
@@ -1,90 +0,0 @@
1
- import { Exception } from '@poppinss/utils';
2
- import { HttpContext } from '@adonisjs/core/http';
3
- /**
4
- * Authentication exception is raised when an attempt is
5
- * made to authenticate an HTTP request
6
- */
7
- export declare class AuthenticationException extends Exception {
8
- static status?: number | undefined;
9
- static code?: string | undefined;
10
- /**
11
- * Raises authentication exception when session guard
12
- * is unable to authenticate the request
13
- */
14
- static E_INVALID_AUTH_SESSION(): AuthenticationException;
15
- /**
16
- * Raises authentication exception when session guard
17
- * is unable to authenticate the request
18
- */
19
- static E_INVALID_BASIC_AUTH_CREDENTIALS(): AuthenticationException;
20
- guardDriverName: string;
21
- redirectTo?: string;
22
- identifier: string;
23
- constructor(message: string, options: ErrorOptions & {
24
- guardDriverName: string;
25
- redirectTo?: string;
26
- code?: string;
27
- status?: number;
28
- });
29
- /**
30
- * Returns the message to be sent in the HTTP response.
31
- * Feel free to override this method and return a custom
32
- * response.
33
- */
34
- getResponseMessage(error: AuthenticationException, ctx: HttpContext): string;
35
- /**
36
- * A collection of authentication exception
37
- * renderers to render the exception to a
38
- * response.
39
- *
40
- * The collection is a key-value pair, where the
41
- * key is the guard driver name and value is
42
- * a factory function to respond to the
43
- * request.
44
- */
45
- renderers: Record<string, (message: string, error: AuthenticationException, ctx: HttpContext) => Promise<void> | void>;
46
- /**
47
- * Self handles the auth exception and converts it to an
48
- * HTTP response
49
- */
50
- handle(error: AuthenticationException, ctx: HttpContext): Promise<void>;
51
- }
52
- /**
53
- * Invalid credentials exception is raised when unable
54
- * to verify user credentials during login
55
- */
56
- export declare class InvalidCredentialsException extends Exception {
57
- static message: string;
58
- static code: string;
59
- static status?: number | undefined;
60
- static E_INVALID_CREDENTIALS(guardDriverName: string): InvalidCredentialsException;
61
- guardDriverName: string;
62
- identifier: string;
63
- constructor(message: string, options: ErrorOptions & {
64
- guardDriverName: string;
65
- code?: string;
66
- status?: number;
67
- });
68
- /**
69
- * Returns the message to be sent in the HTTP response.
70
- * Feel free to override this method and return a custom
71
- * response.
72
- */
73
- getResponseMessage(error: InvalidCredentialsException, ctx: HttpContext): string;
74
- /**
75
- * A collection of authentication exception
76
- * renderers to render the exception to a
77
- * response.
78
- *
79
- * The collection is a key-value pair, where the
80
- * key is the guard driver name and value is
81
- * a factory function to respond to the
82
- * request.
83
- */
84
- renderers: Record<string, (message: string, error: InvalidCredentialsException, ctx: HttpContext) => Promise<void> | void>;
85
- /**
86
- * Self handles the auth exception and converts it to an
87
- * HTTP response
88
- */
89
- handle(error: InvalidCredentialsException, ctx: HttpContext): Promise<void>;
90
- }