@adonisjs/auth 9.1.1 → 9.2.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.
package/build/index.d.ts
CHANGED
|
@@ -4,5 +4,10 @@ export * as symbols from './src/symbols.js';
|
|
|
4
4
|
export { AuthManager } from './src/auth_manager.js';
|
|
5
5
|
export { defineConfig } from './src/define_config.js';
|
|
6
6
|
export { Authenticator } from './src/authenticator.js';
|
|
7
|
-
export { withAuthFinder } from './src/mixins/with_auth_finder.js';
|
|
8
7
|
export { AuthenticatorClient } from './src/authenticator_client.js';
|
|
8
|
+
import type { withAuthFinder as withAuthFinderType } from './src/mixins/lucid.js';
|
|
9
|
+
/**
|
|
10
|
+
* @deprecated Import `withAuthFinder` from `@adonisjs/auth/mixins/lucid` instead
|
|
11
|
+
*/
|
|
12
|
+
declare let withAuthFinder: typeof withAuthFinderType;
|
|
13
|
+
export { withAuthFinder };
|
package/build/index.js
CHANGED
|
@@ -5,11 +5,9 @@ import {
|
|
|
5
5
|
} from "./chunk-OL2Z3AO5.js";
|
|
6
6
|
import "./chunk-3HZHOWKL.js";
|
|
7
7
|
import {
|
|
8
|
-
E_INVALID_CREDENTIALS,
|
|
9
8
|
errors_exports
|
|
10
9
|
} from "./chunk-UGHJLKDI.js";
|
|
11
10
|
import {
|
|
12
|
-
__decorateClass,
|
|
13
11
|
__export
|
|
14
12
|
} from "./chunk-CZCFTIBB.js";
|
|
15
13
|
|
|
@@ -29,6 +27,10 @@ async function configure(command) {
|
|
|
29
27
|
{
|
|
30
28
|
name: "access_tokens",
|
|
31
29
|
message: "Opaque access tokens"
|
|
30
|
+
},
|
|
31
|
+
{
|
|
32
|
+
name: "basic_auth",
|
|
33
|
+
message: "Basic Auth"
|
|
32
34
|
}
|
|
33
35
|
],
|
|
34
36
|
{
|
|
@@ -38,9 +40,9 @@ async function configure(command) {
|
|
|
38
40
|
}
|
|
39
41
|
);
|
|
40
42
|
}
|
|
41
|
-
if (!["session", "access_tokens"].includes(guard)) {
|
|
43
|
+
if (!["session", "access_tokens", "basic_auth"].includes(guard)) {
|
|
42
44
|
command.logger.error(
|
|
43
|
-
`The selected guard "${guard}" is invalid. Select one from: session, access_tokens`
|
|
45
|
+
`The selected guard "${guard}" is invalid. Select one from: session, access_tokens, basic_auth`
|
|
44
46
|
);
|
|
45
47
|
command.exitCode = 1;
|
|
46
48
|
return;
|
|
@@ -81,60 +83,19 @@ function defineConfig(config) {
|
|
|
81
83
|
});
|
|
82
84
|
}
|
|
83
85
|
|
|
84
|
-
//
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
}
|
|
98
|
-
/**
|
|
99
|
-
* Finds the user for authentication via "verifyCredentials".
|
|
100
|
-
* Feel free to override this method customize the user
|
|
101
|
-
* lookup behavior.
|
|
102
|
-
*/
|
|
103
|
-
static findForAuth(uids, value) {
|
|
104
|
-
const query = this.query();
|
|
105
|
-
uids.forEach((uid) => query.orWhere(uid, value));
|
|
106
|
-
return query.limit(1).first();
|
|
107
|
-
}
|
|
108
|
-
/**
|
|
109
|
-
* Find a user by uid and verify their password. This method is
|
|
110
|
-
* safe from timing attacks.
|
|
111
|
-
*/
|
|
112
|
-
static async verifyCredentials(uid, password) {
|
|
113
|
-
if (!uid || !password) {
|
|
114
|
-
throw new E_INVALID_CREDENTIALS("Invalid user credentials");
|
|
115
|
-
}
|
|
116
|
-
const user = await this.findForAuth(options.uids, uid);
|
|
117
|
-
if (!user) {
|
|
118
|
-
await hash().make(password);
|
|
119
|
-
throw new E_INVALID_CREDENTIALS("Invalid user credentials");
|
|
120
|
-
}
|
|
121
|
-
const passwordHash = user[options.passwordColumnName];
|
|
122
|
-
if (!passwordHash) {
|
|
123
|
-
throw new RuntimeException(
|
|
124
|
-
`Cannot verify password during login. The value of column "${options.passwordColumnName}" is undefined or null`
|
|
125
|
-
);
|
|
126
|
-
}
|
|
127
|
-
if (await hash().verify(passwordHash, password)) {
|
|
128
|
-
return user;
|
|
129
|
-
}
|
|
130
|
-
throw new E_INVALID_CREDENTIALS("Invalid user credentials");
|
|
131
|
-
}
|
|
132
|
-
}
|
|
133
|
-
__decorateClass([
|
|
134
|
-
beforeSave()
|
|
135
|
-
], UserWithUserFinder, "hashPassword", 1);
|
|
136
|
-
return UserWithUserFinder;
|
|
137
|
-
};
|
|
86
|
+
// index.ts
|
|
87
|
+
function isModuleInstalled(moduleName) {
|
|
88
|
+
try {
|
|
89
|
+
import.meta.resolve(moduleName);
|
|
90
|
+
return true;
|
|
91
|
+
} catch (e) {
|
|
92
|
+
return false;
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
var withAuthFinder;
|
|
96
|
+
if (isModuleInstalled("@adonisjs/lucid")) {
|
|
97
|
+
const { withAuthFinder: withAuthFinderFn } = await import("./src/mixins/lucid.js");
|
|
98
|
+
withAuthFinder = withAuthFinderFn;
|
|
138
99
|
}
|
|
139
100
|
export {
|
|
140
101
|
AuthManager,
|
package/build/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../configure.ts","../src/symbols.ts","../src/define_config.ts","../
|
|
1
|
+
{"version":3,"sources":["../configure.ts","../src/symbols.ts","../src/define_config.ts","../index.ts"],"sourcesContent":["/*\n * @adonisjs/auth\n *\n * (c) AdonisJS\n *\n * For the full copyright and license information, please view the LICENSE\n * file that was distributed with this source code.\n */\n\nimport { presetAuth } from '@adonisjs/presets/auth'\nimport type Configure from '@adonisjs/core/commands/configure'\n\n/**\n * Configures the auth package\n */\nexport async function configure(command: Configure) {\n const codemods = await command.createCodemods()\n let guard: string | undefined = command.parsedFlags.guard\n\n /**\n * Prompts user to select a guard when not mentioned via\n * the CLI\n */\n if (guard === undefined) {\n guard = await command.prompt.choice(\n 'Select the auth guard you want to use',\n [\n {\n name: 'session',\n message: 'Session',\n },\n {\n name: 'access_tokens',\n message: 'Opaque access tokens',\n },\n {\n name: 'basic_auth',\n message: 'Basic Auth',\n },\n ],\n {\n validate(value) {\n return !!value\n },\n }\n )\n }\n\n /**\n * Ensure selected or guard defined via the CLI flag is\n * valid\n */\n if (!['session', 'access_tokens', 'basic_auth'].includes(guard!)) {\n command.logger.error(\n `The selected guard \"${guard}\" is invalid. Select one from: session, access_tokens, basic_auth`\n )\n command.exitCode = 1\n return\n }\n\n await presetAuth(codemods, command.app, {\n guard: guard as 'session' | 'access_tokens' | 'basic_auth',\n userProvider: 'lucid',\n })\n}\n","/*\n * @adonisjs/lucid\n *\n * (c) AdonisJS\n *\n * For the full copyright and license information, please view the LICENSE\n * file that was distributed with this source code.\n */\n\n/**\n * A symbol to identify the type of the real user for a given\n * user provider\n */\nexport const PROVIDER_REAL_USER = Symbol.for('PROVIDER_REAL_USER')\n\n/**\n * A symbol to identify the type for the events emitted by a guard\n */\nexport const GUARD_KNOWN_EVENTS = Symbol.for('GUARD_KNOWN_EVENTS')\n","/*\n * @adonisjs/auth\n *\n * (c) AdonisJS\n *\n * For the full copyright and license information, please view the LICENSE\n * file that was distributed with this source code.\n */\n\nimport { configProvider } from '@adonisjs/core'\nimport type { ConfigProvider } from '@adonisjs/core/types'\nimport type { GuardConfigProvider, GuardFactory } from './types.js'\n\n/**\n * Config resolved by the \"defineConfig\" method\n */\nexport type ResolvedAuthConfig<\n KnownGuards extends Record<string, GuardFactory | GuardConfigProvider<GuardFactory>>,\n> = {\n default: keyof KnownGuards\n guards: {\n [K in keyof KnownGuards]: KnownGuards[K] extends GuardConfigProvider<infer A>\n ? A\n : KnownGuards[K]\n }\n}\n\n/**\n * Define configuration for the auth package. The function returns\n * a config provider that is invoked inside the auth service\n * provider\n */\nexport function defineConfig<\n KnownGuards extends Record<string, GuardFactory | GuardConfigProvider<GuardFactory>>,\n>(config: {\n default: keyof KnownGuards\n guards: KnownGuards\n}): ConfigProvider<ResolvedAuthConfig<KnownGuards>> {\n return configProvider.create(async (app) => {\n const guardsList = Object.keys(config.guards)\n const guards = {} as Record<string, GuardFactory>\n\n for (let guardName of guardsList) {\n const guard = config.guards[guardName]\n if (typeof guard === 'function') {\n guards[guardName] = guard\n } else {\n guards[guardName] = await guard.resolver(guardName, app)\n }\n }\n\n return {\n default: config.default,\n guards: guards,\n } as ResolvedAuthConfig<KnownGuards>\n })\n}\n","/*\n * @adonisjs/auth\n *\n * (c) AdonisJS\n *\n * For the full copyright and license information, please view the LICENSE\n * file that was distributed with this source code.\n */\n\nexport * as errors from './src/errors.js'\nexport { configure } from './configure.js'\nexport * as symbols from './src/symbols.js'\nexport { AuthManager } from './src/auth_manager.js'\nexport { defineConfig } from './src/define_config.js'\nexport { Authenticator } from './src/authenticator.js'\nexport { AuthenticatorClient } from './src/authenticator_client.js'\nimport type { withAuthFinder as withAuthFinderType } from './src/mixins/lucid.js'\n\nfunction isModuleInstalled(moduleName: string) {\n try {\n import.meta.resolve(moduleName)\n return true\n } catch (e) {\n return false\n }\n}\n\n/**\n * @deprecated Import `withAuthFinder` from `@adonisjs/auth/mixins/lucid` instead\n */\nlet withAuthFinder: typeof withAuthFinderType\n\nif (isModuleInstalled('@adonisjs/lucid')) {\n const { withAuthFinder: withAuthFinderFn } = await import('./src/mixins/lucid.js')\n withAuthFinder = withAuthFinderFn\n}\n\nexport { withAuthFinder }\n"],"mappings":";;;;;;;;;;;;;;AASA,SAAS,kBAAkB;AAM3B,eAAsB,UAAU,SAAoB;AAClD,QAAM,WAAW,MAAM,QAAQ,eAAe;AAC9C,MAAI,QAA4B,QAAQ,YAAY;AAMpD,MAAI,UAAU,QAAW;AACvB,YAAQ,MAAM,QAAQ,OAAO;AAAA,MAC3B;AAAA,MACA;AAAA,QACE;AAAA,UACE,MAAM;AAAA,UACN,SAAS;AAAA,QACX;AAAA,QACA;AAAA,UACE,MAAM;AAAA,UACN,SAAS;AAAA,QACX;AAAA,QACA;AAAA,UACE,MAAM;AAAA,UACN,SAAS;AAAA,QACX;AAAA,MACF;AAAA,MACA;AAAA,QACE,SAAS,OAAO;AACd,iBAAO,CAAC,CAAC;AAAA,QACX;AAAA,MACF;AAAA,IACF;AAAA,EACF;AAMA,MAAI,CAAC,CAAC,WAAW,iBAAiB,YAAY,EAAE,SAAS,KAAM,GAAG;AAChE,YAAQ,OAAO;AAAA,MACb,uBAAuB,KAAK;AAAA,IAC9B;AACA,YAAQ,WAAW;AACnB;AAAA,EACF;AAEA,QAAM,WAAW,UAAU,QAAQ,KAAK;AAAA,IACtC;AAAA,IACA,cAAc;AAAA,EAChB,CAAC;AACH;;;AChEA;AAAA;AAAA;AAAA;AAAA;AAaO,IAAM,qBAAqB,OAAO,IAAI,oBAAoB;AAK1D,IAAM,qBAAqB,OAAO,IAAI,oBAAoB;;;ACTjE,SAAS,sBAAsB;AAuBxB,SAAS,aAEd,QAGkD;AAClD,SAAO,eAAe,OAAO,OAAO,QAAQ;AAC1C,UAAM,aAAa,OAAO,KAAK,OAAO,MAAM;AAC5C,UAAM,SAAS,CAAC;AAEhB,aAAS,aAAa,YAAY;AAChC,YAAM,QAAQ,OAAO,OAAO,SAAS;AACrC,UAAI,OAAO,UAAU,YAAY;AAC/B,eAAO,SAAS,IAAI;AAAA,MACtB,OAAO;AACL,eAAO,SAAS,IAAI,MAAM,MAAM,SAAS,WAAW,GAAG;AAAA,MACzD;AAAA,IACF;AAEA,WAAO;AAAA,MACL,SAAS,OAAO;AAAA,MAChB;AAAA,IACF;AAAA,EACF,CAAC;AACH;;;ACtCA,SAAS,kBAAkB,YAAoB;AAC7C,MAAI;AACF,gBAAY,QAAQ,UAAU;AAC9B,WAAO;AAAA,EACT,SAAS,GAAG;AACV,WAAO;AAAA,EACT;AACF;AAKA,IAAI;AAEJ,IAAI,kBAAkB,iBAAiB,GAAG;AACxC,QAAM,EAAE,gBAAgB,iBAAiB,IAAI,MAAM,OAAO,uBAAuB;AACjF,mBAAiB;AACnB;","names":[]}
|
|
@@ -51,6 +51,7 @@ export declare function withAuthFinder(hash: () => Hash, options: {
|
|
|
51
51
|
merge(value: Partial<{}>, allowExtraProperties?: boolean | undefined): any;
|
|
52
52
|
enableForceUpdate(): any;
|
|
53
53
|
save(): Promise<any>;
|
|
54
|
+
lockForUpdate<T>(callback: (user: any) => T | Promise<T>): Promise<T>;
|
|
54
55
|
delete(): Promise<void>;
|
|
55
56
|
refresh(): Promise<any>;
|
|
56
57
|
load: import("@adonisjs/lucid/types/model").LucidRowPreload<any>;
|
|
@@ -77,20 +78,20 @@ export declare function withAuthFinder(hash: () => Hash, options: {
|
|
|
77
78
|
* Hook to verify user password when creating or updating
|
|
78
79
|
* the user model.
|
|
79
80
|
*/
|
|
80
|
-
hashPassword<
|
|
81
|
+
hashPassword<T_1 extends any & Model>(this: T_1, user: InstanceType<T_1>): Promise<void>;
|
|
81
82
|
/**
|
|
82
83
|
* Finds the user for authentication via "verifyCredentials".
|
|
83
84
|
* Feel free to override this method customize the user
|
|
84
85
|
* lookup behavior.
|
|
85
86
|
*/
|
|
86
|
-
findForAuth<
|
|
87
|
+
findForAuth<T_2 extends any & Model>(this: T_2, uids: string[], value: string): Promise<InstanceType<T_2> | null>;
|
|
87
88
|
/**
|
|
88
89
|
* Find a user by uid and verify their password. This method is
|
|
89
90
|
* safe from timing attacks.
|
|
90
91
|
*/
|
|
91
|
-
verifyCredentials<
|
|
92
|
+
verifyCredentials<T_3 extends any & Model>(this: T_3, uid: string, password: string): Promise<InstanceType<T_3>>;
|
|
92
93
|
readonly booted: boolean;
|
|
93
|
-
find: <
|
|
94
|
+
find: <T_4 extends import("@adonisjs/lucid/types/model").LucidModel>(this: T_4, value: any, options?: import("@adonisjs/lucid/types/model").ModelAdapterOptions | undefined) => Promise<InstanceType<T_4> | null>;
|
|
94
95
|
$columnsDefinitions: Map<string, import("@adonisjs/lucid/types/model").ModelColumnOptions>;
|
|
95
96
|
$relationsDefinitions: Map<string, import("@adonisjs/lucid/types/relations").RelationshipsContract>;
|
|
96
97
|
$computedDefinitions: Map<string, import("@adonisjs/lucid/types/model").ComputedOptions>;
|
|
@@ -110,8 +111,8 @@ export declare function withAuthFinder(hash: () => Hash, options: {
|
|
|
110
111
|
serializedToColumns: import("@adonisjs/lucid/types/model").ModelKeysContract;
|
|
111
112
|
serializedToAttributes: import("@adonisjs/lucid/types/model").ModelKeysContract;
|
|
112
113
|
};
|
|
113
|
-
$createFromAdapterResult: <
|
|
114
|
-
$createMultipleFromAdapterResult: <
|
|
114
|
+
$createFromAdapterResult: <T_5 extends import("@adonisjs/lucid/types/model").LucidModel>(this: T_5, result?: import("@adonisjs/lucid/types/model").ModelObject | undefined, sideloadAttributes?: import("@adonisjs/lucid/types/model").ModelObject | undefined, options?: import("@adonisjs/lucid/types/model").ModelAdapterOptions | undefined) => InstanceType<T_5> | null;
|
|
115
|
+
$createMultipleFromAdapterResult: <T_6 extends import("@adonisjs/lucid/types/model").LucidModel>(this: T_6, results: import("@adonisjs/lucid/types/model").ModelObject[], sideloadAttributes?: import("@adonisjs/lucid/types/model").ModelObject | undefined, options?: import("@adonisjs/lucid/types/model").ModelAdapterOptions | undefined) => InstanceType<T_6>[];
|
|
115
116
|
$addColumn: (name: string, options: Partial<import("@adonisjs/lucid/types/model").ColumnOptions>) => import("@adonisjs/lucid/types/model").ColumnOptions;
|
|
116
117
|
$hasColumn: (name: string) => boolean;
|
|
117
118
|
$getColumn: (name: string) => import("@adonisjs/lucid/types/model").ModelColumnOptions | undefined;
|
|
@@ -127,30 +128,40 @@ export declare function withAuthFinder(hash: () => Hash, options: {
|
|
|
127
128
|
$defineProperty: <Model_3 extends import("@adonisjs/lucid/types/model").LucidModel, Prop extends keyof Model_3>(this: Model_3, propertyName: Prop, defaultValue: Model_3[Prop], strategy: "inherit" | "define" | ((value: Model_3[Prop]) => Model_3[Prop])) => void;
|
|
128
129
|
boot: () => void;
|
|
129
130
|
before: {
|
|
130
|
-
<Model_4 extends import("@adonisjs/lucid/types/model").LucidModel,
|
|
131
|
+
<Model_4 extends import("@adonisjs/lucid/types/model").LucidModel, Event extends "find" | "fetch">(this: Model_4, event: Event, handler: import("@adonisjs/lucid/types/model").HooksHandler<import("@adonisjs/lucid/types/model").ModelQueryBuilderContract<Model_4, InstanceType<Model_4>>, Event>): void;
|
|
131
132
|
<Model_5 extends import("@adonisjs/lucid/types/model").LucidModel>(this: Model_5, event: "paginate", handler: import("@adonisjs/lucid/types/model").HooksHandler<[import("@adonisjs/lucid/types/model").ModelQueryBuilderContract<Model_5, InstanceType<Model_5>>, import("@adonisjs/lucid/types/model").ModelQueryBuilderContract<Model_5, InstanceType<Model_5>>], "paginate">): void;
|
|
132
|
-
<Model_6 extends import("@adonisjs/lucid/types/model").LucidModel,
|
|
133
|
+
<Model_6 extends import("@adonisjs/lucid/types/model").LucidModel, Event_1 extends import("@adonisjs/lucid/types/model").EventsList>(this: Model_6, event: Event_1, handler: import("@adonisjs/lucid/types/model").HooksHandler<InstanceType<Model_6>, Event_1>): void;
|
|
133
134
|
};
|
|
134
135
|
after: {
|
|
135
136
|
<Model_7 extends import("@adonisjs/lucid/types/model").LucidModel>(this: Model_7, event: "fetch", handler: import("@adonisjs/lucid/types/model").HooksHandler<InstanceType<Model_7>[], "fetch">): void;
|
|
136
137
|
<Model_8 extends import("@adonisjs/lucid/types/model").LucidModel>(this: Model_8, event: "paginate", handler: import("@adonisjs/lucid/types/model").HooksHandler<import("@adonisjs/lucid/types/model").ModelPaginatorContract<InstanceType<Model_8>>, "paginate">): void;
|
|
137
|
-
<Model_9 extends import("@adonisjs/lucid/types/model").LucidModel,
|
|
138
|
+
<Model_9 extends import("@adonisjs/lucid/types/model").LucidModel, Event_2 extends import("@adonisjs/lucid/types/model").EventsList>(this: Model_9, event: Event_2, handler: import("@adonisjs/lucid/types/model").HooksHandler<InstanceType<Model_9>, Event_2>): void;
|
|
138
139
|
};
|
|
139
|
-
create: <
|
|
140
|
-
createMany: <
|
|
141
|
-
findOrFail: <
|
|
142
|
-
findBy:
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
140
|
+
create: <T_7 extends import("@adonisjs/lucid/types/model").LucidModel>(this: T_7, values: Partial<import("@adonisjs/lucid/types/model").ModelAttributes<InstanceType<T_7>>>, options?: import("@adonisjs/lucid/types/model").ModelAssignOptions | undefined) => Promise<InstanceType<T_7>>;
|
|
141
|
+
createMany: <T_8 extends import("@adonisjs/lucid/types/model").LucidModel>(this: T_8, values: Partial<import("@adonisjs/lucid/types/model").ModelAttributes<InstanceType<T_8>>>[], options?: import("@adonisjs/lucid/types/model").ModelAssignOptions | undefined) => Promise<InstanceType<T_8>[]>;
|
|
142
|
+
findOrFail: <T_9 extends import("@adonisjs/lucid/types/model").LucidModel>(this: T_9, value: any, options?: import("@adonisjs/lucid/types/model").ModelAdapterOptions | undefined) => Promise<InstanceType<T_9>>;
|
|
143
|
+
findBy: {
|
|
144
|
+
<T_10 extends import("@adonisjs/lucid/types/model").LucidModel>(this: T_10, clause: Record<string, unknown>, options?: import("@adonisjs/lucid/types/model").ModelAdapterOptions | undefined): Promise<InstanceType<T_10> | null>;
|
|
145
|
+
<T_11 extends import("@adonisjs/lucid/types/model").LucidModel>(this: T_11, key: string, value: any, options?: import("@adonisjs/lucid/types/model").ModelAdapterOptions | undefined): Promise<InstanceType<T_11> | null>;
|
|
146
|
+
};
|
|
147
|
+
findByOrFail: {
|
|
148
|
+
<T_12 extends import("@adonisjs/lucid/types/model").LucidModel>(this: T_12, clause: Record<string, unknown>, options?: import("@adonisjs/lucid/types/model").ModelAdapterOptions | undefined): Promise<InstanceType<T_12>>;
|
|
149
|
+
<T_13 extends import("@adonisjs/lucid/types/model").LucidModel>(this: T_13, key: string, value: any, options?: import("@adonisjs/lucid/types/model").ModelAdapterOptions | undefined): Promise<InstanceType<T_13>>;
|
|
150
|
+
};
|
|
151
|
+
findManyBy: {
|
|
152
|
+
<T_14 extends import("@adonisjs/lucid/types/model").LucidModel>(this: T_14, clause: Record<string, unknown>, options?: import("@adonisjs/lucid/types/model").ModelAdapterOptions | undefined): Promise<InstanceType<T_14>[]>;
|
|
153
|
+
<T_15 extends import("@adonisjs/lucid/types/model").LucidModel>(this: T_15, key: string, value: any, options?: import("@adonisjs/lucid/types/model").ModelAdapterOptions | undefined): Promise<InstanceType<T_15>[]>;
|
|
154
|
+
};
|
|
155
|
+
first: <T_16 extends import("@adonisjs/lucid/types/model").LucidModel>(this: T_16, options?: import("@adonisjs/lucid/types/model").ModelAdapterOptions | undefined) => Promise<InstanceType<T_16> | null>;
|
|
156
|
+
firstOrFail: <T_17 extends import("@adonisjs/lucid/types/model").LucidModel>(this: T_17, options?: import("@adonisjs/lucid/types/model").ModelAdapterOptions | undefined) => Promise<InstanceType<T_17>>;
|
|
157
|
+
findMany: <T_18 extends import("@adonisjs/lucid/types/model").LucidModel>(this: T_18, value: any[], options?: import("@adonisjs/lucid/types/model").ModelAdapterOptions | undefined) => Promise<InstanceType<T_18>[]>;
|
|
158
|
+
firstOrNew: <T_19 extends import("@adonisjs/lucid/types/model").LucidModel>(this: T_19, searchPayload: Partial<import("@adonisjs/lucid/types/model").ModelAttributes<InstanceType<T_19>>>, savePayload?: Partial<import("@adonisjs/lucid/types/model").ModelAttributes<InstanceType<T_19>>> | undefined, options?: import("@adonisjs/lucid/types/model").ModelAssignOptions | undefined) => Promise<InstanceType<T_19>>;
|
|
159
|
+
firstOrCreate: <T_20 extends import("@adonisjs/lucid/types/model").LucidModel>(this: T_20, searchPayload: Partial<import("@adonisjs/lucid/types/model").ModelAttributes<InstanceType<T_20>>>, savePayload?: Partial<import("@adonisjs/lucid/types/model").ModelAttributes<InstanceType<T_20>>> | undefined, options?: import("@adonisjs/lucid/types/model").ModelAssignOptions | undefined) => Promise<InstanceType<T_20>>;
|
|
160
|
+
updateOrCreate: <T_21 extends import("@adonisjs/lucid/types/model").LucidModel>(this: T_21, searchPayload: Partial<import("@adonisjs/lucid/types/model").ModelAttributes<InstanceType<T_21>>>, updatePayload: Partial<import("@adonisjs/lucid/types/model").ModelAttributes<InstanceType<T_21>>>, options?: import("@adonisjs/lucid/types/model").ModelAssignOptions | undefined) => Promise<InstanceType<T_21>>;
|
|
161
|
+
fetchOrNewUpMany: <T_22 extends import("@adonisjs/lucid/types/model").LucidModel>(this: T_22, predicate: keyof import("@adonisjs/lucid/types/model").ModelAttributes<InstanceType<T_22>> | (keyof import("@adonisjs/lucid/types/model").ModelAttributes<InstanceType<T_22>>)[], payload: Partial<import("@adonisjs/lucid/types/model").ModelAttributes<InstanceType<T_22>>>[], options?: import("@adonisjs/lucid/types/model").ModelAssignOptions | undefined) => Promise<InstanceType<T_22>[]>;
|
|
162
|
+
fetchOrCreateMany: <T_23 extends import("@adonisjs/lucid/types/model").LucidModel>(this: T_23, predicate: keyof import("@adonisjs/lucid/types/model").ModelAttributes<InstanceType<T_23>> | (keyof import("@adonisjs/lucid/types/model").ModelAttributes<InstanceType<T_23>>)[], payload: Partial<import("@adonisjs/lucid/types/model").ModelAttributes<InstanceType<T_23>>>[], options?: import("@adonisjs/lucid/types/model").ModelAssignOptions | undefined) => Promise<InstanceType<T_23>[]>;
|
|
163
|
+
updateOrCreateMany: <T_24 extends import("@adonisjs/lucid/types/model").LucidModel>(this: T_24, predicate: keyof import("@adonisjs/lucid/types/model").ModelAttributes<InstanceType<T_24>> | (keyof import("@adonisjs/lucid/types/model").ModelAttributes<InstanceType<T_24>>)[], payload: Partial<import("@adonisjs/lucid/types/model").ModelAttributes<InstanceType<T_24>>>[], options?: import("@adonisjs/lucid/types/model").ModelAssignOptions | undefined) => Promise<InstanceType<T_24>[]>;
|
|
164
|
+
all: <T_25 extends import("@adonisjs/lucid/types/model").LucidModel>(this: T_25, options?: import("@adonisjs/lucid/types/model").ModelAdapterOptions | undefined) => Promise<InstanceType<T_25>[]>;
|
|
154
165
|
query: <Model_10 extends import("@adonisjs/lucid/types/model").LucidModel, Result = InstanceType<Model_10>>(this: Model_10, options?: import("@adonisjs/lucid/types/model").ModelAdapterOptions | undefined) => import("@adonisjs/lucid/types/model").ModelQueryBuilderContract<Model_10, Result>;
|
|
155
166
|
truncate: (cascade?: boolean | undefined) => Promise<void>;
|
|
156
167
|
} & Model;
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import {
|
|
2
|
+
E_INVALID_CREDENTIALS
|
|
3
|
+
} from "../../chunk-UGHJLKDI.js";
|
|
4
|
+
import {
|
|
5
|
+
__decorateClass
|
|
6
|
+
} from "../../chunk-CZCFTIBB.js";
|
|
7
|
+
|
|
8
|
+
// src/mixins/lucid.ts
|
|
9
|
+
import { RuntimeException } from "@adonisjs/core/exceptions";
|
|
10
|
+
import { beforeSave } from "@adonisjs/lucid/orm";
|
|
11
|
+
function withAuthFinder(hash, options) {
|
|
12
|
+
return (superclass) => {
|
|
13
|
+
class UserWithUserFinder extends superclass {
|
|
14
|
+
static async hashPassword(user) {
|
|
15
|
+
if (user.$dirty[options.passwordColumnName]) {
|
|
16
|
+
;
|
|
17
|
+
user[options.passwordColumnName] = await hash().make(
|
|
18
|
+
user[options.passwordColumnName]
|
|
19
|
+
);
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Finds the user for authentication via "verifyCredentials".
|
|
24
|
+
* Feel free to override this method customize the user
|
|
25
|
+
* lookup behavior.
|
|
26
|
+
*/
|
|
27
|
+
static findForAuth(uids, value) {
|
|
28
|
+
const query = this.query();
|
|
29
|
+
uids.forEach((uid) => query.orWhere(uid, value));
|
|
30
|
+
return query.limit(1).first();
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Find a user by uid and verify their password. This method is
|
|
34
|
+
* safe from timing attacks.
|
|
35
|
+
*/
|
|
36
|
+
static async verifyCredentials(uid, password) {
|
|
37
|
+
if (!uid || !password) {
|
|
38
|
+
throw new E_INVALID_CREDENTIALS("Invalid user credentials");
|
|
39
|
+
}
|
|
40
|
+
const user = await this.findForAuth(options.uids, uid);
|
|
41
|
+
if (!user) {
|
|
42
|
+
await hash().make(password);
|
|
43
|
+
throw new E_INVALID_CREDENTIALS("Invalid user credentials");
|
|
44
|
+
}
|
|
45
|
+
const passwordHash = user[options.passwordColumnName];
|
|
46
|
+
if (!passwordHash) {
|
|
47
|
+
throw new RuntimeException(
|
|
48
|
+
`Cannot verify password during login. The value of column "${options.passwordColumnName}" is undefined or null`
|
|
49
|
+
);
|
|
50
|
+
}
|
|
51
|
+
if (await hash().verify(passwordHash, password)) {
|
|
52
|
+
return user;
|
|
53
|
+
}
|
|
54
|
+
throw new E_INVALID_CREDENTIALS("Invalid user credentials");
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
__decorateClass([
|
|
58
|
+
beforeSave()
|
|
59
|
+
], UserWithUserFinder, "hashPassword", 1);
|
|
60
|
+
return UserWithUserFinder;
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
export {
|
|
64
|
+
withAuthFinder
|
|
65
|
+
};
|
|
66
|
+
//# sourceMappingURL=lucid.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/mixins/lucid.ts"],"sourcesContent":["/*\n * @adonisjs/auth\n *\n * (c) AdonisJS\n *\n * For the full copyright and license information, please view the LICENSE\n * file that was distributed with this source code.\n */\n\nimport type { Hash } from '@adonisjs/core/hash'\nimport { RuntimeException } from '@adonisjs/core/exceptions'\nimport { beforeSave, type BaseModel } from '@adonisjs/lucid/orm'\nimport type { NormalizeConstructor } from '@adonisjs/core/types/helpers'\nimport { E_INVALID_CREDENTIALS } from '../errors.js'\n\n/**\n * Mixing to add user lookup and password verification methods\n * on a model.\n *\n * Under the hood, this mixin defines following methods and hooks\n *\n * - beforeSave hook to hash user password\n * - findForAuth method to find a user during authentication\n * - verifyCredentials method to verify user credentials and prevent\n * timing attacks.\n */\nexport function withAuthFinder(\n hash: () => Hash,\n options: {\n uids: string[]\n passwordColumnName: string\n }\n) {\n return <Model extends NormalizeConstructor<typeof BaseModel>>(superclass: Model) => {\n class UserWithUserFinder extends superclass {\n /**\n * Hook to verify user password when creating or updating\n * the user model.\n */\n @beforeSave()\n static async hashPassword<T extends typeof UserWithUserFinder>(\n this: T,\n user: InstanceType<T>\n ) {\n if (user.$dirty[options.passwordColumnName]) {\n ;(user as any)[options.passwordColumnName] = await hash().make(\n (user as any)[options.passwordColumnName]\n )\n }\n }\n\n /**\n * Finds the user for authentication via \"verifyCredentials\".\n * Feel free to override this method customize the user\n * lookup behavior.\n */\n static findForAuth<T extends typeof UserWithUserFinder>(\n this: T,\n uids: string[],\n value: string\n ): Promise<InstanceType<T> | null> {\n const query = this.query()\n uids.forEach((uid) => query.orWhere(uid, value))\n return query.limit(1).first()\n }\n\n /**\n * Find a user by uid and verify their password. This method is\n * safe from timing attacks.\n */\n static async verifyCredentials<T extends typeof UserWithUserFinder>(\n this: T,\n uid: string,\n password: string\n ) {\n /**\n * Fail when uid or the password are missing\n */\n if (!uid || !password) {\n throw new E_INVALID_CREDENTIALS('Invalid user credentials')\n }\n\n const user = await this.findForAuth(options.uids, uid)\n if (!user) {\n await hash().make(password)\n throw new E_INVALID_CREDENTIALS('Invalid user credentials')\n }\n\n const passwordHash = (user as any)[options.passwordColumnName]\n if (!passwordHash) {\n throw new RuntimeException(\n `Cannot verify password during login. The value of column \"${options.passwordColumnName}\" is undefined or null`\n )\n }\n\n if (await hash().verify(passwordHash, password)) {\n return user\n }\n\n throw new E_INVALID_CREDENTIALS('Invalid user credentials')\n }\n }\n\n return UserWithUserFinder\n }\n}\n"],"mappings":";;;;;;;;AAUA,SAAS,wBAAwB;AACjC,SAAS,kBAAkC;AAepC,SAAS,eACd,MACA,SAIA;AACA,SAAO,CAAuD,eAAsB;AAAA,IAClF,MAAM,2BAA2B,WAAW;AAAA,MAM1C,aAAa,aAEX,MACA;AACA,YAAI,KAAK,OAAO,QAAQ,kBAAkB,GAAG;AAC3C;AAAC,UAAC,KAAa,QAAQ,kBAAkB,IAAI,MAAM,KAAK,EAAE;AAAA,YACvD,KAAa,QAAQ,kBAAkB;AAAA,UAC1C;AAAA,QACF;AAAA,MACF;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,MAOA,OAAO,YAEL,MACA,OACiC;AACjC,cAAM,QAAQ,KAAK,MAAM;AACzB,aAAK,QAAQ,CAAC,QAAQ,MAAM,QAAQ,KAAK,KAAK,CAAC;AAC/C,eAAO,MAAM,MAAM,CAAC,EAAE,MAAM;AAAA,MAC9B;AAAA;AAAA;AAAA;AAAA;AAAA,MAMA,aAAa,kBAEX,KACA,UACA;AAIA,YAAI,CAAC,OAAO,CAAC,UAAU;AACrB,gBAAM,IAAI,sBAAsB,0BAA0B;AAAA,QAC5D;AAEA,cAAM,OAAO,MAAM,KAAK,YAAY,QAAQ,MAAM,GAAG;AACrD,YAAI,CAAC,MAAM;AACT,gBAAM,KAAK,EAAE,KAAK,QAAQ;AAC1B,gBAAM,IAAI,sBAAsB,0BAA0B;AAAA,QAC5D;AAEA,cAAM,eAAgB,KAAa,QAAQ,kBAAkB;AAC7D,YAAI,CAAC,cAAc;AACjB,gBAAM,IAAI;AAAA,YACR,6DAA6D,QAAQ,kBAAkB;AAAA,UACzF;AAAA,QACF;AAEA,YAAI,MAAM,KAAK,EAAE,OAAO,cAAc,QAAQ,GAAG;AAC/C,iBAAO;AAAA,QACT;AAEA,cAAM,IAAI,sBAAsB,0BAA0B;AAAA,MAC5D;AAAA,IACF;AA7De;AAAA,MADZ,WAAW;AAAA,OALR,oBAMS;AA+Df,WAAO;AAAA,EACT;AACF;","names":[]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@adonisjs/auth",
|
|
3
|
-
"version": "9.
|
|
3
|
+
"version": "9.2.0",
|
|
4
4
|
"description": "Official authentication provider for Adonis framework",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "build/index.js",
|
|
@@ -17,6 +17,7 @@
|
|
|
17
17
|
".": "./build/index.js",
|
|
18
18
|
"./types": "./build/src/types.js",
|
|
19
19
|
"./auth_provider": "./build/providers/auth_provider.js",
|
|
20
|
+
"./mixins/lucid": "./build/src/mixins/lucid.js",
|
|
20
21
|
"./plugins/api_client": "./build/src/plugins/japa/api_client.js",
|
|
21
22
|
"./plugins/browser_client": "./build/src/plugins/japa/browser_client.js",
|
|
22
23
|
"./services/main": "./build/services/auth.js",
|
|
@@ -66,28 +67,28 @@
|
|
|
66
67
|
"url": "https://github.com/adonisjs/auth/issues"
|
|
67
68
|
},
|
|
68
69
|
"devDependencies": {
|
|
69
|
-
"@adonisjs/assembler": "^7.
|
|
70
|
-
"@adonisjs/core": "^6.
|
|
71
|
-
"@adonisjs/eslint-config": "^1.
|
|
72
|
-
"@adonisjs/i18n": "^2.0.
|
|
73
|
-
"@adonisjs/lucid": "^20.1
|
|
74
|
-
"@adonisjs/prettier-config": "^1.
|
|
75
|
-
"@adonisjs/session": "^7.
|
|
76
|
-
"@adonisjs/tsconfig": "^1.
|
|
77
|
-
"@commitlint/cli": "^
|
|
78
|
-
"@commitlint/config-conventional": "^
|
|
79
|
-
"@japa/api-client": "^2.0.
|
|
80
|
-
"@japa/assert": "^
|
|
81
|
-
"@japa/browser-client": "^2.0.
|
|
82
|
-
"@japa/expect-type": "^2.0.
|
|
83
|
-
"@japa/file-system": "^2.
|
|
84
|
-
"@japa/plugin-adonisjs": "^3.0.
|
|
85
|
-
"@japa/runner": "^3.1.
|
|
86
|
-
"@japa/snapshot": "^2.0.
|
|
87
|
-
"@swc/core": "^1.
|
|
88
|
-
"@types/basic-auth": "^1.1.
|
|
70
|
+
"@adonisjs/assembler": "^7.4.0",
|
|
71
|
+
"@adonisjs/core": "^6.5.0",
|
|
72
|
+
"@adonisjs/eslint-config": "^1.3.0",
|
|
73
|
+
"@adonisjs/i18n": "^2.0.1",
|
|
74
|
+
"@adonisjs/lucid": "^20.5.1",
|
|
75
|
+
"@adonisjs/prettier-config": "^1.3.0",
|
|
76
|
+
"@adonisjs/session": "^7.3.0",
|
|
77
|
+
"@adonisjs/tsconfig": "^1.3.0",
|
|
78
|
+
"@commitlint/cli": "^19.2.1",
|
|
79
|
+
"@commitlint/config-conventional": "^19.1.0",
|
|
80
|
+
"@japa/api-client": "^2.0.3",
|
|
81
|
+
"@japa/assert": "^3.0.0",
|
|
82
|
+
"@japa/browser-client": "^2.0.3",
|
|
83
|
+
"@japa/expect-type": "^2.0.2",
|
|
84
|
+
"@japa/file-system": "^2.3.0",
|
|
85
|
+
"@japa/plugin-adonisjs": "^3.0.1",
|
|
86
|
+
"@japa/runner": "^3.1.2",
|
|
87
|
+
"@japa/snapshot": "^2.0.5",
|
|
88
|
+
"@swc/core": "^1.4.11",
|
|
89
|
+
"@types/basic-auth": "^1.1.8",
|
|
89
90
|
"@types/luxon": "^3.4.2",
|
|
90
|
-
"@types/node": "^20.
|
|
91
|
+
"@types/node": "^20.12.2",
|
|
91
92
|
"@types/set-cookie-parser": "^2.4.7",
|
|
92
93
|
"@types/sinon": "^17.0.3",
|
|
93
94
|
"c8": "^9.0.0",
|
|
@@ -95,25 +96,25 @@
|
|
|
95
96
|
"copyfiles": "^2.4.1",
|
|
96
97
|
"cross-env": "^7.0.3",
|
|
97
98
|
"del-cli": "^5.1.0",
|
|
98
|
-
"dotenv": "^16.4.
|
|
99
|
-
"eslint": "^8.
|
|
99
|
+
"dotenv": "^16.4.5",
|
|
100
|
+
"eslint": "^8.57.0",
|
|
100
101
|
"github-label-sync": "^2.3.1",
|
|
101
|
-
"husky": "^9.0.
|
|
102
|
+
"husky": "^9.0.11",
|
|
102
103
|
"luxon": "^3.4.4",
|
|
103
|
-
"mysql2": "^3.9.
|
|
104
|
-
"nock": "^13.5.
|
|
105
|
-
"np": "^
|
|
106
|
-
"pg": "^8.11.
|
|
107
|
-
"playwright": "^1.
|
|
108
|
-
"prettier": "^3.
|
|
104
|
+
"mysql2": "^3.9.3",
|
|
105
|
+
"nock": "^13.5.4",
|
|
106
|
+
"np": "^10.0.2",
|
|
107
|
+
"pg": "^8.11.4",
|
|
108
|
+
"playwright": "^1.42.1",
|
|
109
|
+
"prettier": "^3.2.5",
|
|
109
110
|
"set-cookie-parser": "^2.6.0",
|
|
110
111
|
"sinon": "^17.0.1",
|
|
111
112
|
"sqlite3": "^5.1.7",
|
|
112
|
-
"tedious": "^
|
|
113
|
+
"tedious": "^18.1.0",
|
|
113
114
|
"timekeeper": "^2.3.1",
|
|
114
115
|
"ts-node": "^10.9.2",
|
|
115
|
-
"tsup": "^8.0.
|
|
116
|
-
"typescript": "^5.
|
|
116
|
+
"tsup": "^8.0.2",
|
|
117
|
+
"typescript": "^5.4.3"
|
|
117
118
|
},
|
|
118
119
|
"prettier": "@adonisjs/prettier-config",
|
|
119
120
|
"eslintConfig": {
|
|
@@ -146,16 +147,16 @@
|
|
|
146
147
|
]
|
|
147
148
|
},
|
|
148
149
|
"dependencies": {
|
|
149
|
-
"@adonisjs/presets": "^2.
|
|
150
|
+
"@adonisjs/presets": "^2.4.0",
|
|
150
151
|
"basic-auth": "^2.0.1"
|
|
151
152
|
},
|
|
152
153
|
"peerDependencies": {
|
|
153
|
-
"@adonisjs/core": "^6.
|
|
154
|
-
"@adonisjs/lucid": "^20.1
|
|
155
|
-
"@adonisjs/session": "^7.
|
|
156
|
-
"@japa/api-client": "^2.0.
|
|
157
|
-
"@japa/browser-client": "^2.0.
|
|
158
|
-
"@japa/plugin-adonisjs": "^3.0.
|
|
154
|
+
"@adonisjs/core": "^6.5.0",
|
|
155
|
+
"@adonisjs/lucid": "^20.5.1",
|
|
156
|
+
"@adonisjs/session": "^7.3.0",
|
|
157
|
+
"@japa/api-client": "^2.0.3",
|
|
158
|
+
"@japa/browser-client": "^2.0.3",
|
|
159
|
+
"@japa/plugin-adonisjs": "^3.0.1"
|
|
159
160
|
},
|
|
160
161
|
"peerDependenciesMeta": {
|
|
161
162
|
"@adonisjs/lucid": {
|
|
@@ -182,6 +183,7 @@
|
|
|
182
183
|
"./src/plugins/japa/api_client.ts",
|
|
183
184
|
"./src/plugins/japa/browser_client.ts",
|
|
184
185
|
"./services/auth.ts",
|
|
186
|
+
"./src/mixins/lucid.ts",
|
|
185
187
|
"./src/middleware/initialize_auth_middleware.ts",
|
|
186
188
|
"./modules/access_tokens_guard/main.ts",
|
|
187
189
|
"./modules/access_tokens_guard/types.ts",
|