@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.
- package/build/chunk-3HZHOWKL.js +8 -0
- package/build/chunk-3HZHOWKL.js.map +1 -0
- package/build/chunk-CZCFTIBB.js +21 -0
- package/build/chunk-CZCFTIBB.js.map +1 -0
- package/build/chunk-OL2Z3AO5.js +246 -0
- package/build/chunk-OL2Z3AO5.js.map +1 -0
- package/build/chunk-UGHJLKDI.js +197 -0
- package/build/chunk-UGHJLKDI.js.map +1 -0
- package/build/index.d.ts +7 -6
- package/build/index.js +149 -15
- package/build/index.js.map +1 -0
- package/build/modules/access_tokens_guard/access_token.d.ts +137 -0
- package/build/modules/access_tokens_guard/crc32.d.ts +16 -0
- package/build/modules/access_tokens_guard/define_config.d.ts +17 -0
- package/build/modules/access_tokens_guard/guard.d.ts +81 -0
- package/build/modules/access_tokens_guard/main.d.ts +5 -0
- package/build/modules/access_tokens_guard/main.js +929 -0
- package/build/modules/access_tokens_guard/main.js.map +1 -0
- package/build/modules/access_tokens_guard/token_providers/db.d.ts +76 -0
- package/build/modules/access_tokens_guard/types.d.ts +208 -0
- package/build/modules/access_tokens_guard/types.js +1 -0
- package/build/modules/access_tokens_guard/types.js.map +1 -0
- package/build/modules/access_tokens_guard/user_providers/lucid.d.ts +53 -0
- package/build/modules/session_guard/define_config.d.ts +17 -0
- package/build/modules/session_guard/guard.d.ts +98 -0
- package/build/modules/session_guard/main.d.ts +5 -0
- package/build/modules/session_guard/main.js +741 -0
- package/build/modules/session_guard/main.js.map +1 -0
- package/build/modules/session_guard/remember_me_token.d.ts +88 -0
- package/build/modules/session_guard/token_providers/db.d.ts +69 -0
- package/build/modules/session_guard/types.d.ts +243 -0
- package/build/modules/session_guard/types.js +1 -0
- package/build/modules/session_guard/types.js.map +1 -0
- package/build/modules/session_guard/user_providers/lucid.d.ts +57 -0
- package/build/providers/auth_provider.d.ts +1 -1
- package/build/providers/auth_provider.js +31 -27
- package/build/providers/auth_provider.js.map +1 -0
- package/build/services/auth.d.ts +1 -1
- package/build/services/auth.js +10 -15
- package/build/services/auth.js.map +1 -0
- package/build/src/{auth/auth_manager.d.ts → auth_manager.d.ts} +8 -3
- package/build/src/authenticator.d.ts +81 -0
- package/build/src/{auth/authenticator_client.d.ts → authenticator_client.d.ts} +4 -4
- package/build/src/{auth/define_config.d.ts → define_config.d.ts} +0 -10
- package/build/src/errors.d.ts +105 -0
- package/build/src/{auth/middleware → middleware}/initialize_auth_middleware.d.ts +3 -2
- package/build/src/middleware/initialize_auth_middleware.js +17 -0
- package/build/src/middleware/initialize_auth_middleware.js.map +1 -0
- package/build/src/mixins/with_auth_finder.d.ts +156 -0
- package/build/src/{auth/plugins → plugins}/japa/api_client.d.ts +8 -8
- package/build/src/plugins/japa/api_client.js +59 -0
- package/build/src/plugins/japa/api_client.js.map +1 -0
- package/build/src/{auth/plugins → plugins}/japa/browser_client.d.ts +10 -7
- package/build/src/plugins/japa/browser_client.js +67 -0
- package/build/src/plugins/japa/browser_client.js.map +1 -0
- package/build/src/{auth/types.d.ts → types.d.ts} +31 -26
- package/build/src/types.js +1 -0
- package/build/src/types.js.map +1 -0
- package/package.json +88 -68
- package/build/configure.js +0 -47
- package/build/factories/basic_auth_guard_factory.d.ts +0 -12
- package/build/factories/basic_auth_guard_factory.js +0 -22
- package/build/factories/database_token_factory.d.ts +0 -36
- package/build/factories/database_token_factory.js +0 -54
- package/build/factories/database_user_provider.d.ts +0 -14
- package/build/factories/database_user_provider.js +0 -27
- package/build/factories/lucid_user_provider.d.ts +0 -28
- package/build/factories/lucid_user_provider.js +0 -68
- package/build/factories/main.d.ts +0 -4
- package/build/factories/main.js +0 -12
- package/build/factories/session_guard_factory.d.ts +0 -13
- package/build/factories/session_guard_factory.js +0 -24
- package/build/src/auth/auth_manager.js +0 -41
- package/build/src/auth/authenticator.d.ts +0 -63
- package/build/src/auth/authenticator.js +0 -129
- package/build/src/auth/authenticator_client.js +0 -59
- package/build/src/auth/debug.js +0 -10
- package/build/src/auth/define_config.js +0 -54
- package/build/src/auth/errors.d.ts +0 -90
- package/build/src/auth/errors.js +0 -201
- package/build/src/auth/middleware/initialize_auth_middleware.js +0 -25
- package/build/src/auth/plugins/japa/api_client.js +0 -63
- package/build/src/auth/plugins/japa/browser_client.js +0 -64
- package/build/src/auth/symbols.js +0 -17
- package/build/src/auth/types.js +0 -9
- package/build/src/auth/user_providers/main.d.ts +0 -15
- package/build/src/auth/user_providers/main.js +0 -22
- package/build/src/core/guard_user.d.ts +0 -26
- package/build/src/core/guard_user.js +0 -29
- package/build/src/core/token.d.ts +0 -89
- package/build/src/core/token.js +0 -114
- package/build/src/core/token_providers/database.d.ts +0 -77
- package/build/src/core/token_providers/database.js +0 -113
- package/build/src/core/types.d.ts +0 -178
- package/build/src/core/types.js +0 -9
- package/build/src/core/user_providers/database.d.ts +0 -78
- package/build/src/core/user_providers/database.js +0 -117
- package/build/src/core/user_providers/lucid.d.ts +0 -61
- package/build/src/core/user_providers/lucid.js +0 -122
- package/build/src/guards/basic_auth/define_config.d.ts +0 -16
- package/build/src/guards/basic_auth/define_config.js +0 -38
- package/build/src/guards/basic_auth/guard.d.ts +0 -70
- package/build/src/guards/basic_auth/guard.js +0 -190
- package/build/src/guards/basic_auth/main.d.ts +0 -2
- package/build/src/guards/basic_auth/main.js +0 -10
- package/build/src/guards/basic_auth/types.d.ts +0 -35
- package/build/src/guards/basic_auth/types.js +0 -9
- package/build/src/guards/session/define_config.d.ts +0 -23
- package/build/src/guards/session/define_config.js +0 -56
- package/build/src/guards/session/guard.d.ts +0 -123
- package/build/src/guards/session/guard.js +0 -510
- package/build/src/guards/session/main.d.ts +0 -3
- package/build/src/guards/session/main.js +0 -11
- package/build/src/guards/session/token.d.ts +0 -57
- package/build/src/guards/session/token.js +0 -58
- package/build/src/guards/session/token_providers/main.d.ts +0 -33
- package/build/src/guards/session/token_providers/main.js +0 -42
- package/build/src/guards/session/types.d.ts +0 -104
- package/build/src/guards/session/types.js +0 -9
- package/build/stubs/main.d.ts +0 -1
- package/build/stubs/main.js +0 -10
- package/build/stubs/middleware/auth_middleware.stub +0 -30
- package/build/stubs/middleware/guest_middleware.stub +0 -36
- /package/build/src/{auth/debug.d.ts → debug.d.ts} +0 -0
- /package/build/src/{auth/symbols.d.ts → symbols.d.ts} +0 -0
|
@@ -1,77 +0,0 @@
|
|
|
1
|
-
import type { Database } from '@adonisjs/lucid/database';
|
|
2
|
-
import type { DatabaseTokenProviderOptions, TokenProviderContract } from '../types.js';
|
|
3
|
-
/**
|
|
4
|
-
* The representation of a token inside the database
|
|
5
|
-
*/
|
|
6
|
-
type DatabaseTokenRow = {
|
|
7
|
-
series: string;
|
|
8
|
-
user_id: string | number;
|
|
9
|
-
type: string;
|
|
10
|
-
token: string;
|
|
11
|
-
created_at: Date;
|
|
12
|
-
updated_at: Date;
|
|
13
|
-
expires_at: Date | null;
|
|
14
|
-
} & Record<string, any>;
|
|
15
|
-
/**
|
|
16
|
-
* A generic implementation to read tokens from the database
|
|
17
|
-
*/
|
|
18
|
-
export declare abstract class DatabaseTokenProvider<Token> implements TokenProviderContract<Token> {
|
|
19
|
-
/**
|
|
20
|
-
* Reference to the database query builder needed to
|
|
21
|
-
* query the database for tokens
|
|
22
|
-
*/
|
|
23
|
-
protected db: Database;
|
|
24
|
-
/**
|
|
25
|
-
* Options accepted
|
|
26
|
-
*/
|
|
27
|
-
protected options: DatabaseTokenProviderOptions;
|
|
28
|
-
constructor(
|
|
29
|
-
/**
|
|
30
|
-
* Reference to the database query builder needed to
|
|
31
|
-
* query the database for tokens
|
|
32
|
-
*/
|
|
33
|
-
db: Database,
|
|
34
|
-
/**
|
|
35
|
-
* Options accepted
|
|
36
|
-
*/
|
|
37
|
-
options: DatabaseTokenProviderOptions);
|
|
38
|
-
/**
|
|
39
|
-
* Should parse token to a database token row
|
|
40
|
-
*/
|
|
41
|
-
protected abstract parseToken(token: Token): DatabaseTokenRow;
|
|
42
|
-
/**
|
|
43
|
-
* Abstract method to prepare a token from the database
|
|
44
|
-
* row
|
|
45
|
-
*/
|
|
46
|
-
protected abstract prepareToken(dbRow: DatabaseTokenRow): Token;
|
|
47
|
-
/**
|
|
48
|
-
* Returns an instance of the query builder
|
|
49
|
-
*/
|
|
50
|
-
protected getQueryBuilder(): import("@adonisjs/lucid/types/querybuilder").DatabaseQueryBuilderContract<DatabaseTokenRow>;
|
|
51
|
-
/**
|
|
52
|
-
* Returns an instance of the query builder for insert
|
|
53
|
-
* queries
|
|
54
|
-
*/
|
|
55
|
-
protected getInsertQueryBuilder(): import("@adonisjs/lucid/types/querybuilder").InsertQueryBuilderContract<any[]>;
|
|
56
|
-
/**
|
|
57
|
-
* Persists token inside the database
|
|
58
|
-
*/
|
|
59
|
-
createToken(token: Token): Promise<void>;
|
|
60
|
-
/**
|
|
61
|
-
* Finds a token by series inside the database and returns an
|
|
62
|
-
* instance of it.
|
|
63
|
-
*
|
|
64
|
-
* Returns null if the token is missing or expired
|
|
65
|
-
*/
|
|
66
|
-
getTokenBySeries(series: string): Promise<Token | null>;
|
|
67
|
-
/**
|
|
68
|
-
* Removes a token from the database by the
|
|
69
|
-
* series number
|
|
70
|
-
*/
|
|
71
|
-
deleteTokenBySeries(series: string): Promise<void>;
|
|
72
|
-
/**
|
|
73
|
-
* Updates token hash and expiry
|
|
74
|
-
*/
|
|
75
|
-
updateTokenBySeries(series: string, hash: string, expiresAt: Date): Promise<void>;
|
|
76
|
-
}
|
|
77
|
-
export {};
|
|
@@ -1,113 +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 '../../auth/debug.js';
|
|
10
|
-
/**
|
|
11
|
-
* A generic implementation to read tokens from the database
|
|
12
|
-
*/
|
|
13
|
-
export class DatabaseTokenProvider {
|
|
14
|
-
db;
|
|
15
|
-
options;
|
|
16
|
-
constructor(
|
|
17
|
-
/**
|
|
18
|
-
* Reference to the database query builder needed to
|
|
19
|
-
* query the database for tokens
|
|
20
|
-
*/
|
|
21
|
-
db,
|
|
22
|
-
/**
|
|
23
|
-
* Options accepted
|
|
24
|
-
*/
|
|
25
|
-
options) {
|
|
26
|
-
this.db = db;
|
|
27
|
-
this.options = options;
|
|
28
|
-
debug('db_token_provider: options %O', options);
|
|
29
|
-
}
|
|
30
|
-
/**
|
|
31
|
-
* Returns an instance of the query builder
|
|
32
|
-
*/
|
|
33
|
-
getQueryBuilder() {
|
|
34
|
-
return this.db.connection(this.options.connection).query();
|
|
35
|
-
}
|
|
36
|
-
/**
|
|
37
|
-
* Returns an instance of the query builder for insert
|
|
38
|
-
* queries
|
|
39
|
-
*/
|
|
40
|
-
getInsertQueryBuilder() {
|
|
41
|
-
return this.db.connection(this.options.connection).insertQuery();
|
|
42
|
-
}
|
|
43
|
-
/**
|
|
44
|
-
* Persists token inside the database
|
|
45
|
-
*/
|
|
46
|
-
async createToken(token) {
|
|
47
|
-
const parsedToken = this.parseToken(token);
|
|
48
|
-
debug('db_token_provider: creating token %O', parsedToken);
|
|
49
|
-
await this.getInsertQueryBuilder()
|
|
50
|
-
.table(this.options.table)
|
|
51
|
-
.insert({
|
|
52
|
-
...parsedToken,
|
|
53
|
-
});
|
|
54
|
-
}
|
|
55
|
-
/**
|
|
56
|
-
* Finds a token by series inside the database and returns an
|
|
57
|
-
* instance of it.
|
|
58
|
-
*
|
|
59
|
-
* Returns null if the token is missing or expired
|
|
60
|
-
*/
|
|
61
|
-
async getTokenBySeries(series) {
|
|
62
|
-
debug('db_token_provider: reading token by series %s', series);
|
|
63
|
-
const token = await this.getQueryBuilder()
|
|
64
|
-
.from(this.options.table)
|
|
65
|
-
.where('series', series)
|
|
66
|
-
.limit(1)
|
|
67
|
-
.first();
|
|
68
|
-
if (!token) {
|
|
69
|
-
debug('db_token_provider:: token %O', token);
|
|
70
|
-
return null;
|
|
71
|
-
}
|
|
72
|
-
if (typeof token.expires_at === 'number') {
|
|
73
|
-
token.expires_at = new Date(token.expires_at);
|
|
74
|
-
}
|
|
75
|
-
if (typeof token.created_at === 'number') {
|
|
76
|
-
token.created_at = new Date(token.created_at);
|
|
77
|
-
}
|
|
78
|
-
if (typeof token.updated_at === 'number') {
|
|
79
|
-
token.updated_at = new Date(token.updated_at);
|
|
80
|
-
}
|
|
81
|
-
debug('db_token_provider:: token %O', token);
|
|
82
|
-
/**
|
|
83
|
-
* Return null when token has been expired
|
|
84
|
-
*/
|
|
85
|
-
if (token.expires_at && token.expires_at instanceof Date && token.expires_at < new Date()) {
|
|
86
|
-
return null;
|
|
87
|
-
}
|
|
88
|
-
return this.prepareToken(token);
|
|
89
|
-
}
|
|
90
|
-
/**
|
|
91
|
-
* Removes a token from the database by the
|
|
92
|
-
* series number
|
|
93
|
-
*/
|
|
94
|
-
async deleteTokenBySeries(series) {
|
|
95
|
-
debug('db_token_provider: deleting token by series %s', series);
|
|
96
|
-
await this.getQueryBuilder().from(this.options.table).where('series', series).del();
|
|
97
|
-
}
|
|
98
|
-
/**
|
|
99
|
-
* Updates token hash and expiry
|
|
100
|
-
*/
|
|
101
|
-
async updateTokenBySeries(series, hash, expiresAt) {
|
|
102
|
-
const updatePayload = {
|
|
103
|
-
token: hash,
|
|
104
|
-
updated_at: new Date(),
|
|
105
|
-
expires_at: expiresAt,
|
|
106
|
-
};
|
|
107
|
-
debug('db_token_provider: updating token by series %s: %O', series, updatePayload);
|
|
108
|
-
await this.getQueryBuilder()
|
|
109
|
-
.from(this.options.table)
|
|
110
|
-
.where('series', series)
|
|
111
|
-
.update(updatePayload);
|
|
112
|
-
}
|
|
113
|
-
}
|
|
@@ -1,178 +0,0 @@
|
|
|
1
|
-
import type { QueryClientContract } from '@adonisjs/lucid/types/database';
|
|
2
|
-
import type { GuardUser } from './guard_user.js';
|
|
3
|
-
import type { PROVIDER_REAL_USER } from '../auth/symbols.js';
|
|
4
|
-
import type { LucidModel, LucidRow } from '@adonisjs/lucid/types/model';
|
|
5
|
-
/**
|
|
6
|
-
* A token represents an opaque token issued to a client
|
|
7
|
-
* to perform a specific task.
|
|
8
|
-
*
|
|
9
|
-
* The raw value of a token is only visible at the time of
|
|
10
|
-
* issuing it and one must persist hash to the database.
|
|
11
|
-
*/
|
|
12
|
-
export interface TokenContract {
|
|
13
|
-
/**
|
|
14
|
-
* Token type to uniquely identify a bucket of tokens
|
|
15
|
-
*/
|
|
16
|
-
readonly type: string;
|
|
17
|
-
/**
|
|
18
|
-
* The plain text value. Only exists when the token is first
|
|
19
|
-
* created
|
|
20
|
-
*/
|
|
21
|
-
value?: string;
|
|
22
|
-
/**
|
|
23
|
-
* Additional metadata associated with the token.
|
|
24
|
-
*/
|
|
25
|
-
metaData?: Record<string, any>;
|
|
26
|
-
/**
|
|
27
|
-
* The token hash for persisting the token in a database
|
|
28
|
-
*/
|
|
29
|
-
hash: string;
|
|
30
|
-
/**
|
|
31
|
-
* A unique readable series counter to find the token inside the
|
|
32
|
-
* database.
|
|
33
|
-
*/
|
|
34
|
-
series: string;
|
|
35
|
-
/**
|
|
36
|
-
* Timestamp when the token was first persisted
|
|
37
|
-
*/
|
|
38
|
-
createdAt: Date;
|
|
39
|
-
/**
|
|
40
|
-
* Timestamp when the token was updated
|
|
41
|
-
*/
|
|
42
|
-
updatedAt: Date;
|
|
43
|
-
/**
|
|
44
|
-
* Timestamp when the token will expire
|
|
45
|
-
*/
|
|
46
|
-
expiresAt?: Date;
|
|
47
|
-
/**
|
|
48
|
-
* Verifies the raw text value against the hash
|
|
49
|
-
*/
|
|
50
|
-
verify(value: string): boolean;
|
|
51
|
-
}
|
|
52
|
-
/**
|
|
53
|
-
* The UserProvider is used to lookup a user for authentication
|
|
54
|
-
*/
|
|
55
|
-
export interface UserProviderContract<RealUser> {
|
|
56
|
-
[PROVIDER_REAL_USER]: RealUser;
|
|
57
|
-
/**
|
|
58
|
-
* Creates a user object that guards can use for
|
|
59
|
-
* authentication.
|
|
60
|
-
*/
|
|
61
|
-
createUserForGuard(user: RealUser): Promise<GuardUser<RealUser>>;
|
|
62
|
-
/**
|
|
63
|
-
* Find a user by uid. The uid could be one or multiple fields
|
|
64
|
-
* to unique identify a user.
|
|
65
|
-
*
|
|
66
|
-
* This method is called when finding a user for login
|
|
67
|
-
*/
|
|
68
|
-
findByUid(value: string | number): Promise<GuardUser<RealUser> | null>;
|
|
69
|
-
/**
|
|
70
|
-
* Find a user by unique primary id. This method is called when
|
|
71
|
-
* authenticating user from their session.
|
|
72
|
-
*/
|
|
73
|
-
findById(value: string | number): Promise<GuardUser<RealUser> | null>;
|
|
74
|
-
}
|
|
75
|
-
/**
|
|
76
|
-
* The TokenProvider is used to lookup/persist tokens during authentication
|
|
77
|
-
*/
|
|
78
|
-
export interface TokenProviderContract<Token> {
|
|
79
|
-
/**
|
|
80
|
-
* Returns a token by the series counter, or null when token is
|
|
81
|
-
* missing
|
|
82
|
-
*/
|
|
83
|
-
getTokenBySeries(series: string): Promise<Token | null>;
|
|
84
|
-
/**
|
|
85
|
-
* Deletes a token by the series counter
|
|
86
|
-
*/
|
|
87
|
-
deleteTokenBySeries(series: string): Promise<void>;
|
|
88
|
-
/**
|
|
89
|
-
* Updates a token by the series counter
|
|
90
|
-
*/
|
|
91
|
-
updateTokenBySeries(series: string, hash: string, expiresAt: Date): Promise<void>;
|
|
92
|
-
/**
|
|
93
|
-
* Creates a new token and persists it to the database
|
|
94
|
-
*/
|
|
95
|
-
createToken(token: Token): Promise<void>;
|
|
96
|
-
}
|
|
97
|
-
/**
|
|
98
|
-
* A lucid model that can be used during authentication
|
|
99
|
-
*/
|
|
100
|
-
export type LucidAuthenticatable = LucidModel & {
|
|
101
|
-
new (): LucidRow & {
|
|
102
|
-
/**
|
|
103
|
-
* Verify the plain text password against the user password
|
|
104
|
-
* hash
|
|
105
|
-
*/
|
|
106
|
-
verifyPasswordForAuth(plainTextPassword: string): Promise<boolean>;
|
|
107
|
-
};
|
|
108
|
-
};
|
|
109
|
-
/**
|
|
110
|
-
* Options accepted by the Lucid user provider
|
|
111
|
-
*/
|
|
112
|
-
export type LucidUserProviderOptions<Model extends LucidAuthenticatable> = {
|
|
113
|
-
/**
|
|
114
|
-
* Optionally define the connection to use when making database
|
|
115
|
-
* queries
|
|
116
|
-
*/
|
|
117
|
-
connection?: string;
|
|
118
|
-
/**
|
|
119
|
-
* Optionally define the query client instance to use for making
|
|
120
|
-
* database queries.
|
|
121
|
-
*
|
|
122
|
-
* When both "connection" and "client" are defined, the client will
|
|
123
|
-
* be given the preference.
|
|
124
|
-
*/
|
|
125
|
-
client?: QueryClientContract;
|
|
126
|
-
/**
|
|
127
|
-
* Model to use for authentication
|
|
128
|
-
*/
|
|
129
|
-
model: () => Promise<{
|
|
130
|
-
default: Model;
|
|
131
|
-
}>;
|
|
132
|
-
/**
|
|
133
|
-
* An array of uids to use when finding a user for login. Make
|
|
134
|
-
* sure all fields can be used to uniquely lookup a user.
|
|
135
|
-
*/
|
|
136
|
-
uids: Extract<keyof InstanceType<Model>, string>[];
|
|
137
|
-
};
|
|
138
|
-
/**
|
|
139
|
-
* Options accepted by the Database user provider
|
|
140
|
-
*/
|
|
141
|
-
export type DatabaseUserProviderOptions<RealUser extends Record<string, any>> = {
|
|
142
|
-
/**
|
|
143
|
-
* Optionally define the connection to use when making database
|
|
144
|
-
* queries
|
|
145
|
-
*/
|
|
146
|
-
connection?: string;
|
|
147
|
-
/**
|
|
148
|
-
* Database table to query to find the user
|
|
149
|
-
*/
|
|
150
|
-
table: string;
|
|
151
|
-
/**
|
|
152
|
-
* Column name to read the hashed password
|
|
153
|
-
*/
|
|
154
|
-
passwordColumnName: string;
|
|
155
|
-
/**
|
|
156
|
-
* An array of uids to use when finding a user for login. Make
|
|
157
|
-
* sure all fields can be used to uniquely lookup a user.
|
|
158
|
-
*/
|
|
159
|
-
uids: Extract<keyof RealUser, string>[];
|
|
160
|
-
/**
|
|
161
|
-
* The name of the id column to unique identify the user.
|
|
162
|
-
*/
|
|
163
|
-
id: string;
|
|
164
|
-
};
|
|
165
|
-
/**
|
|
166
|
-
* Options accepted by the Database token provider
|
|
167
|
-
*/
|
|
168
|
-
export type DatabaseTokenProviderOptions = {
|
|
169
|
-
/**
|
|
170
|
-
* Optionally define the connection to use when making database
|
|
171
|
-
* queries
|
|
172
|
-
*/
|
|
173
|
-
connection?: string;
|
|
174
|
-
/**
|
|
175
|
-
* Database table to query to find the user
|
|
176
|
-
*/
|
|
177
|
-
table: string;
|
|
178
|
-
};
|
package/build/src/core/types.js
DELETED
|
@@ -1,78 +0,0 @@
|
|
|
1
|
-
import type { Hash } from '@adonisjs/core/hash';
|
|
2
|
-
import type { Database } from '@adonisjs/lucid/database';
|
|
3
|
-
import { GuardUser } from '../guard_user.js';
|
|
4
|
-
import { PROVIDER_REAL_USER } from '../../auth/symbols.js';
|
|
5
|
-
import type { DatabaseUserProviderOptions, UserProviderContract } from '../types.js';
|
|
6
|
-
/**
|
|
7
|
-
* Database user represents a guard user used by authentication guards
|
|
8
|
-
* to perform authentication.
|
|
9
|
-
*/
|
|
10
|
-
declare class DatabaseUser<RealUser extends Record<string, any>> extends GuardUser<RealUser> {
|
|
11
|
-
#private;
|
|
12
|
-
constructor(realUser: RealUser, hasher: Hash, options: {
|
|
13
|
-
id: string;
|
|
14
|
-
passwordColumnName: string;
|
|
15
|
-
});
|
|
16
|
-
/**
|
|
17
|
-
* @inheritdoc
|
|
18
|
-
*/
|
|
19
|
-
getId(): string | number;
|
|
20
|
-
/**
|
|
21
|
-
* @inheritdoc
|
|
22
|
-
*/
|
|
23
|
-
verifyPassword(plainTextPassword: string): Promise<boolean>;
|
|
24
|
-
}
|
|
25
|
-
/**
|
|
26
|
-
* Database user provider is used to lookup user for authentication
|
|
27
|
-
* using the Database query builder.
|
|
28
|
-
*/
|
|
29
|
-
export declare abstract class BaseDatabaseUserProvider<RealUser extends Record<string, any>> implements UserProviderContract<RealUser> {
|
|
30
|
-
/**
|
|
31
|
-
* Reference to the database query builder needed to
|
|
32
|
-
* query the database for users
|
|
33
|
-
*/
|
|
34
|
-
protected db: Database;
|
|
35
|
-
/**
|
|
36
|
-
* Hasher is used to verify plain text passwords
|
|
37
|
-
*/
|
|
38
|
-
protected hasher: Hash;
|
|
39
|
-
/**
|
|
40
|
-
* Options accepted
|
|
41
|
-
*/
|
|
42
|
-
protected options: DatabaseUserProviderOptions<RealUser>;
|
|
43
|
-
[PROVIDER_REAL_USER]: RealUser;
|
|
44
|
-
constructor(
|
|
45
|
-
/**
|
|
46
|
-
* Reference to the database query builder needed to
|
|
47
|
-
* query the database for users
|
|
48
|
-
*/
|
|
49
|
-
db: Database,
|
|
50
|
-
/**
|
|
51
|
-
* Hasher is used to verify plain text passwords
|
|
52
|
-
*/
|
|
53
|
-
hasher: Hash,
|
|
54
|
-
/**
|
|
55
|
-
* Options accepted
|
|
56
|
-
*/
|
|
57
|
-
options: DatabaseUserProviderOptions<RealUser>);
|
|
58
|
-
/**
|
|
59
|
-
* Returns an instance of the query builder
|
|
60
|
-
*/
|
|
61
|
-
protected getQueryBuilder(): import("@adonisjs/lucid/types/querybuilder").DatabaseQueryBuilderContract<any>;
|
|
62
|
-
/**
|
|
63
|
-
* Returns an instance of the "DatabaseUser" that guards
|
|
64
|
-
* can use for authentication
|
|
65
|
-
*/
|
|
66
|
-
createUserForGuard(user: RealUser): Promise<DatabaseUser<RealUser>>;
|
|
67
|
-
/**
|
|
68
|
-
* Finds a user by id by query the configured database
|
|
69
|
-
* table
|
|
70
|
-
*/
|
|
71
|
-
findById(value: string | number): Promise<DatabaseUser<RealUser> | null>;
|
|
72
|
-
/**
|
|
73
|
-
* Finds a user using one of the pre-configured unique
|
|
74
|
-
* ids, via the configured model.
|
|
75
|
-
*/
|
|
76
|
-
findByUid(value: string | number): Promise<DatabaseUser<RealUser> | null>;
|
|
77
|
-
}
|
|
78
|
-
export {};
|
|
@@ -1,117 +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 { RuntimeException } from '@poppinss/utils';
|
|
10
|
-
import debug from '../../auth/debug.js';
|
|
11
|
-
import { GuardUser } from '../guard_user.js';
|
|
12
|
-
import { PROVIDER_REAL_USER } from '../../auth/symbols.js';
|
|
13
|
-
/**
|
|
14
|
-
* Database user represents a guard user used by authentication guards
|
|
15
|
-
* to perform authentication.
|
|
16
|
-
*/
|
|
17
|
-
class DatabaseUser extends GuardUser {
|
|
18
|
-
#options;
|
|
19
|
-
#hasher;
|
|
20
|
-
constructor(realUser, hasher, options) {
|
|
21
|
-
super(realUser);
|
|
22
|
-
this.#hasher = hasher;
|
|
23
|
-
this.#options = options;
|
|
24
|
-
}
|
|
25
|
-
/**
|
|
26
|
-
* @inheritdoc
|
|
27
|
-
*/
|
|
28
|
-
getId() {
|
|
29
|
-
const id = this.realUser[this.#options.id];
|
|
30
|
-
if (!id) {
|
|
31
|
-
throw new RuntimeException(`Invalid user object. The value of column "${this.#options.id}" is undefined or null`);
|
|
32
|
-
}
|
|
33
|
-
return id;
|
|
34
|
-
}
|
|
35
|
-
/**
|
|
36
|
-
* @inheritdoc
|
|
37
|
-
*/
|
|
38
|
-
async verifyPassword(plainTextPassword) {
|
|
39
|
-
const password = this.realUser[this.#options.passwordColumnName];
|
|
40
|
-
if (!password) {
|
|
41
|
-
throw new RuntimeException(`Cannot verify password during login. The value of column "${this.#options.passwordColumnName}" is undefined or null`);
|
|
42
|
-
}
|
|
43
|
-
return this.#hasher.verify(password, plainTextPassword);
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
/**
|
|
47
|
-
* Database user provider is used to lookup user for authentication
|
|
48
|
-
* using the Database query builder.
|
|
49
|
-
*/
|
|
50
|
-
export class BaseDatabaseUserProvider {
|
|
51
|
-
db;
|
|
52
|
-
hasher;
|
|
53
|
-
options;
|
|
54
|
-
constructor(
|
|
55
|
-
/**
|
|
56
|
-
* Reference to the database query builder needed to
|
|
57
|
-
* query the database for users
|
|
58
|
-
*/
|
|
59
|
-
db,
|
|
60
|
-
/**
|
|
61
|
-
* Hasher is used to verify plain text passwords
|
|
62
|
-
*/
|
|
63
|
-
hasher,
|
|
64
|
-
/**
|
|
65
|
-
* Options accepted
|
|
66
|
-
*/
|
|
67
|
-
options) {
|
|
68
|
-
this.db = db;
|
|
69
|
-
this.hasher = hasher;
|
|
70
|
-
this.options = options;
|
|
71
|
-
debug('db_user_provider: options %O', options);
|
|
72
|
-
}
|
|
73
|
-
/**
|
|
74
|
-
* Returns an instance of the query builder
|
|
75
|
-
*/
|
|
76
|
-
getQueryBuilder() {
|
|
77
|
-
return this.db.connection(this.options.connection).query();
|
|
78
|
-
}
|
|
79
|
-
/**
|
|
80
|
-
* Returns an instance of the "DatabaseUser" that guards
|
|
81
|
-
* can use for authentication
|
|
82
|
-
*/
|
|
83
|
-
async createUserForGuard(user) {
|
|
84
|
-
if (!user || typeof user !== 'object') {
|
|
85
|
-
throw new RuntimeException(`Invalid user object. It must be a database row object from the "${this.options.table}" table`);
|
|
86
|
-
}
|
|
87
|
-
debug('db_user_provider: converting user object to guard user %O', user);
|
|
88
|
-
return new DatabaseUser(user, this.hasher, this.options);
|
|
89
|
-
}
|
|
90
|
-
/**
|
|
91
|
-
* Finds a user by id by query the configured database
|
|
92
|
-
* table
|
|
93
|
-
*/
|
|
94
|
-
async findById(value) {
|
|
95
|
-
const query = this.getQueryBuilder().from(this.options.table);
|
|
96
|
-
debug('db_user_provider: finding user by id %s', value);
|
|
97
|
-
const user = await query.where(this.options.id, value).limit(1).first();
|
|
98
|
-
if (!user) {
|
|
99
|
-
return null;
|
|
100
|
-
}
|
|
101
|
-
return this.createUserForGuard(user);
|
|
102
|
-
}
|
|
103
|
-
/**
|
|
104
|
-
* Finds a user using one of the pre-configured unique
|
|
105
|
-
* ids, via the configured model.
|
|
106
|
-
*/
|
|
107
|
-
async findByUid(value) {
|
|
108
|
-
const query = this.getQueryBuilder().from(this.options.table);
|
|
109
|
-
this.options.uids.forEach((uid) => query.orWhere(uid, value));
|
|
110
|
-
debug('db_user_provider: finding user by uids, uids: %O, value: %s', this.options.uids, value);
|
|
111
|
-
const user = await query.limit(1).first();
|
|
112
|
-
if (!user) {
|
|
113
|
-
return null;
|
|
114
|
-
}
|
|
115
|
-
return this.createUserForGuard(user);
|
|
116
|
-
}
|
|
117
|
-
}
|
|
@@ -1,61 +0,0 @@
|
|
|
1
|
-
import { GuardUser } from '../guard_user.js';
|
|
2
|
-
import { PROVIDER_REAL_USER } from '../../auth/symbols.js';
|
|
3
|
-
import type { UserProviderContract, LucidAuthenticatable, LucidUserProviderOptions } from '../types.js';
|
|
4
|
-
/**
|
|
5
|
-
* Lucid user represents a guard user, used by authentication guards
|
|
6
|
-
* to perform authentication.
|
|
7
|
-
*/
|
|
8
|
-
declare class LucidUser<RealUser extends InstanceType<LucidAuthenticatable>> extends GuardUser<RealUser> {
|
|
9
|
-
/**
|
|
10
|
-
* @inheritdoc
|
|
11
|
-
*/
|
|
12
|
-
getId(): string | number;
|
|
13
|
-
/**
|
|
14
|
-
* @inheritdoc
|
|
15
|
-
*/
|
|
16
|
-
verifyPassword(plainTextPassword: string): Promise<boolean>;
|
|
17
|
-
}
|
|
18
|
-
/**
|
|
19
|
-
* Lucid user provider is used to lookup user for authentication
|
|
20
|
-
* using a Lucid model.
|
|
21
|
-
*/
|
|
22
|
-
export declare abstract class BaseLucidUserProvider<UserModel extends LucidAuthenticatable> implements UserProviderContract<InstanceType<UserModel>> {
|
|
23
|
-
/**
|
|
24
|
-
* Lucid provider options
|
|
25
|
-
*/
|
|
26
|
-
protected options: LucidUserProviderOptions<UserModel>;
|
|
27
|
-
[PROVIDER_REAL_USER]: InstanceType<UserModel>;
|
|
28
|
-
/**
|
|
29
|
-
* Reference to the lazily imported model
|
|
30
|
-
*/
|
|
31
|
-
protected model?: UserModel;
|
|
32
|
-
constructor(
|
|
33
|
-
/**
|
|
34
|
-
* Lucid provider options
|
|
35
|
-
*/
|
|
36
|
-
options: LucidUserProviderOptions<UserModel>);
|
|
37
|
-
/**
|
|
38
|
-
* Imports the model from the provider, returns and caches it
|
|
39
|
-
* for further operations.
|
|
40
|
-
*/
|
|
41
|
-
protected getModel(): Promise<UserModel>;
|
|
42
|
-
/**
|
|
43
|
-
* Returns an instance of the query builder
|
|
44
|
-
*/
|
|
45
|
-
protected getQueryBuilder(model: UserModel): import("@adonisjs/lucid/types/model").ModelQueryBuilderContract<UserModel, InstanceType<UserModel>>;
|
|
46
|
-
/**
|
|
47
|
-
* Returns an instance of the "LucidUser" that guards
|
|
48
|
-
* can use for authentication
|
|
49
|
-
*/
|
|
50
|
-
createUserForGuard(user: InstanceType<UserModel>): Promise<LucidUser<InstanceType<UserModel>>>;
|
|
51
|
-
/**
|
|
52
|
-
* Finds a user by id using the configured model.
|
|
53
|
-
*/
|
|
54
|
-
findById(value: string | number): Promise<LucidUser<InstanceType<UserModel>> | null>;
|
|
55
|
-
/**
|
|
56
|
-
* Finds a user using one of the pre-configured unique
|
|
57
|
-
* ids, via the configured model.
|
|
58
|
-
*/
|
|
59
|
-
findByUid(value: string | number): Promise<LucidUser<InstanceType<UserModel>> | null>;
|
|
60
|
-
}
|
|
61
|
-
export {};
|