@adonisjs/auth 8.0.9 → 8.0.12
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/src/Exceptions/AuthenticationException.d.ts +1 -0
- package/build/src/Exceptions/AuthenticationException.js +12 -5
- package/build/src/Exceptions/InvalidCredentialsException.d.ts +1 -0
- package/build/src/Exceptions/InvalidCredentialsException.js +17 -3
- package/build/src/TokenProviders/Database/index.js +2 -2
- package/build/templates/contract/partials/api-guard.txt +3 -3
- package/build/templates/contract/partials/basic-guard.txt +3 -3
- package/build/templates/contract/partials/user-provider-database.txt +3 -3
- package/build/templates/contract/partials/user-provider-lucid.txt +3 -3
- package/build/templates/contract/partials/web-guard.txt +3 -3
- package/build/templates/middleware/Auth.txt +8 -4
- package/build/templates/middleware/SilentAuth.txt +1 -1
- package/build/templates/migrations/api_tokens.txt +2 -2
- package/build/templates/migrations/auth.txt +2 -2
- package/build/templates/model.txt +1 -5
- package/package.json +39 -31
|
@@ -20,6 +20,7 @@ class AuthenticationException extends utils_1.Exception {
|
|
|
20
20
|
constructor(message, code, guard, redirectTo) {
|
|
21
21
|
super(message, 401, code);
|
|
22
22
|
this.redirectTo = '/login';
|
|
23
|
+
this.responseText = this.message;
|
|
23
24
|
if (redirectTo) {
|
|
24
25
|
this.redirectTo = redirectTo;
|
|
25
26
|
}
|
|
@@ -35,7 +36,7 @@ class AuthenticationException extends utils_1.Exception {
|
|
|
35
36
|
ctx.response
|
|
36
37
|
.status(this.status)
|
|
37
38
|
.header('WWW-Authenticate', `Basic realm="${realm}", charset="UTF-8"`)
|
|
38
|
-
.send(
|
|
39
|
+
.send(this.responseText);
|
|
39
40
|
}
|
|
40
41
|
/**
|
|
41
42
|
* Send response as an array of errors
|
|
@@ -44,7 +45,7 @@ class AuthenticationException extends utils_1.Exception {
|
|
|
44
45
|
ctx.response.status(this.status).send({
|
|
45
46
|
errors: [
|
|
46
47
|
{
|
|
47
|
-
message: this.
|
|
48
|
+
message: this.responseText,
|
|
48
49
|
},
|
|
49
50
|
],
|
|
50
51
|
});
|
|
@@ -54,10 +55,10 @@ class AuthenticationException extends utils_1.Exception {
|
|
|
54
55
|
*/
|
|
55
56
|
respondWithRedirect(ctx) {
|
|
56
57
|
if (!ctx.session) {
|
|
57
|
-
return ctx.response.status(this.status).send(this.
|
|
58
|
+
return ctx.response.status(this.status).send(this.responseText);
|
|
58
59
|
}
|
|
59
60
|
ctx.session.flashExcept(['_csrf']);
|
|
60
|
-
ctx.session.flash('auth', { error: this.
|
|
61
|
+
ctx.session.flash('auth', { error: this.responseText });
|
|
61
62
|
ctx.response.redirect(this.redirectTo, true);
|
|
62
63
|
}
|
|
63
64
|
/**
|
|
@@ -68,7 +69,7 @@ class AuthenticationException extends utils_1.Exception {
|
|
|
68
69
|
errors: [
|
|
69
70
|
{
|
|
70
71
|
code: this.code,
|
|
71
|
-
title: this.
|
|
72
|
+
title: this.responseText,
|
|
72
73
|
source: null,
|
|
73
74
|
},
|
|
74
75
|
],
|
|
@@ -101,6 +102,12 @@ class AuthenticationException extends utils_1.Exception {
|
|
|
101
102
|
* We need access to the guard config and driver to make appropriate response
|
|
102
103
|
*/
|
|
103
104
|
const config = this.guard ? ctx.auth.use(this.guard).config : null;
|
|
105
|
+
/**
|
|
106
|
+
* Use translation when using i18n
|
|
107
|
+
*/
|
|
108
|
+
if ('i18n' in ctx) {
|
|
109
|
+
this.responseText = ctx.i18n.formatMessage(`auth.${this.code}`, {}, this.message);
|
|
110
|
+
}
|
|
104
111
|
/**
|
|
105
112
|
* Show username, password prompt when using basic auth driver
|
|
106
113
|
*/
|
|
@@ -14,6 +14,10 @@ const utils_1 = require("@poppinss/utils");
|
|
|
14
14
|
* Exception raised when unable to verify user credentials
|
|
15
15
|
*/
|
|
16
16
|
class InvalidCredentialsException extends utils_1.Exception {
|
|
17
|
+
constructor() {
|
|
18
|
+
super(...arguments);
|
|
19
|
+
this.responseText = this.message;
|
|
20
|
+
}
|
|
17
21
|
/**
|
|
18
22
|
* Unable to find user
|
|
19
23
|
*/
|
|
@@ -37,7 +41,7 @@ class InvalidCredentialsException extends utils_1.Exception {
|
|
|
37
41
|
ctx.response.status(this.status).send({
|
|
38
42
|
errors: [
|
|
39
43
|
{
|
|
40
|
-
message:
|
|
44
|
+
message: this.responseText,
|
|
41
45
|
},
|
|
42
46
|
],
|
|
43
47
|
});
|
|
@@ -47,10 +51,14 @@ class InvalidCredentialsException extends utils_1.Exception {
|
|
|
47
51
|
*/
|
|
48
52
|
respondWithRedirect(ctx) {
|
|
49
53
|
if (!ctx.session) {
|
|
50
|
-
return ctx.response.status(this.status).send(
|
|
54
|
+
return ctx.response.status(this.status).send(this.responseText);
|
|
51
55
|
}
|
|
52
56
|
ctx.session.flashExcept(['_csrf']);
|
|
53
57
|
ctx.session.flash('auth', {
|
|
58
|
+
error: this.responseText,
|
|
59
|
+
/**
|
|
60
|
+
* Will be removed in the future
|
|
61
|
+
*/
|
|
54
62
|
errors: {
|
|
55
63
|
uid: this.code === 'E_INVALID_AUTH_UID' ? ['Invalid login id'] : null,
|
|
56
64
|
password: this.code === 'E_INVALID_AUTH_PASSWORD' ? ['Invalid password'] : null,
|
|
@@ -66,7 +74,7 @@ class InvalidCredentialsException extends utils_1.Exception {
|
|
|
66
74
|
errors: [
|
|
67
75
|
{
|
|
68
76
|
code: this.code,
|
|
69
|
-
title:
|
|
77
|
+
title: this.responseText,
|
|
70
78
|
source: null,
|
|
71
79
|
},
|
|
72
80
|
],
|
|
@@ -77,6 +85,12 @@ class InvalidCredentialsException extends utils_1.Exception {
|
|
|
77
85
|
* upon the type of request
|
|
78
86
|
*/
|
|
79
87
|
async handle(_, ctx) {
|
|
88
|
+
/**
|
|
89
|
+
* Use translation when using i18n
|
|
90
|
+
*/
|
|
91
|
+
if ('i18n' in ctx) {
|
|
92
|
+
this.responseText = ctx.i18n.formatMessage(`auth.${this.code}`, {}, this.message);
|
|
93
|
+
}
|
|
80
94
|
if (ctx.request.ajax()) {
|
|
81
95
|
this.respondWithJson(ctx);
|
|
82
96
|
return;
|
|
@@ -113,8 +113,8 @@ class TokenDatabaseProvider {
|
|
|
113
113
|
created_at: luxon_1.DateTime.local().toFormat(client.dialect.dateTimeFormat),
|
|
114
114
|
...token.meta,
|
|
115
115
|
};
|
|
116
|
-
const [
|
|
117
|
-
return String(
|
|
116
|
+
const [row] = await client.table(this.config.table).insert(payload).returning('id');
|
|
117
|
+
return String(typeof row === 'number' ? row : row.id);
|
|
118
118
|
}
|
|
119
119
|
/**
|
|
120
120
|
* Removes a given token
|
|
@@ -11,6 +11,6 @@
|
|
|
11
11
|
|
|
|
12
12
|
*/
|
|
13
13
|
user: {
|
|
14
|
-
implementation: LucidProviderContract<typeof {{ modelName }}
|
|
15
|
-
config: LucidProviderConfig<typeof {{ modelName }}
|
|
16
|
-
}
|
|
14
|
+
implementation: LucidProviderContract<typeof {{ modelName }}>
|
|
15
|
+
config: LucidProviderConfig<typeof {{ modelName }}>
|
|
16
|
+
}
|
|
@@ -11,8 +11,8 @@ import { AuthenticationException } from '@adonisjs/auth/build/standalone'
|
|
|
11
11
|
*/
|
|
12
12
|
export default class AuthMiddleware {
|
|
13
13
|
/**
|
|
14
|
-
|
|
15
|
-
|
|
14
|
+
* The URL to redirect to when request is Unauthorized
|
|
15
|
+
*/
|
|
16
16
|
protected redirectTo = '/login'
|
|
17
17
|
|
|
18
18
|
/**
|
|
@@ -23,7 +23,7 @@ export default class AuthMiddleware {
|
|
|
23
23
|
* of the mentioned guards and that guard will be used by the rest of the code
|
|
24
24
|
* during the current request.
|
|
25
25
|
*/
|
|
26
|
-
protected async authenticate
|
|
26
|
+
protected async authenticate(auth: HttpContextContract['auth'], guards: (keyof GuardsList)[]) {
|
|
27
27
|
/**
|
|
28
28
|
* Hold reference to the guard last attempted within the for loop. We pass
|
|
29
29
|
* the reference of the guard to the "AuthenticationException", so that
|
|
@@ -60,7 +60,11 @@ export default class AuthMiddleware {
|
|
|
60
60
|
/**
|
|
61
61
|
* Handle request
|
|
62
62
|
*/
|
|
63
|
-
public async handle (
|
|
63
|
+
public async handle (
|
|
64
|
+
{ auth }: HttpContextContract,
|
|
65
|
+
next: () => Promise<void>,
|
|
66
|
+
customGuards: (keyof GuardsList)[]
|
|
67
|
+
) {
|
|
64
68
|
/**
|
|
65
69
|
* Uses the user defined guards or the default guard mentioned in
|
|
66
70
|
* the config file
|
|
@@ -10,7 +10,7 @@ export default class SilentAuthMiddleware {
|
|
|
10
10
|
/**
|
|
11
11
|
* Handle request
|
|
12
12
|
*/
|
|
13
|
-
public async handle
|
|
13
|
+
public async handle({ auth }: HttpContextContract, next: () => Promise<void>) {
|
|
14
14
|
/**
|
|
15
15
|
* Check if user is logged-in or not. If yes, then `ctx.auth.user` will be
|
|
16
16
|
* set to the instance of the currently logged in user.
|
|
@@ -3,7 +3,7 @@ import BaseSchema from '@ioc:Adonis/Lucid/Schema'
|
|
|
3
3
|
export default class {{ tokensSchemaName }} extends BaseSchema {
|
|
4
4
|
protected tableName = '{{ tokensTableName }}'
|
|
5
5
|
|
|
6
|
-
public async up
|
|
6
|
+
public async up() {
|
|
7
7
|
this.schema.createTable(this.tableName, (table) => {
|
|
8
8
|
table.increments('id').primary()
|
|
9
9
|
table.integer('user_id').unsigned().references('id').inTable('{{ usersTableName }}').onDelete('CASCADE')
|
|
@@ -19,7 +19,7 @@ export default class {{ tokensSchemaName }} extends BaseSchema {
|
|
|
19
19
|
})
|
|
20
20
|
}
|
|
21
21
|
|
|
22
|
-
public async down
|
|
22
|
+
public async down() {
|
|
23
23
|
this.schema.dropTable(this.tableName)
|
|
24
24
|
}
|
|
25
25
|
}
|
|
@@ -3,7 +3,7 @@ import BaseSchema from '@ioc:Adonis/Lucid/Schema'
|
|
|
3
3
|
export default class {{ usersSchemaName }} extends BaseSchema {
|
|
4
4
|
protected tableName = '{{ usersTableName }}'
|
|
5
5
|
|
|
6
|
-
public async up
|
|
6
|
+
public async up() {
|
|
7
7
|
this.schema.createTable(this.tableName, (table) => {
|
|
8
8
|
table.increments('id').primary()
|
|
9
9
|
table.string('email', 255).notNullable()
|
|
@@ -18,7 +18,7 @@ export default class {{ usersSchemaName }} extends BaseSchema {
|
|
|
18
18
|
})
|
|
19
19
|
}
|
|
20
20
|
|
|
21
|
-
public async down
|
|
21
|
+
public async down() {
|
|
22
22
|
this.schema.dropTable(this.tableName)
|
|
23
23
|
}
|
|
24
24
|
}
|
|
@@ -1,10 +1,6 @@
|
|
|
1
1
|
import { DateTime } from 'luxon'
|
|
2
2
|
import Hash from '@ioc:Adonis/Core/Hash'
|
|
3
|
-
import {
|
|
4
|
-
column,
|
|
5
|
-
beforeSave,
|
|
6
|
-
BaseModel,
|
|
7
|
-
} from '@ioc:Adonis/Lucid/Orm'
|
|
3
|
+
import { column, beforeSave, BaseModel } from '@ioc:Adonis/Lucid/Orm'
|
|
8
4
|
|
|
9
5
|
export default class {{ modelName }} extends BaseModel {
|
|
10
6
|
@column({ isPrimary: true })
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@adonisjs/auth",
|
|
3
|
-
"version": "8.0.
|
|
3
|
+
"version": "8.0.12",
|
|
4
4
|
"description": "Offical authentication provider for Adonis framework",
|
|
5
5
|
"types": "build/adonis-typings/index.d.ts",
|
|
6
6
|
"main": "build/providers/AuthProvider.js",
|
|
@@ -16,8 +16,8 @@
|
|
|
16
16
|
"scripts": {
|
|
17
17
|
"mrm": "mrm --preset=@adonisjs/mrm-preset",
|
|
18
18
|
"pretest": "npm run lint",
|
|
19
|
-
"test": "node
|
|
20
|
-
"clean": "del build",
|
|
19
|
+
"test": "node -r @adonisjs/require-ts/build/register ./bin/test.ts",
|
|
20
|
+
"clean": "del-cli build",
|
|
21
21
|
"copyfiles": "copyfiles \"templates/**/*.txt\" build",
|
|
22
22
|
"compile": "npm run lint && npm run clean && tsc",
|
|
23
23
|
"build": "npm run compile && npm run copyfiles",
|
|
@@ -46,37 +46,41 @@
|
|
|
46
46
|
"url": "https://github.com/adonisjs/auth/issues"
|
|
47
47
|
},
|
|
48
48
|
"devDependencies": {
|
|
49
|
-
"@adonisjs/core": "^5.
|
|
50
|
-
"@adonisjs/
|
|
51
|
-
"@adonisjs/
|
|
52
|
-
"@adonisjs/
|
|
53
|
-
"@adonisjs/
|
|
54
|
-
"@adonisjs/
|
|
55
|
-
"@adonisjs/
|
|
56
|
-
"@adonisjs/
|
|
57
|
-
"@
|
|
58
|
-
"@
|
|
49
|
+
"@adonisjs/core": "^5.5.0",
|
|
50
|
+
"@adonisjs/i18n": "^1.5.4",
|
|
51
|
+
"@adonisjs/lucid": "^17.0.0",
|
|
52
|
+
"@adonisjs/mrm-preset": "^5.0.2",
|
|
53
|
+
"@adonisjs/redis": "^7.1.1",
|
|
54
|
+
"@adonisjs/repl": "^3.1.8",
|
|
55
|
+
"@adonisjs/require-ts": "^2.0.10",
|
|
56
|
+
"@adonisjs/session": "^6.1.4",
|
|
57
|
+
"@adonisjs/sink": "^5.2.2",
|
|
58
|
+
"@japa/assert": "^1.2.3",
|
|
59
|
+
"@japa/run-failed-tests": "^1.0.3",
|
|
60
|
+
"@japa/runner": "^1.2.0",
|
|
61
|
+
"@japa/spec-reporter": "^1.1.7",
|
|
62
|
+
"@poppinss/dev-utils": "^2.0.2",
|
|
63
|
+
"@types/node": "^17.0.21",
|
|
59
64
|
"@types/supertest": "^2.0.11",
|
|
65
|
+
"@vscode/sqlite3": "^5.0.7",
|
|
60
66
|
"copyfiles": "^2.4.1",
|
|
61
67
|
"del-cli": "^4.0.1",
|
|
62
|
-
"eslint": "^
|
|
63
|
-
"eslint-config-prettier": "^8.
|
|
64
|
-
"eslint-plugin-adonis": "^1.
|
|
65
|
-
"eslint-plugin-prettier": "^
|
|
68
|
+
"eslint": "^8.10.0",
|
|
69
|
+
"eslint-config-prettier": "^8.4.0",
|
|
70
|
+
"eslint-plugin-adonis": "^2.1.0",
|
|
71
|
+
"eslint-plugin-prettier": "^4.0.0",
|
|
66
72
|
"github-label-sync": "^2.0.2",
|
|
67
|
-
"husky": "^7.0.
|
|
68
|
-
"
|
|
69
|
-
"
|
|
70
|
-
"np": "^7.5.0",
|
|
73
|
+
"husky": "^7.0.4",
|
|
74
|
+
"mrm": "^3.0.10",
|
|
75
|
+
"np": "^7.6.0",
|
|
71
76
|
"phc-bcrypt": "^1.0.7",
|
|
72
|
-
"pino-pretty": "^
|
|
73
|
-
"prettier": "^2.
|
|
77
|
+
"pino-pretty": "^7.5.1",
|
|
78
|
+
"prettier": "^2.5.1",
|
|
74
79
|
"reflect-metadata": "^0.1.13",
|
|
75
80
|
"set-cookie-parser": "^2.4.8",
|
|
76
|
-
"
|
|
77
|
-
"
|
|
78
|
-
"
|
|
79
|
-
"typescript": "^4.4.2"
|
|
81
|
+
"supertest": "^6.2.2",
|
|
82
|
+
"ts-essentials": "^9.1.2",
|
|
83
|
+
"typescript": "^4.6.2"
|
|
80
84
|
},
|
|
81
85
|
"nyc": {
|
|
82
86
|
"exclude": [
|
|
@@ -96,17 +100,21 @@
|
|
|
96
100
|
"anyBranch": false
|
|
97
101
|
},
|
|
98
102
|
"dependencies": {
|
|
99
|
-
"@poppinss/hooks": "^
|
|
100
|
-
"@poppinss/utils": "^
|
|
101
|
-
"luxon": "^2.
|
|
103
|
+
"@poppinss/hooks": "^5.0.2",
|
|
104
|
+
"@poppinss/utils": "^4.0.2",
|
|
105
|
+
"luxon": "^2.3.1"
|
|
102
106
|
},
|
|
103
107
|
"peerDependencies": {
|
|
104
108
|
"@adonisjs/core": "^5.1.1",
|
|
105
|
-
"@adonisjs/
|
|
109
|
+
"@adonisjs/i18n": "^1.3.1",
|
|
110
|
+
"@adonisjs/lucid": "^17.0.0",
|
|
106
111
|
"@adonisjs/redis": "^7.0.0",
|
|
107
112
|
"@adonisjs/session": "^6.0.0"
|
|
108
113
|
},
|
|
109
114
|
"peerDependenciesMeta": {
|
|
115
|
+
"@adonisjs/i18n": {
|
|
116
|
+
"optional": true
|
|
117
|
+
},
|
|
110
118
|
"@adonisjs/lucid": {
|
|
111
119
|
"optional": true
|
|
112
120
|
},
|