@adonisjs/auth 8.2.2 → 9.0.0-0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE.md +1 -1
- package/README.md +19 -40
- package/build/configure.d.ts +5 -0
- package/build/configure.js +41 -0
- package/build/factories/database_token_factory.d.ts +36 -0
- package/build/factories/database_token_factory.js +54 -0
- package/build/factories/database_user_provider.d.ts +14 -0
- package/build/factories/database_user_provider.js +27 -0
- package/build/factories/lucid_user_provider.d.ts +28 -0
- package/build/factories/lucid_user_provider.js +68 -0
- package/build/factories/main.d.ts +4 -0
- package/build/factories/main.js +12 -0
- package/build/factories/session_guard_factory.d.ts +13 -0
- package/build/factories/session_guard_factory.js +24 -0
- package/build/index.d.ts +7 -0
- package/build/index.js +15 -0
- package/build/providers/auth_provider.d.ts +12 -0
- package/build/providers/auth_provider.js +27 -0
- package/build/services/auth.d.ts +3 -0
- package/build/services/auth.js +17 -0
- package/build/src/auth/auth_manager.d.ts +18 -0
- package/build/src/auth/auth_manager.js +28 -0
- package/build/src/auth/authenticator.d.ts +18 -0
- package/build/src/auth/authenticator.js +55 -0
- package/build/src/auth/debug.d.ts +3 -0
- package/build/{adonis-typings/container.js → src/auth/debug.js} +3 -1
- package/build/src/auth/define_config.d.ts +30 -0
- package/build/src/auth/define_config.js +54 -0
- package/build/src/auth/errors.d.ts +8 -0
- package/build/src/auth/errors.js +17 -0
- package/build/src/auth/symbols.d.ts +9 -0
- package/build/src/auth/symbols.js +17 -0
- package/build/src/auth/types.d.ts +52 -0
- package/build/{adonis-typings/context.js → src/auth/types.js} +2 -1
- package/build/src/auth/user_providers/main.d.ts +15 -0
- package/build/src/auth/user_providers/main.js +22 -0
- package/build/src/core/guard_user.d.ts +26 -0
- package/build/src/core/guard_user.js +29 -0
- package/build/src/core/token.d.ts +86 -0
- package/build/src/core/token.js +112 -0
- package/build/src/core/token_providers/database.d.ts +77 -0
- package/build/src/core/token_providers/database.js +113 -0
- package/build/src/core/types.d.ts +178 -0
- package/build/{adonis-typings/auth.js → src/core/types.js} +2 -1
- package/build/src/core/user_providers/database.d.ts +78 -0
- package/build/src/core/user_providers/database.js +117 -0
- package/build/src/core/user_providers/lucid.d.ts +61 -0
- package/build/src/core/user_providers/lucid.js +122 -0
- package/build/src/guards/session/define_config.d.ts +23 -0
- package/build/src/guards/session/define_config.js +56 -0
- package/build/src/guards/session/guard.d.ts +92 -0
- package/build/src/guards/session/guard.js +380 -0
- package/build/src/guards/session/main.d.ts +3 -0
- package/build/src/guards/session/main.js +11 -0
- package/build/src/guards/session/token.d.ts +57 -0
- package/build/src/guards/session/token.js +58 -0
- package/build/src/guards/session/token_providers/main.d.ts +33 -0
- package/build/src/guards/session/token_providers/main.js +42 -0
- package/build/src/guards/session/types.d.ts +97 -0
- package/build/{adonis-typings/events.js → src/guards/session/types.js} +2 -1
- package/build/stubs/config/auth_middleware.stub +12 -0
- package/build/stubs/config.stub +35 -0
- package/build/stubs/main.d.ts +1 -0
- package/build/{adonis-typings/tests.js → stubs/main.js} +2 -3
- package/package.json +96 -91
- package/build/adonis-typings/auth.d.ts +0 -635
- package/build/adonis-typings/container.d.ts +0 -6
- package/build/adonis-typings/context.d.ts +0 -6
- package/build/adonis-typings/events.d.ts +0 -10
- package/build/adonis-typings/index.d.ts +0 -5
- package/build/adonis-typings/index.js +0 -13
- package/build/adonis-typings/tests.d.ts +0 -23
- package/build/instructions.js +0 -338
- package/build/providers/AuthProvider.d.ts +0 -30
- package/build/providers/AuthProvider.js +0 -69
- package/build/src/Auth/index.d.ts +0 -97
- package/build/src/Auth/index.js +0 -155
- package/build/src/AuthManager/index.d.ts +0 -117
- package/build/src/AuthManager/index.js +0 -262
- package/build/src/Bindings/Tests.d.ts +0 -6
- package/build/src/Bindings/Tests.js +0 -69
- package/build/src/Clients/Oat/index.d.ts +0 -50
- package/build/src/Clients/Oat/index.js +0 -123
- package/build/src/Clients/Session/index.d.ts +0 -34
- package/build/src/Clients/Session/index.js +0 -72
- package/build/src/Exceptions/AuthenticationException.d.ts +0 -47
- package/build/src/Exceptions/AuthenticationException.js +0 -142
- package/build/src/Exceptions/InvalidCredentialsException.d.ts +0 -34
- package/build/src/Exceptions/InvalidCredentialsException.js +0 -112
- package/build/src/Guards/Base/index.d.ts +0 -75
- package/build/src/Guards/Base/index.js +0 -138
- package/build/src/Guards/BasicAuth/index.d.ts +0 -67
- package/build/src/Guards/BasicAuth/index.js +0 -181
- package/build/src/Guards/Oat/index.d.ts +0 -149
- package/build/src/Guards/Oat/index.js +0 -347
- package/build/src/Guards/Session/index.d.ts +0 -127
- package/build/src/Guards/Session/index.js +0 -338
- package/build/src/TokenProviders/Database/index.d.ts +0 -43
- package/build/src/TokenProviders/Database/index.js +0 -126
- package/build/src/TokenProviders/Redis/index.d.ts +0 -44
- package/build/src/TokenProviders/Redis/index.js +0 -129
- package/build/src/Tokens/OpaqueToken/index.d.ts +0 -46
- package/build/src/Tokens/OpaqueToken/index.js +0 -43
- package/build/src/Tokens/ProviderToken/index.d.ts +0 -23
- package/build/src/Tokens/ProviderToken/index.js +0 -27
- package/build/src/UserProviders/Database/User.d.ts +0 -28
- package/build/src/UserProviders/Database/User.js +0 -74
- package/build/src/UserProviders/Database/index.d.ts +0 -75
- package/build/src/UserProviders/Database/index.js +0 -141
- package/build/src/UserProviders/Lucid/User.d.ts +0 -28
- package/build/src/UserProviders/Lucid/User.js +0 -74
- package/build/src/UserProviders/Lucid/index.d.ts +0 -72
- package/build/src/UserProviders/Lucid/index.js +0 -146
- package/build/standalone.d.ts +0 -1
- package/build/standalone.js +0 -13
- package/build/templates/config/auth.txt +0 -34
- package/build/templates/config/partials/api-guard.txt +0 -22
- package/build/templates/config/partials/basic-guard.txt +0 -19
- package/build/templates/config/partials/tokens-provider-database.txt +0 -19
- package/build/templates/config/partials/tokens-provider-redis.txt +0 -22
- package/build/templates/config/partials/user-provider-database.txt +0 -43
- package/build/templates/config/partials/user-provider-lucid.txt +0 -45
- package/build/templates/config/partials/web-guard.txt +0 -17
- package/build/templates/contract/auth.txt +0 -55
- package/build/templates/contract/partials/api-guard.txt +0 -14
- package/build/templates/contract/partials/basic-guard.txt +0 -14
- package/build/templates/contract/partials/user-provider-database.txt +0 -16
- package/build/templates/contract/partials/user-provider-lucid.txt +0 -16
- package/build/templates/contract/partials/web-guard.txt +0 -14
- package/build/templates/middleware/Auth.txt +0 -76
- package/build/templates/middleware/SilentAuth.txt +0 -21
- package/build/templates/migrations/api_tokens.txt +0 -25
- package/build/templates/migrations/auth.txt +0 -24
- package/build/templates/model.txt +0 -30
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
import { DateTime } from 'luxon';
|
|
2
|
-
import { OpaqueTokenContract } from '@ioc:Adonis/Addons/Auth';
|
|
3
|
-
/**
|
|
4
|
-
* Opaque token represents a persisted token generated for a given user
|
|
5
|
-
*
|
|
6
|
-
* Calling `opaqueToken.toJSON()` will give you an object, that you can send back
|
|
7
|
-
* as response to share the token with the client.
|
|
8
|
-
*/
|
|
9
|
-
export declare class OpaqueToken implements OpaqueTokenContract<any> {
|
|
10
|
-
name: string;
|
|
11
|
-
token: string;
|
|
12
|
-
user: any;
|
|
13
|
-
/**
|
|
14
|
-
* The type of the token. Always set to bearer
|
|
15
|
-
*/
|
|
16
|
-
type: "bearer";
|
|
17
|
-
/**
|
|
18
|
-
* The datetime in which the token will expire
|
|
19
|
-
*/
|
|
20
|
-
expiresAt?: DateTime;
|
|
21
|
-
/**
|
|
22
|
-
* Time left until token gets expired
|
|
23
|
-
*/
|
|
24
|
-
expiresIn?: number;
|
|
25
|
-
/**
|
|
26
|
-
* Any meta data attached to the token
|
|
27
|
-
*/
|
|
28
|
-
meta: any;
|
|
29
|
-
/**
|
|
30
|
-
* Hash of the token saved inside the database. Make sure to never share
|
|
31
|
-
* this with the client
|
|
32
|
-
*/
|
|
33
|
-
tokenHash: string;
|
|
34
|
-
constructor(name: string, // Name associated with the token
|
|
35
|
-
token: string, // The raw token value. Only available for the first time
|
|
36
|
-
user: any);
|
|
37
|
-
/**
|
|
38
|
-
* Shareable version of the token
|
|
39
|
-
*/
|
|
40
|
-
toJSON(): {
|
|
41
|
-
expires_in?: number | undefined;
|
|
42
|
-
expires_at?: string | undefined;
|
|
43
|
-
type: "bearer";
|
|
44
|
-
token: string;
|
|
45
|
-
};
|
|
46
|
-
}
|
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/*
|
|
3
|
-
* @adonisjs/auth
|
|
4
|
-
*
|
|
5
|
-
* (c) Harminder Virk <virk@adonisjs.com>
|
|
6
|
-
*
|
|
7
|
-
* For the full copyright and license information, please view the LICENSE
|
|
8
|
-
* file that was distributed with this source code.
|
|
9
|
-
*/
|
|
10
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
11
|
-
exports.OpaqueToken = void 0;
|
|
12
|
-
/**
|
|
13
|
-
* Opaque token represents a persisted token generated for a given user
|
|
14
|
-
*
|
|
15
|
-
* Calling `opaqueToken.toJSON()` will give you an object, that you can send back
|
|
16
|
-
* as response to share the token with the client.
|
|
17
|
-
*/
|
|
18
|
-
class OpaqueToken {
|
|
19
|
-
constructor(name, // Name associated with the token
|
|
20
|
-
token, // The raw token value. Only available for the first time
|
|
21
|
-
user // The user for which the token is generated
|
|
22
|
-
) {
|
|
23
|
-
this.name = name;
|
|
24
|
-
this.token = token;
|
|
25
|
-
this.user = user;
|
|
26
|
-
/**
|
|
27
|
-
* The type of the token. Always set to bearer
|
|
28
|
-
*/
|
|
29
|
-
this.type = 'bearer';
|
|
30
|
-
}
|
|
31
|
-
/**
|
|
32
|
-
* Shareable version of the token
|
|
33
|
-
*/
|
|
34
|
-
toJSON() {
|
|
35
|
-
return {
|
|
36
|
-
type: this.type,
|
|
37
|
-
token: this.token,
|
|
38
|
-
...(this.expiresAt ? { expires_at: this.expiresAt.toISO() || undefined } : {}),
|
|
39
|
-
...(this.expiresIn ? { expires_in: this.expiresIn } : {}),
|
|
40
|
-
};
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
exports.OpaqueToken = OpaqueToken;
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import { DateTime } from 'luxon';
|
|
2
|
-
import { ProviderTokenContract } from '@ioc:Adonis/Addons/Auth';
|
|
3
|
-
/**
|
|
4
|
-
* Token returned and accepted by the token providers
|
|
5
|
-
*/
|
|
6
|
-
export declare class ProviderToken implements ProviderTokenContract {
|
|
7
|
-
name: string;
|
|
8
|
-
tokenHash: string;
|
|
9
|
-
userId: string | number;
|
|
10
|
-
type: string;
|
|
11
|
-
/**
|
|
12
|
-
* Expiry date
|
|
13
|
-
*/
|
|
14
|
-
expiresAt?: DateTime;
|
|
15
|
-
/**
|
|
16
|
-
* All other token details
|
|
17
|
-
*/
|
|
18
|
-
meta?: any;
|
|
19
|
-
constructor(name: string, // Name associated with the token
|
|
20
|
-
tokenHash: string, // The hash to persist
|
|
21
|
-
userId: string | number, // The user for which the token is generated
|
|
22
|
-
type: string);
|
|
23
|
-
}
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/*
|
|
3
|
-
* @adonisjs/auth
|
|
4
|
-
*
|
|
5
|
-
* (c) Harminder Virk <virk@adonisjs.com>
|
|
6
|
-
*
|
|
7
|
-
* For the full copyright and license information, please view the LICENSE
|
|
8
|
-
* file that was distributed with this source code.
|
|
9
|
-
*/
|
|
10
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
11
|
-
exports.ProviderToken = void 0;
|
|
12
|
-
/**
|
|
13
|
-
* Token returned and accepted by the token providers
|
|
14
|
-
*/
|
|
15
|
-
class ProviderToken {
|
|
16
|
-
constructor(name, // Name associated with the token
|
|
17
|
-
tokenHash, // The hash to persist
|
|
18
|
-
userId, // The user for which the token is generated
|
|
19
|
-
type // The type of the token.
|
|
20
|
-
) {
|
|
21
|
-
this.name = name;
|
|
22
|
-
this.tokenHash = tokenHash;
|
|
23
|
-
this.userId = userId;
|
|
24
|
-
this.type = type;
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
exports.ProviderToken = ProviderToken;
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
/// <reference types="@adonisjs/hash/build/adonis-typings" />
|
|
2
|
-
import type { HashContract } from '@ioc:Adonis/Core/Hash';
|
|
3
|
-
import type { ProviderUserContract, DatabaseProviderRow, DatabaseProviderConfig } from '@ioc:Adonis/Addons/Auth';
|
|
4
|
-
/**
|
|
5
|
-
* Database user works a bridge between the provider and the guard
|
|
6
|
-
*/
|
|
7
|
-
export declare class DatabaseUser implements ProviderUserContract<DatabaseProviderRow> {
|
|
8
|
-
user: DatabaseProviderRow | null;
|
|
9
|
-
private config;
|
|
10
|
-
private hash;
|
|
11
|
-
constructor(user: DatabaseProviderRow | null, config: DatabaseProviderConfig, hash: HashContract);
|
|
12
|
-
/**
|
|
13
|
-
* Returns the value of the user id
|
|
14
|
-
*/
|
|
15
|
-
getId(): any;
|
|
16
|
-
/**
|
|
17
|
-
* Verifies the user password
|
|
18
|
-
*/
|
|
19
|
-
verifyPassword(plainPassword: string): Promise<boolean>;
|
|
20
|
-
/**
|
|
21
|
-
* Returns the user remember me token or null
|
|
22
|
-
*/
|
|
23
|
-
getRememberMeToken(): string | null;
|
|
24
|
-
/**
|
|
25
|
-
* Updates user remember me token
|
|
26
|
-
*/
|
|
27
|
-
setRememberMeToken(token: string): void;
|
|
28
|
-
}
|
|
@@ -1,74 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/*
|
|
3
|
-
* @adonisjs/auth
|
|
4
|
-
*
|
|
5
|
-
* (c) Harminder Virk <virk@adonisjs.com>
|
|
6
|
-
*
|
|
7
|
-
* For the full copyright and license information, please view the LICENSE
|
|
8
|
-
* file that was distributed with this source code.
|
|
9
|
-
*/
|
|
10
|
-
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
11
|
-
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
12
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
13
|
-
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;
|
|
14
|
-
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
15
|
-
};
|
|
16
|
-
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
17
|
-
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
18
|
-
};
|
|
19
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
20
|
-
exports.DatabaseUser = void 0;
|
|
21
|
-
const utils_1 = require("@poppinss/utils");
|
|
22
|
-
const standalone_1 = require("@adonisjs/core/build/standalone");
|
|
23
|
-
/**
|
|
24
|
-
* Database user works a bridge between the provider and the guard
|
|
25
|
-
*/
|
|
26
|
-
let DatabaseUser = class DatabaseUser {
|
|
27
|
-
constructor(user, config, hash) {
|
|
28
|
-
this.user = user;
|
|
29
|
-
this.config = config;
|
|
30
|
-
this.hash = hash;
|
|
31
|
-
}
|
|
32
|
-
/**
|
|
33
|
-
* Returns the value of the user id
|
|
34
|
-
*/
|
|
35
|
-
getId() {
|
|
36
|
-
return this.user ? this.user[this.config.identifierKey] : null;
|
|
37
|
-
}
|
|
38
|
-
/**
|
|
39
|
-
* Verifies the user password
|
|
40
|
-
*/
|
|
41
|
-
async verifyPassword(plainPassword) {
|
|
42
|
-
if (!this.user) {
|
|
43
|
-
throw new utils_1.Exception('Cannot "verifyPassword" for non-existing user');
|
|
44
|
-
}
|
|
45
|
-
/**
|
|
46
|
-
* Ensure user has password
|
|
47
|
-
*/
|
|
48
|
-
if (!this.user.password) {
|
|
49
|
-
throw new utils_1.Exception('Auth user object must have a password in order to call "verifyPassword"');
|
|
50
|
-
}
|
|
51
|
-
const hasher = this.config.hashDriver ? this.hash.use(this.config.hashDriver) : this.hash;
|
|
52
|
-
return hasher.verify(this.user.password, plainPassword);
|
|
53
|
-
}
|
|
54
|
-
/**
|
|
55
|
-
* Returns the user remember me token or null
|
|
56
|
-
*/
|
|
57
|
-
getRememberMeToken() {
|
|
58
|
-
return this.user ? this.user.remember_me_token || null : null;
|
|
59
|
-
}
|
|
60
|
-
/**
|
|
61
|
-
* Updates user remember me token
|
|
62
|
-
*/
|
|
63
|
-
setRememberMeToken(token) {
|
|
64
|
-
if (!this.user) {
|
|
65
|
-
throw new utils_1.Exception('Cannot set "rememberMeToken" on non-existing user');
|
|
66
|
-
}
|
|
67
|
-
this.user.remember_me_token = token;
|
|
68
|
-
}
|
|
69
|
-
};
|
|
70
|
-
DatabaseUser = __decorate([
|
|
71
|
-
(0, standalone_1.inject)([null, null, 'Adonis/Core/Hash']),
|
|
72
|
-
__metadata("design:paramtypes", [Object, Object, Object])
|
|
73
|
-
], DatabaseUser);
|
|
74
|
-
exports.DatabaseUser = DatabaseUser;
|
|
@@ -1,75 +0,0 @@
|
|
|
1
|
-
/// <reference types="@adonisjs/application/build/adonis-typings/application" />
|
|
2
|
-
import { ApplicationContract } from '@ioc:Adonis/Core/Application';
|
|
3
|
-
import { DatabaseContract, QueryClientContract } from '@ioc:Adonis/Lucid/Database';
|
|
4
|
-
import { DatabaseProviderRow, ProviderUserContract, DatabaseProviderConfig, DatabaseProviderContract } from '@ioc:Adonis/Addons/Auth';
|
|
5
|
-
/**
|
|
6
|
-
* Database provider to lookup users inside the database
|
|
7
|
-
*/
|
|
8
|
-
export declare class DatabaseProvider implements DatabaseProviderContract<DatabaseProviderRow> {
|
|
9
|
-
private application;
|
|
10
|
-
private config;
|
|
11
|
-
private db;
|
|
12
|
-
/**
|
|
13
|
-
* Hooks reference
|
|
14
|
-
*/
|
|
15
|
-
private hooks;
|
|
16
|
-
/**
|
|
17
|
-
* Custom connection or query client
|
|
18
|
-
*/
|
|
19
|
-
private connection?;
|
|
20
|
-
/**
|
|
21
|
-
* Name of the remember_me_token column
|
|
22
|
-
*/
|
|
23
|
-
private rememberMeColumn;
|
|
24
|
-
constructor(application: ApplicationContract, config: DatabaseProviderConfig, db: DatabaseContract);
|
|
25
|
-
/**
|
|
26
|
-
* Returns the query client for invoking queries
|
|
27
|
-
*/
|
|
28
|
-
private getQueryClient;
|
|
29
|
-
/**
|
|
30
|
-
* Returns the query builder instance for the users table
|
|
31
|
-
*/
|
|
32
|
-
private getUserQueryBuilder;
|
|
33
|
-
/**
|
|
34
|
-
* Ensure "user.id" is always present
|
|
35
|
-
*/
|
|
36
|
-
private ensureUserHasId;
|
|
37
|
-
/**
|
|
38
|
-
* Executes the query to find the user, calls the registered hooks
|
|
39
|
-
* and wraps the result inside [[ProviderUserContract]]
|
|
40
|
-
*/
|
|
41
|
-
private findUser;
|
|
42
|
-
/**
|
|
43
|
-
* Returns an instance of provider user
|
|
44
|
-
*/
|
|
45
|
-
getUserFor(user: any): Promise<ProviderUserContract<DatabaseProviderRow>>;
|
|
46
|
-
/**
|
|
47
|
-
* Define custom connection
|
|
48
|
-
*/
|
|
49
|
-
setConnection(connection: string | QueryClientContract): this;
|
|
50
|
-
/**
|
|
51
|
-
* Define before hooks. Check interface for exact type information
|
|
52
|
-
*/
|
|
53
|
-
before(event: 'findUser', callback: (query: any) => Promise<void>): this;
|
|
54
|
-
/**
|
|
55
|
-
* Define after hooks. Check interface for exact type information
|
|
56
|
-
*/
|
|
57
|
-
after(event: 'findUser', callback: (...args: any[]) => Promise<void>): this;
|
|
58
|
-
/**
|
|
59
|
-
* Returns the user row using the primary key
|
|
60
|
-
*/
|
|
61
|
-
findById(id: string | number): Promise<ProviderUserContract<DatabaseProviderRow>>;
|
|
62
|
-
/**
|
|
63
|
-
* Returns a user from their remember me token
|
|
64
|
-
*/
|
|
65
|
-
findByRememberMeToken(id: number | string, token: string): Promise<ProviderUserContract<DatabaseProviderRow>>;
|
|
66
|
-
/**
|
|
67
|
-
* Returns the user row by searching the uidValue against
|
|
68
|
-
* their defined uids.
|
|
69
|
-
*/
|
|
70
|
-
findByUid(uidValue: string): Promise<ProviderUserContract<DatabaseProviderRow>>;
|
|
71
|
-
/**
|
|
72
|
-
* Updates the user remember me token
|
|
73
|
-
*/
|
|
74
|
-
updateRememberMeToken(user: ProviderUserContract<DatabaseProviderRow>): Promise<void>;
|
|
75
|
-
}
|
|
@@ -1,141 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/*
|
|
3
|
-
* @adonisjs/auth
|
|
4
|
-
*
|
|
5
|
-
* (c) Harminder Virk <virk@adonisjs.com>
|
|
6
|
-
*
|
|
7
|
-
* For the full copyright and license information, please view the LICENSE
|
|
8
|
-
* file that was distributed with this source code.
|
|
9
|
-
*/
|
|
10
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
11
|
-
exports.DatabaseProvider = void 0;
|
|
12
|
-
const hooks_1 = require("@poppinss/hooks");
|
|
13
|
-
const utils_1 = require("@poppinss/utils");
|
|
14
|
-
const User_1 = require("./User");
|
|
15
|
-
/**
|
|
16
|
-
* Database provider to lookup users inside the database
|
|
17
|
-
*/
|
|
18
|
-
class DatabaseProvider {
|
|
19
|
-
constructor(application, config, db) {
|
|
20
|
-
this.application = application;
|
|
21
|
-
this.config = config;
|
|
22
|
-
this.db = db;
|
|
23
|
-
/**
|
|
24
|
-
* Hooks reference
|
|
25
|
-
*/
|
|
26
|
-
this.hooks = new hooks_1.Hooks();
|
|
27
|
-
/**
|
|
28
|
-
* Name of the remember_me_token column
|
|
29
|
-
*/
|
|
30
|
-
this.rememberMeColumn = 'remember_me_token';
|
|
31
|
-
}
|
|
32
|
-
/**
|
|
33
|
-
* Returns the query client for invoking queries
|
|
34
|
-
*/
|
|
35
|
-
getQueryClient() {
|
|
36
|
-
if (!this.connection) {
|
|
37
|
-
return this.db.connection(this.config.connection);
|
|
38
|
-
}
|
|
39
|
-
return typeof this.connection === 'string'
|
|
40
|
-
? this.db.connection(this.connection)
|
|
41
|
-
: this.connection;
|
|
42
|
-
}
|
|
43
|
-
/**
|
|
44
|
-
* Returns the query builder instance for the users table
|
|
45
|
-
*/
|
|
46
|
-
getUserQueryBuilder() {
|
|
47
|
-
return this.getQueryClient().from(this.config.usersTable);
|
|
48
|
-
}
|
|
49
|
-
/**
|
|
50
|
-
* Ensure "user.id" is always present
|
|
51
|
-
*/
|
|
52
|
-
ensureUserHasId(user) {
|
|
53
|
-
/**
|
|
54
|
-
* Ignore when user is null
|
|
55
|
-
*/
|
|
56
|
-
if (!user) {
|
|
57
|
-
return;
|
|
58
|
-
}
|
|
59
|
-
if (!user[this.config.identifierKey]) {
|
|
60
|
-
throw new utils_1.Exception(`Auth database provider expects "${this.config.usersTable}.${this.config.identifierKey}" to always exist`);
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
/**
|
|
64
|
-
* Executes the query to find the user, calls the registered hooks
|
|
65
|
-
* and wraps the result inside [[ProviderUserContract]]
|
|
66
|
-
*/
|
|
67
|
-
async findUser(query) {
|
|
68
|
-
await this.hooks.exec('before', 'findUser', query);
|
|
69
|
-
const user = await query.first();
|
|
70
|
-
if (user) {
|
|
71
|
-
await this.hooks.exec('after', 'findUser', user);
|
|
72
|
-
}
|
|
73
|
-
return this.getUserFor(user);
|
|
74
|
-
}
|
|
75
|
-
/**
|
|
76
|
-
* Returns an instance of provider user
|
|
77
|
-
*/
|
|
78
|
-
async getUserFor(user) {
|
|
79
|
-
this.ensureUserHasId(user);
|
|
80
|
-
const UserBuilder = this.config.user ? (0, utils_1.esmResolver)(await this.config.user()) : User_1.DatabaseUser;
|
|
81
|
-
return this.application.container.makeAsync(UserBuilder, [user, this.config]);
|
|
82
|
-
}
|
|
83
|
-
/**
|
|
84
|
-
* Define custom connection
|
|
85
|
-
*/
|
|
86
|
-
setConnection(connection) {
|
|
87
|
-
this.connection = connection;
|
|
88
|
-
return this;
|
|
89
|
-
}
|
|
90
|
-
/**
|
|
91
|
-
* Define before hooks. Check interface for exact type information
|
|
92
|
-
*/
|
|
93
|
-
before(event, callback) {
|
|
94
|
-
this.hooks.add('before', event, callback);
|
|
95
|
-
return this;
|
|
96
|
-
}
|
|
97
|
-
/**
|
|
98
|
-
* Define after hooks. Check interface for exact type information
|
|
99
|
-
*/
|
|
100
|
-
after(event, callback) {
|
|
101
|
-
this.hooks.add('after', event, callback);
|
|
102
|
-
return this;
|
|
103
|
-
}
|
|
104
|
-
/**
|
|
105
|
-
* Returns the user row using the primary key
|
|
106
|
-
*/
|
|
107
|
-
async findById(id) {
|
|
108
|
-
const query = this.getUserQueryBuilder();
|
|
109
|
-
return this.findUser(query.where(this.config.identifierKey, id));
|
|
110
|
-
}
|
|
111
|
-
/**
|
|
112
|
-
* Returns a user from their remember me token
|
|
113
|
-
*/
|
|
114
|
-
async findByRememberMeToken(id, token) {
|
|
115
|
-
const query = this.getUserQueryBuilder()
|
|
116
|
-
.where(this.rememberMeColumn, token)
|
|
117
|
-
.where(this.config.identifierKey, id);
|
|
118
|
-
return this.findUser(query);
|
|
119
|
-
}
|
|
120
|
-
/**
|
|
121
|
-
* Returns the user row by searching the uidValue against
|
|
122
|
-
* their defined uids.
|
|
123
|
-
*/
|
|
124
|
-
async findByUid(uidValue) {
|
|
125
|
-
const query = this.getUserQueryBuilder();
|
|
126
|
-
this.config.uids.forEach((uid) => query.orWhere(uid, uidValue));
|
|
127
|
-
return this.findUser(query);
|
|
128
|
-
}
|
|
129
|
-
/**
|
|
130
|
-
* Updates the user remember me token
|
|
131
|
-
*/
|
|
132
|
-
async updateRememberMeToken(user) {
|
|
133
|
-
this.ensureUserHasId(user);
|
|
134
|
-
await this.getUserQueryBuilder()
|
|
135
|
-
.where(this.config.identifierKey, user[this.config.identifierKey])
|
|
136
|
-
.update({
|
|
137
|
-
remember_me_token: user.getRememberMeToken(),
|
|
138
|
-
});
|
|
139
|
-
}
|
|
140
|
-
}
|
|
141
|
-
exports.DatabaseProvider = DatabaseProvider;
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
/// <reference types="@adonisjs/hash/build/adonis-typings" />
|
|
2
|
-
import type { HashContract } from '@ioc:Adonis/Core/Hash';
|
|
3
|
-
import type { LucidProviderModel, ProviderUserContract, LucidProviderConfig } from '@ioc:Adonis/Addons/Auth';
|
|
4
|
-
/**
|
|
5
|
-
* Lucid works works a bridge between the provider and the guard
|
|
6
|
-
*/
|
|
7
|
-
export declare class LucidUser<User extends LucidProviderModel> implements ProviderUserContract<InstanceType<User>> {
|
|
8
|
-
user: InstanceType<User> | null;
|
|
9
|
-
private config;
|
|
10
|
-
private hash;
|
|
11
|
-
constructor(user: InstanceType<User> | null, config: LucidProviderConfig<User>, hash: HashContract);
|
|
12
|
-
/**
|
|
13
|
-
* Returns the value of the user id
|
|
14
|
-
*/
|
|
15
|
-
getId(): any;
|
|
16
|
-
/**
|
|
17
|
-
* Verifies the user password
|
|
18
|
-
*/
|
|
19
|
-
verifyPassword(plainPassword: string): Promise<boolean>;
|
|
20
|
-
/**
|
|
21
|
-
* Returns the user remember me token or null
|
|
22
|
-
*/
|
|
23
|
-
getRememberMeToken(): string | null;
|
|
24
|
-
/**
|
|
25
|
-
* Updates user remember me token
|
|
26
|
-
*/
|
|
27
|
-
setRememberMeToken(token: string): void;
|
|
28
|
-
}
|
|
@@ -1,74 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/*
|
|
3
|
-
* @adonisjs/auth
|
|
4
|
-
*
|
|
5
|
-
* (c) Harminder Virk <virk@adonisjs.com>
|
|
6
|
-
*
|
|
7
|
-
* For the full copyright and license information, please view the LICENSE
|
|
8
|
-
* file that was distributed with this source code.
|
|
9
|
-
*/
|
|
10
|
-
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
11
|
-
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
12
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
13
|
-
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;
|
|
14
|
-
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
15
|
-
};
|
|
16
|
-
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
17
|
-
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
18
|
-
};
|
|
19
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
20
|
-
exports.LucidUser = void 0;
|
|
21
|
-
const utils_1 = require("@poppinss/utils");
|
|
22
|
-
const standalone_1 = require("@adonisjs/core/build/standalone");
|
|
23
|
-
/**
|
|
24
|
-
* Lucid works works a bridge between the provider and the guard
|
|
25
|
-
*/
|
|
26
|
-
let LucidUser = class LucidUser {
|
|
27
|
-
constructor(user, config, hash) {
|
|
28
|
-
this.user = user;
|
|
29
|
-
this.config = config;
|
|
30
|
-
this.hash = hash;
|
|
31
|
-
}
|
|
32
|
-
/**
|
|
33
|
-
* Returns the value of the user id
|
|
34
|
-
*/
|
|
35
|
-
getId() {
|
|
36
|
-
return this.user ? this.user[this.config.identifierKey] : null;
|
|
37
|
-
}
|
|
38
|
-
/**
|
|
39
|
-
* Verifies the user password
|
|
40
|
-
*/
|
|
41
|
-
async verifyPassword(plainPassword) {
|
|
42
|
-
if (!this.user) {
|
|
43
|
-
throw new utils_1.Exception('Cannot "verifyPassword" for non-existing user');
|
|
44
|
-
}
|
|
45
|
-
/**
|
|
46
|
-
* Ensure user has password
|
|
47
|
-
*/
|
|
48
|
-
if (!this.user.password) {
|
|
49
|
-
throw new utils_1.Exception('Auth user object must have a password in order to call "verifyPassword"');
|
|
50
|
-
}
|
|
51
|
-
const hasher = this.config.hashDriver ? this.hash.use(this.config.hashDriver) : this.hash;
|
|
52
|
-
return hasher.verify(this.user.password, plainPassword);
|
|
53
|
-
}
|
|
54
|
-
/**
|
|
55
|
-
* Returns the user remember me token or null
|
|
56
|
-
*/
|
|
57
|
-
getRememberMeToken() {
|
|
58
|
-
return this.user ? this.user.rememberMeToken || null : null;
|
|
59
|
-
}
|
|
60
|
-
/**
|
|
61
|
-
* Updates user remember me token
|
|
62
|
-
*/
|
|
63
|
-
setRememberMeToken(token) {
|
|
64
|
-
if (!this.user) {
|
|
65
|
-
throw new utils_1.Exception('Cannot set "rememberMeToken" on non-existing user');
|
|
66
|
-
}
|
|
67
|
-
this.user.rememberMeToken = token;
|
|
68
|
-
}
|
|
69
|
-
};
|
|
70
|
-
LucidUser = __decorate([
|
|
71
|
-
(0, standalone_1.inject)([null, null, 'Adonis/Core/Hash']),
|
|
72
|
-
__metadata("design:paramtypes", [Object, Object, Object])
|
|
73
|
-
], LucidUser);
|
|
74
|
-
exports.LucidUser = LucidUser;
|
|
@@ -1,72 +0,0 @@
|
|
|
1
|
-
/// <reference types="@adonisjs/application/build/adonis-typings/application" />
|
|
2
|
-
import { ApplicationContract } from '@ioc:Adonis/Core/Application';
|
|
3
|
-
import { QueryClientContract } from '@ioc:Adonis/Lucid/Database';
|
|
4
|
-
import { LucidProviderModel, LucidProviderConfig, ProviderUserContract, LucidProviderContract } from '@ioc:Adonis/Addons/Auth';
|
|
5
|
-
/**
|
|
6
|
-
* Lucid provider uses Lucid models to lookup a users
|
|
7
|
-
*/
|
|
8
|
-
export declare class LucidProvider implements LucidProviderContract<LucidProviderModel> {
|
|
9
|
-
private application;
|
|
10
|
-
private config;
|
|
11
|
-
/**
|
|
12
|
-
* Hooks reference
|
|
13
|
-
*/
|
|
14
|
-
private hooks;
|
|
15
|
-
/**
|
|
16
|
-
* Custom connection or query client
|
|
17
|
-
*/
|
|
18
|
-
private connection?;
|
|
19
|
-
constructor(application: ApplicationContract, config: LucidProviderConfig<LucidProviderModel>);
|
|
20
|
-
/**
|
|
21
|
-
* The models options for constructing a query
|
|
22
|
-
*/
|
|
23
|
-
private getModelOptions;
|
|
24
|
-
/**
|
|
25
|
-
* Returns the auth model
|
|
26
|
-
*/
|
|
27
|
-
private getModel;
|
|
28
|
-
/**
|
|
29
|
-
* Returns query instance for the user model
|
|
30
|
-
*/
|
|
31
|
-
private getModelQuery;
|
|
32
|
-
/**
|
|
33
|
-
* Executes the query to find the user, calls the registered hooks
|
|
34
|
-
* and wraps the result inside [[ProviderUserContract]]
|
|
35
|
-
*/
|
|
36
|
-
private findUser;
|
|
37
|
-
/**
|
|
38
|
-
* Returns an instance of the [[ProviderUser]] by wrapping lucid model
|
|
39
|
-
* inside it
|
|
40
|
-
*/
|
|
41
|
-
getUserFor(user: InstanceType<LucidProviderModel> | null): Promise<any>;
|
|
42
|
-
/**
|
|
43
|
-
* Define custom connection
|
|
44
|
-
*/
|
|
45
|
-
setConnection(connection: string | QueryClientContract): this;
|
|
46
|
-
/**
|
|
47
|
-
* Define before hooks. Check interface for exact type information
|
|
48
|
-
*/
|
|
49
|
-
before(event: 'findUser', callback: (query: any) => Promise<void>): this;
|
|
50
|
-
/**
|
|
51
|
-
* Define after hooks. Check interface for exact type information
|
|
52
|
-
*/
|
|
53
|
-
after(event: 'findUser', callback: (...args: any[]) => Promise<void>): this;
|
|
54
|
-
/**
|
|
55
|
-
* Returns a user instance using the primary key value
|
|
56
|
-
*/
|
|
57
|
-
findById(id: string | number): Promise<any>;
|
|
58
|
-
/**
|
|
59
|
-
* Returns a user instance using a specific token type and value
|
|
60
|
-
*/
|
|
61
|
-
findByRememberMeToken(id: string | number, value: string): Promise<any>;
|
|
62
|
-
/**
|
|
63
|
-
* Returns the user instance by searching the uidValue against
|
|
64
|
-
* their defined uids.
|
|
65
|
-
*/
|
|
66
|
-
findByUid(uidValue: string): Promise<any>;
|
|
67
|
-
/**
|
|
68
|
-
* Updates the user remember me token. The guard must called `setRememberMeToken`
|
|
69
|
-
* before invoking this method.
|
|
70
|
-
*/
|
|
71
|
-
updateRememberMeToken(providerUser: ProviderUserContract<InstanceType<LucidProviderModel>>): Promise<void>;
|
|
72
|
-
}
|