@adonisjs/auth 9.3.0 → 9.3.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-ASYBJUQZ.js → chunk-MUPAP5IP.js} +1 -2
- package/build/{chunk-R3M7VJFL.js → chunk-RKU6NS6C.js} +2 -3
- package/build/{chunk-3HZHOWKL.js → chunk-U24HGFIR.js} +0 -1
- package/build/{chunk-7AZWKBZW.js → chunk-UXA4FHST.js} +0 -1
- package/build/index.js +4 -5
- package/build/modules/access_tokens_guard/main.js +2 -3
- package/build/modules/access_tokens_guard/types.js +0 -1
- package/build/modules/basic_auth_guard/main.js +2 -3
- package/build/modules/basic_auth_guard/types.js +0 -1
- package/build/modules/session_guard/main.js +2 -3
- package/build/modules/session_guard/types.js +0 -1
- package/build/providers/auth_provider.js +4 -5
- package/build/services/auth.js +1 -2
- package/build/src/middleware/initialize_auth_middleware.js +1 -2
- package/build/src/mixins/lucid.js +2 -3
- package/build/src/plugins/japa/api_client.js +2 -3
- package/build/src/plugins/japa/browser_client.js +2 -3
- package/build/src/types.js +0 -1
- package/package.json +46 -54
- package/build/chunk-3HZHOWKL.js.map +0 -1
- package/build/chunk-7AZWKBZW.js.map +0 -1
- package/build/chunk-ASYBJUQZ.js.map +0 -1
- package/build/chunk-R3M7VJFL.js.map +0 -1
- package/build/index.js.map +0 -1
- package/build/modules/access_tokens_guard/main.js.map +0 -1
- package/build/modules/access_tokens_guard/types.js.map +0 -1
- package/build/modules/basic_auth_guard/main.js.map +0 -1
- package/build/modules/basic_auth_guard/types.js.map +0 -1
- package/build/modules/session_guard/main.js.map +0 -1
- package/build/modules/session_guard/types.js.map +0 -1
- package/build/providers/auth_provider.js.map +0 -1
- package/build/services/auth.js.map +0 -1
- package/build/src/middleware/initialize_auth_middleware.js.map +0 -1
- package/build/src/mixins/lucid.js.map +0 -1
- package/build/src/plugins/japa/api_client.js.map +0 -1
- package/build/src/plugins/japa/browser_client.js.map +0 -1
- package/build/src/types.js.map +0 -1
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import {
|
|
2
2
|
__export
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-UXA4FHST.js";
|
|
4
4
|
|
|
5
5
|
// src/errors.ts
|
|
6
6
|
var errors_exports = {};
|
|
@@ -194,4 +194,3 @@ export {
|
|
|
194
194
|
E_INVALID_CREDENTIALS,
|
|
195
195
|
errors_exports
|
|
196
196
|
};
|
|
197
|
-
//# sourceMappingURL=chunk-ASYBJUQZ.js.map
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import {
|
|
2
2
|
debug_default
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-U24HGFIR.js";
|
|
4
4
|
import {
|
|
5
5
|
E_UNAUTHORIZED_ACCESS
|
|
6
|
-
} from "./chunk-
|
|
6
|
+
} from "./chunk-MUPAP5IP.js";
|
|
7
7
|
|
|
8
8
|
// src/authenticator.ts
|
|
9
9
|
import { RuntimeException } from "@adonisjs/core/exceptions";
|
|
@@ -243,4 +243,3 @@ export {
|
|
|
243
243
|
AuthenticatorClient,
|
|
244
244
|
AuthManager
|
|
245
245
|
};
|
|
246
|
-
//# sourceMappingURL=chunk-R3M7VJFL.js.map
|
package/build/index.js
CHANGED
|
@@ -2,14 +2,14 @@ import {
|
|
|
2
2
|
AuthManager,
|
|
3
3
|
Authenticator,
|
|
4
4
|
AuthenticatorClient
|
|
5
|
-
} from "./chunk-
|
|
6
|
-
import "./chunk-
|
|
5
|
+
} from "./chunk-RKU6NS6C.js";
|
|
6
|
+
import "./chunk-U24HGFIR.js";
|
|
7
7
|
import {
|
|
8
8
|
errors_exports
|
|
9
|
-
} from "./chunk-
|
|
9
|
+
} from "./chunk-MUPAP5IP.js";
|
|
10
10
|
import {
|
|
11
11
|
__export
|
|
12
|
-
} from "./chunk-
|
|
12
|
+
} from "./chunk-UXA4FHST.js";
|
|
13
13
|
|
|
14
14
|
// configure.ts
|
|
15
15
|
import { presetAuth } from "@adonisjs/presets/auth";
|
|
@@ -107,4 +107,3 @@ export {
|
|
|
107
107
|
symbols_exports as symbols,
|
|
108
108
|
withAuthFinder
|
|
109
109
|
};
|
|
110
|
-
//# sourceMappingURL=index.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import {
|
|
2
2
|
E_UNAUTHORIZED_ACCESS
|
|
3
|
-
} from "../../chunk-
|
|
4
|
-
import "../../chunk-
|
|
3
|
+
} from "../../chunk-MUPAP5IP.js";
|
|
4
|
+
import "../../chunk-UXA4FHST.js";
|
|
5
5
|
|
|
6
6
|
// modules/access_tokens_guard/access_token.ts
|
|
7
7
|
import { createHash } from "node:crypto";
|
|
@@ -955,4 +955,3 @@ export {
|
|
|
955
955
|
tokensGuard,
|
|
956
956
|
tokensUserProvider
|
|
957
957
|
};
|
|
958
|
-
//# sourceMappingURL=main.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
//# sourceMappingURL=types.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import {
|
|
2
2
|
E_UNAUTHORIZED_ACCESS
|
|
3
|
-
} from "../../chunk-
|
|
4
|
-
import "../../chunk-
|
|
3
|
+
} from "../../chunk-MUPAP5IP.js";
|
|
4
|
+
import "../../chunk-UXA4FHST.js";
|
|
5
5
|
|
|
6
6
|
// modules/basic_auth_guard/guard.ts
|
|
7
7
|
import auth from "basic-auth";
|
|
@@ -233,4 +233,3 @@ export {
|
|
|
233
233
|
basicAuthGuard,
|
|
234
234
|
basicAuthUserProvider
|
|
235
235
|
};
|
|
236
|
-
//# sourceMappingURL=main.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
//# sourceMappingURL=types.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import {
|
|
2
2
|
E_UNAUTHORIZED_ACCESS
|
|
3
|
-
} from "../../chunk-
|
|
4
|
-
import "../../chunk-
|
|
3
|
+
} from "../../chunk-MUPAP5IP.js";
|
|
4
|
+
import "../../chunk-UXA4FHST.js";
|
|
5
5
|
|
|
6
6
|
// modules/session_guard/remember_me_token.ts
|
|
7
7
|
import { createHash } from "node:crypto";
|
|
@@ -751,4 +751,3 @@ export {
|
|
|
751
751
|
sessionGuard,
|
|
752
752
|
sessionUserProvider
|
|
753
753
|
};
|
|
754
|
-
//# sourceMappingURL=main.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
//# sourceMappingURL=types.js.map
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import {
|
|
2
2
|
AuthManager
|
|
3
|
-
} from "../chunk-
|
|
4
|
-
import "../chunk-
|
|
5
|
-
import "../chunk-
|
|
6
|
-
import "../chunk-
|
|
3
|
+
} from "../chunk-RKU6NS6C.js";
|
|
4
|
+
import "../chunk-U24HGFIR.js";
|
|
5
|
+
import "../chunk-MUPAP5IP.js";
|
|
6
|
+
import "../chunk-UXA4FHST.js";
|
|
7
7
|
|
|
8
8
|
// providers/auth_provider.ts
|
|
9
9
|
import { configProvider } from "@adonisjs/core";
|
|
@@ -28,4 +28,3 @@ var AuthProvider = class {
|
|
|
28
28
|
export {
|
|
29
29
|
AuthProvider as default
|
|
30
30
|
};
|
|
31
|
-
//# sourceMappingURL=auth_provider.js.map
|
package/build/services/auth.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import "../../chunk-
|
|
1
|
+
import "../../chunk-UXA4FHST.js";
|
|
2
2
|
|
|
3
3
|
// src/middleware/initialize_auth_middleware.ts
|
|
4
4
|
var InitializeAuthMiddleware = class {
|
|
@@ -14,4 +14,3 @@ var InitializeAuthMiddleware = class {
|
|
|
14
14
|
export {
|
|
15
15
|
InitializeAuthMiddleware as default
|
|
16
16
|
};
|
|
17
|
-
//# sourceMappingURL=initialize_auth_middleware.js.map
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import {
|
|
2
2
|
E_INVALID_CREDENTIALS
|
|
3
|
-
} from "../../chunk-
|
|
3
|
+
} from "../../chunk-MUPAP5IP.js";
|
|
4
4
|
import {
|
|
5
5
|
__decorateClass
|
|
6
|
-
} from "../../chunk-
|
|
6
|
+
} from "../../chunk-UXA4FHST.js";
|
|
7
7
|
|
|
8
8
|
// src/mixins/lucid.ts
|
|
9
9
|
import { RuntimeException } from "@adonisjs/core/exceptions";
|
|
@@ -70,4 +70,3 @@ function withAuthFinder(hash, options) {
|
|
|
70
70
|
export {
|
|
71
71
|
withAuthFinder
|
|
72
72
|
};
|
|
73
|
-
//# sourceMappingURL=lucid.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import {
|
|
2
2
|
debug_default
|
|
3
|
-
} from "../../../chunk-
|
|
4
|
-
import "../../../chunk-
|
|
3
|
+
} from "../../../chunk-U24HGFIR.js";
|
|
4
|
+
import "../../../chunk-UXA4FHST.js";
|
|
5
5
|
|
|
6
6
|
// src/plugins/japa/api_client.ts
|
|
7
7
|
import { ApiClient, ApiRequest } from "@japa/api-client";
|
|
@@ -56,4 +56,3 @@ var authApiClient = (app) => {
|
|
|
56
56
|
export {
|
|
57
57
|
authApiClient
|
|
58
58
|
};
|
|
59
|
-
//# sourceMappingURL=api_client.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import {
|
|
2
2
|
debug_default
|
|
3
|
-
} from "../../../chunk-
|
|
4
|
-
import "../../../chunk-
|
|
3
|
+
} from "../../../chunk-U24HGFIR.js";
|
|
4
|
+
import "../../../chunk-UXA4FHST.js";
|
|
5
5
|
|
|
6
6
|
// src/plugins/japa/browser_client.ts
|
|
7
7
|
import { decoratorsCollection } from "@japa/browser-client";
|
|
@@ -64,4 +64,3 @@ var authBrowserClient = (app) => {
|
|
|
64
64
|
export {
|
|
65
65
|
authBrowserClient
|
|
66
66
|
};
|
|
67
|
-
//# sourceMappingURL=browser_client.js.map
|
package/build/src/types.js
CHANGED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
//# sourceMappingURL=types.js.map
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@adonisjs/auth",
|
|
3
3
|
"description": "Official authentication provider for Adonis framework",
|
|
4
|
-
"version": "9.3.
|
|
4
|
+
"version": "9.3.1",
|
|
5
5
|
"engines": {
|
|
6
6
|
"node": ">=18.16.0"
|
|
7
7
|
},
|
|
@@ -36,43 +36,43 @@
|
|
|
36
36
|
"test:mysql": "cross-env DB=mysql npm run quick:test",
|
|
37
37
|
"test:mssql": "cross-env DB=mssql npm run quick:test",
|
|
38
38
|
"test:pg": "cross-env DB=pg npm run quick:test",
|
|
39
|
-
"
|
|
39
|
+
"lint": "eslint .",
|
|
40
|
+
"format": "prettier --write .",
|
|
40
41
|
"typecheck": "tsc --noEmit",
|
|
42
|
+
"clean": "del-cli build",
|
|
41
43
|
"copy:templates": "copyfiles \"stubs/**/*.stub\" --up=\"1\" build",
|
|
42
44
|
"precompile": "npm run lint && npm run clean",
|
|
43
45
|
"compile": "tsup-node && tsc --emitDeclarationOnly --declaration",
|
|
44
46
|
"postcompile": "npm run copy:templates",
|
|
45
47
|
"build": "npm run compile",
|
|
46
48
|
"prepublishOnly": "npm run build",
|
|
47
|
-
"lint": "eslint .",
|
|
48
|
-
"format": "prettier --write .",
|
|
49
49
|
"release": "release-it",
|
|
50
50
|
"version": "npm run build",
|
|
51
51
|
"quick:test": "cross-env NODE_DEBUG=\"adonisjs:auth:*\" node --enable-source-maps --import=ts-node-maintained/register/esm ./bin/test.js"
|
|
52
52
|
},
|
|
53
53
|
"devDependencies": {
|
|
54
54
|
"@adonisjs/assembler": "^7.8.2",
|
|
55
|
-
"@adonisjs/core": "^6.17.
|
|
55
|
+
"@adonisjs/core": "^6.17.1",
|
|
56
56
|
"@adonisjs/eslint-config": "^2.0.0-beta.7",
|
|
57
57
|
"@adonisjs/hash": "^9.0.5",
|
|
58
58
|
"@adonisjs/i18n": "^2.2.0",
|
|
59
|
-
"@adonisjs/lucid": "^21.
|
|
59
|
+
"@adonisjs/lucid": "^21.6.0",
|
|
60
60
|
"@adonisjs/prettier-config": "^1.4.0",
|
|
61
|
-
"@adonisjs/session": "^7.5.
|
|
61
|
+
"@adonisjs/session": "^7.5.1",
|
|
62
62
|
"@adonisjs/tsconfig": "^1.4.0",
|
|
63
|
-
"@japa/api-client": "^
|
|
64
|
-
"@japa/assert": "^
|
|
65
|
-
"@japa/browser-client": "^2.
|
|
66
|
-
"@japa/expect-type": "^2.0.
|
|
67
|
-
"@japa/file-system": "^2.3.
|
|
68
|
-
"@japa/plugin-adonisjs": "^
|
|
69
|
-
"@japa/runner": "^
|
|
70
|
-
"@japa/snapshot": "^2.0.
|
|
71
|
-
"@release-it/conventional-changelog": "^
|
|
72
|
-
"@swc/core": "^1.10.
|
|
63
|
+
"@japa/api-client": "^3.0.3",
|
|
64
|
+
"@japa/assert": "^4.0.1",
|
|
65
|
+
"@japa/browser-client": "^2.1.1",
|
|
66
|
+
"@japa/expect-type": "^2.0.3",
|
|
67
|
+
"@japa/file-system": "^2.3.2",
|
|
68
|
+
"@japa/plugin-adonisjs": "^4.0.0",
|
|
69
|
+
"@japa/runner": "^4.1.0",
|
|
70
|
+
"@japa/snapshot": "^2.0.8",
|
|
71
|
+
"@release-it/conventional-changelog": "^10.0.0",
|
|
72
|
+
"@swc/core": "^1.10.7",
|
|
73
73
|
"@types/basic-auth": "^1.1.8",
|
|
74
74
|
"@types/luxon": "^3.4.2",
|
|
75
|
-
"@types/node": "^22.10.
|
|
75
|
+
"@types/node": "^22.10.7",
|
|
76
76
|
"@types/set-cookie-parser": "^2.4.10",
|
|
77
77
|
"@types/sinon": "^17.0.3",
|
|
78
78
|
"c8": "^10.1.3",
|
|
@@ -81,14 +81,14 @@
|
|
|
81
81
|
"cross-env": "^7.0.3",
|
|
82
82
|
"del-cli": "^6.0.0",
|
|
83
83
|
"dotenv": "^16.4.7",
|
|
84
|
-
"eslint": "^9.
|
|
84
|
+
"eslint": "^9.18.0",
|
|
85
85
|
"luxon": "^3.5.0",
|
|
86
|
-
"mysql2": "^3.
|
|
86
|
+
"mysql2": "^3.12.0",
|
|
87
87
|
"nock": "^13.5.6",
|
|
88
88
|
"pg": "^8.13.1",
|
|
89
89
|
"playwright": "^1.49.1",
|
|
90
90
|
"prettier": "^3.4.2",
|
|
91
|
-
"release-it": "^
|
|
91
|
+
"release-it": "^18.1.1",
|
|
92
92
|
"set-cookie-parser": "^2.7.1",
|
|
93
93
|
"sinon": "^19.0.2",
|
|
94
94
|
"sqlite3": "^5.1.7",
|
|
@@ -96,20 +96,20 @@
|
|
|
96
96
|
"timekeeper": "^2.3.1",
|
|
97
97
|
"ts-node-maintained": "^10.9.4",
|
|
98
98
|
"tsup": "^8.3.5",
|
|
99
|
-
"typescript": "^5.7.
|
|
99
|
+
"typescript": "^5.7.3"
|
|
100
100
|
},
|
|
101
101
|
"dependencies": {
|
|
102
|
-
"@adonisjs/presets": "^2.6.
|
|
103
|
-
"@poppinss/utils": "^6.
|
|
102
|
+
"@adonisjs/presets": "^2.6.4",
|
|
103
|
+
"@poppinss/utils": "^6.9.2",
|
|
104
104
|
"basic-auth": "^2.0.1"
|
|
105
105
|
},
|
|
106
106
|
"peerDependencies": {
|
|
107
107
|
"@adonisjs/core": "^6.11.0",
|
|
108
108
|
"@adonisjs/lucid": "^20.0.0 || ^21.0.1",
|
|
109
109
|
"@adonisjs/session": "^7.4.1",
|
|
110
|
-
"@japa/api-client": "^2.0.3",
|
|
110
|
+
"@japa/api-client": "^2.0.3 || ^3.0.0",
|
|
111
111
|
"@japa/browser-client": "^2.0.3",
|
|
112
|
-
"@japa/plugin-adonisjs": "^3.0.1"
|
|
112
|
+
"@japa/plugin-adonisjs": "^3.0.1 || ^4.0.0"
|
|
113
113
|
},
|
|
114
114
|
"peerDependenciesMeta": {
|
|
115
115
|
"@adonisjs/lucid": {
|
|
@@ -128,11 +128,6 @@
|
|
|
128
128
|
"optional": true
|
|
129
129
|
}
|
|
130
130
|
},
|
|
131
|
-
"author": "Harminder Virk <virk@adonisjs.com>",
|
|
132
|
-
"contributors": [
|
|
133
|
-
"Romain Lanz <romain.lanz@pm.me>"
|
|
134
|
-
],
|
|
135
|
-
"license": "MIT",
|
|
136
131
|
"homepage": "https://github.com/adonisjs/auth#readme",
|
|
137
132
|
"repository": {
|
|
138
133
|
"type": "git",
|
|
@@ -146,18 +141,14 @@
|
|
|
146
141
|
"authentication",
|
|
147
142
|
"auth"
|
|
148
143
|
],
|
|
149
|
-
"
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
"
|
|
154
|
-
"extends": [
|
|
155
|
-
"@commitlint/config-conventional"
|
|
156
|
-
]
|
|
157
|
-
},
|
|
144
|
+
"author": "Harminder Virk <virk@adonisjs.com>",
|
|
145
|
+
"contributors": [
|
|
146
|
+
"Romain Lanz <romain.lanz@pm.me>"
|
|
147
|
+
],
|
|
148
|
+
"license": "MIT",
|
|
158
149
|
"publishConfig": {
|
|
159
150
|
"access": "public",
|
|
160
|
-
"
|
|
151
|
+
"provenance": true
|
|
161
152
|
},
|
|
162
153
|
"release-it": {
|
|
163
154
|
"git": {
|
|
@@ -183,17 +174,6 @@
|
|
|
183
174
|
}
|
|
184
175
|
}
|
|
185
176
|
},
|
|
186
|
-
"c8": {
|
|
187
|
-
"reporter": [
|
|
188
|
-
"text",
|
|
189
|
-
"html"
|
|
190
|
-
],
|
|
191
|
-
"exclude": [
|
|
192
|
-
"tests/**",
|
|
193
|
-
"backup/**",
|
|
194
|
-
"factories/**"
|
|
195
|
-
]
|
|
196
|
-
},
|
|
197
177
|
"tsup": {
|
|
198
178
|
"entry": [
|
|
199
179
|
"./index.ts",
|
|
@@ -215,7 +195,19 @@
|
|
|
215
195
|
"clean": true,
|
|
216
196
|
"format": "esm",
|
|
217
197
|
"dts": false,
|
|
218
|
-
"sourcemap":
|
|
198
|
+
"sourcemap": false,
|
|
219
199
|
"target": "esnext"
|
|
220
|
-
}
|
|
200
|
+
},
|
|
201
|
+
"c8": {
|
|
202
|
+
"reporter": [
|
|
203
|
+
"text",
|
|
204
|
+
"html"
|
|
205
|
+
],
|
|
206
|
+
"exclude": [
|
|
207
|
+
"tests/**",
|
|
208
|
+
"backup/**",
|
|
209
|
+
"factories/**"
|
|
210
|
+
]
|
|
211
|
+
},
|
|
212
|
+
"prettier": "@adonisjs/prettier-config"
|
|
221
213
|
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/debug.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 { debuglog } from 'node:util'\n\nexport default debuglog('adonisjs:auth')\n"],"mappings":";AASA,SAAS,gBAAgB;AAEzB,IAAO,gBAAQ,SAAS,eAAe;","names":[]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/errors.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 { I18n } from '@adonisjs/i18n'\nimport { Exception } from '@adonisjs/core/exceptions'\nimport type { HttpContext } from '@adonisjs/core/http'\n\n/**\n * The \"E_UNAUTHORIZED_ACCESS\" exception is raised when unable to\n * authenticate an incoming HTTP request.\n *\n * The \"error.guardDriverName\" can be used to know the driver which\n * raised the error.\n */\nexport const E_UNAUTHORIZED_ACCESS = class extends Exception {\n static status: number = 401\n static code: string = 'E_UNAUTHORIZED_ACCESS'\n\n /**\n * Endpoint to redirect to. Only used by \"session\" driver\n * renderer\n */\n redirectTo?: string\n\n /**\n * Translation identifier. Can be customized\n */\n identifier: string = 'errors.E_UNAUTHORIZED_ACCESS'\n\n /**\n * The guard name reference that raised the exception. It allows\n * us to customize the logic of handling the exception.\n */\n guardDriverName: string\n\n /**\n * A collection of renderers to render the exception to a\n * response.\n *\n * The collection is a key-value pair, where the key is\n * the guard driver name and value is a factory function\n * to respond to the request.\n */\n renderers: Record<\n string,\n (message: string, error: this, ctx: HttpContext) => Promise<void> | void\n > = {\n /**\n * Response when session driver is used\n */\n session: (message, error, ctx) => {\n switch (ctx.request.accepts(['html', 'application/vnd.api+json', 'json'])) {\n case 'html':\n case null:\n ctx.session.flashExcept(['_csrf'])\n ctx.session.flashErrors({ [error.code!]: message })\n ctx.response.redirect(error.redirectTo || '/', true)\n break\n case 'json':\n ctx.response.status(error.status).send({\n errors: [\n {\n message,\n },\n ],\n })\n break\n case 'application/vnd.api+json':\n ctx.response.status(error.status).send({\n errors: [\n {\n code: error.code,\n title: message,\n },\n ],\n })\n break\n }\n },\n\n /**\n * Response when basic auth driver is used\n */\n basic_auth: (message, _, ctx) => {\n ctx.response\n .status(this.status)\n .header('WWW-Authenticate', `Basic realm=\"Authenticate\", charset=\"UTF-8\"`)\n .send(message)\n },\n\n /**\n * Response when access tokens driver is used\n */\n access_tokens: (message, error, ctx) => {\n switch (ctx.request.accepts(['html', 'application/vnd.api+json', 'json'])) {\n case 'html':\n case null:\n ctx.response.status(error.status).send(message)\n break\n case 'json':\n ctx.response.status(error.status).send({\n errors: [\n {\n message,\n },\n ],\n })\n break\n case 'application/vnd.api+json':\n ctx.response.status(error.status).send({\n errors: [\n {\n code: error.code,\n title: message,\n },\n ],\n })\n break\n }\n },\n }\n\n /**\n * Returns the message to be sent in the HTTP response.\n * Feel free to override this method and return a custom\n * response.\n */\n getResponseMessage(error: this, ctx: HttpContext) {\n if ('i18n' in ctx) {\n return (ctx.i18n as I18n).t(error.identifier, {}, error.message)\n }\n return error.message\n }\n\n constructor(\n message: string,\n options: {\n redirectTo?: string\n guardDriverName: string\n }\n ) {\n super(message, {})\n this.guardDriverName = options.guardDriverName\n this.redirectTo = options.redirectTo\n }\n\n /**\n * Converts exception to an HTTP response\n */\n async handle(error: this, ctx: HttpContext) {\n const renderer = this.renderers[this.guardDriverName]\n const message = error.getResponseMessage(error, ctx)\n\n if (!renderer) {\n return ctx.response.status(error.status).send(message)\n }\n\n return renderer(message, error, ctx)\n }\n}\n\n/**\n * Exception is raised when user credentials are invalid\n */\nexport const E_INVALID_CREDENTIALS = class extends Exception {\n static status: number = 400\n static code: string = 'E_INVALID_CREDENTIALS'\n\n /**\n * Translation identifier. Can be customized\n */\n identifier: string = 'errors.E_INVALID_CREDENTIALS'\n\n /**\n * Returns the message to be sent in the HTTP response.\n * Feel free to override this method and return a custom\n * response.\n */\n getResponseMessage(error: this, ctx: HttpContext) {\n if ('i18n' in ctx) {\n return (ctx.i18n as I18n).t(error.identifier, {}, error.message)\n }\n return error.message\n }\n\n /**\n * Converts exception to an HTTP response\n */\n async handle(error: this, ctx: HttpContext) {\n const message = this.getResponseMessage(error, ctx)\n\n switch (ctx.request.accepts(['html', 'application/vnd.api+json', 'json'])) {\n case 'html':\n case null:\n if (ctx.session) {\n ctx.session.flashExcept(['_csrf', '_method', 'password', 'password_confirmation'])\n ctx.session.flashErrors({ [error.code!]: message })\n ctx.response.redirect('back', true)\n } else {\n ctx.response.status(error.status).send(message)\n }\n break\n case 'json':\n ctx.response.status(error.status).send({\n errors: [\n {\n message,\n },\n ],\n })\n break\n case 'application/vnd.api+json':\n ctx.response.status(error.status).send({\n errors: [\n {\n code: error.code,\n title: message,\n },\n ],\n })\n break\n }\n }\n}\n"],"mappings":";;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAUA,SAAS,iBAAiB;AAUnB,IAAM,wBAAwB,cAAc,UAAU;AAAA,EAC3D,OAAO,SAAiB;AAAA,EACxB,OAAO,OAAe;AAAA;AAAA;AAAA;AAAA;AAAA,EAMtB;AAAA;AAAA;AAAA;AAAA,EAKA,aAAqB;AAAA;AAAA;AAAA;AAAA;AAAA,EAMrB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAUA,YAGI;AAAA;AAAA;AAAA;AAAA,IAIF,SAAS,CAAC,SAAS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,4BAA4B,MAAM,CAAC,GAAG;AAAA,MACzE,KAAK;AAAA,MACL,KAAK;AACH,YAAI,IAAI,SAAS;AACf,cAAI,QAAQ,YAAY,CAAC,SAAS,WAAW,YAAY,uBAAuB,CAAC;AACjF,cAAI,QAAQ,YAAY,EAAE,CAAC,MAAM,IAAK,GAAG,QAAQ,CAAC;AAClD,cAAI,SAAS,SAAS,QAAQ,IAAI;AAAA,QACpC,OAAO;AACL,cAAI,SAAS,OAAO,MAAM,MAAM,EAAE,KAAK,OAAO;AAAA,QAChD;AACA;AAAA,MACF,KAAK;AACH,YAAI,SAAS,OAAO,MAAM,MAAM,EAAE,KAAK;AAAA,UACrC,QAAQ;AAAA,YACN;AAAA,cACE;AAAA,YACF;AAAA,UACF;AAAA,QACF,CAAC;AACD;AAAA,MACF,KAAK;AACH,YAAI,SAAS,OAAO,MAAM,MAAM,EAAE,KAAK;AAAA,UACrC,QAAQ;AAAA,YACN;AAAA,cACE,MAAM,MAAM;AAAA,cACZ,OAAO;AAAA,YACT;AAAA,UACF;AAAA,QACF,CAAC;AACD;AAAA,IACJ;AAAA,EACF;AACF;","names":[]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/authenticator.ts","../src/authenticator_client.ts","../src/auth_manager.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 { HttpContext } from '@adonisjs/core/http'\nimport { RuntimeException } from '@adonisjs/core/exceptions'\n\nimport debug from './debug.js'\nimport type { GuardFactory } from './types.js'\nimport { E_UNAUTHORIZED_ACCESS } from './errors.js'\n\n/**\n * Authenticator is used to authenticate incoming HTTP requests\n * using one or more known guards.\n */\nexport class Authenticator<KnownGuards extends Record<string, GuardFactory>> {\n /**\n * Registered guards\n */\n #config: {\n default: keyof KnownGuards\n guards: KnownGuards\n }\n\n /**\n * Cache of guards created during the HTTP request\n */\n #guardsCache: Partial<Record<keyof KnownGuards, unknown>> = {}\n\n /**\n * Last guard that was used to perform the authentication via\n * the \"authenticateUsing\" method.\n *\n * @note\n * Reset on every call made to \"authenticate\", \"check\" and\n * \"authenticateUsing\" method.\n */\n #authenticationAttemptedViaGuard?: keyof KnownGuards\n\n /**\n * Name of the guard using which the request has\n * been authenticated successfully.\n *\n * @note\n * Reset on every call made to \"authenticate\", \"check\" and\n * \"authenticateUsing\" method.\n */\n #authenticatedViaGuard?: keyof KnownGuards\n\n /**\n * Reference to HTTP context\n */\n #ctx: HttpContext\n\n /**\n * Name of the default guard\n */\n get defaultGuard(): keyof KnownGuards {\n return this.#config.default\n }\n\n /**\n * Reference to the guard using which the current\n * request has been authenticated.\n */\n get authenticatedViaGuard(): keyof KnownGuards | undefined {\n return this.#authenticatedViaGuard\n }\n\n /**\n * A boolean to know if the current request has been authenticated. The\n * property returns false when \"authenticate\" or \"authenticateUsing\"\n * methods are not used.\n */\n get isAuthenticated(): boolean {\n if (!this.#authenticationAttemptedViaGuard) {\n return false\n }\n\n return this.use(this.#authenticationAttemptedViaGuard).isAuthenticated\n }\n\n /**\n * Reference to the currently authenticated user. The property returns\n * undefined when \"authenticate\" or \"authenticateUsing\" methods are\n * not used.\n */\n get user(): {\n [K in keyof KnownGuards]: ReturnType<KnownGuards[K]>['user']\n }[keyof KnownGuards] {\n if (!this.#authenticationAttemptedViaGuard) {\n return undefined\n }\n\n return this.use(this.#authenticationAttemptedViaGuard).user\n }\n\n /**\n * Whether or not the authentication has been attempted during\n * the current request. The property returns false when the\n * \"authenticate\" or \"authenticateUsing\" methods are not\n * used.\n */\n get authenticationAttempted(): boolean {\n if (!this.#authenticationAttemptedViaGuard) {\n return false\n }\n\n return this.use(this.#authenticationAttemptedViaGuard).authenticationAttempted\n }\n\n constructor(ctx: HttpContext, config: { default: keyof KnownGuards; guards: KnownGuards }) {\n this.#ctx = ctx\n this.#config = config\n debug('creating authenticator. config %O', this.#config)\n }\n\n /**\n * Returns an instance of the logged-in user or throws an\n * exception\n */\n getUserOrFail(): {\n [K in keyof KnownGuards]: ReturnType<ReturnType<KnownGuards[K]>['getUserOrFail']>\n }[keyof KnownGuards] {\n if (!this.#authenticationAttemptedViaGuard) {\n throw new RuntimeException(\n 'Cannot access authenticated user. Please call \"auth.authenticate\" method first.'\n )\n }\n\n return this.use(this.#authenticationAttemptedViaGuard).getUserOrFail() as {\n [K in keyof KnownGuards]: ReturnType<ReturnType<KnownGuards[K]>['getUserOrFail']>\n }[keyof KnownGuards]\n }\n\n /**\n * Returns an instance of a known guard. Guards instances are\n * cached during the lifecycle of an HTTP request.\n */\n use<Guard extends keyof KnownGuards>(guard?: Guard): ReturnType<KnownGuards[Guard]> {\n const guardToUse = guard || this.#config.default\n\n /**\n * Use cached copy if exists\n */\n const cachedGuard = this.#guardsCache[guardToUse]\n if (cachedGuard) {\n debug('authenticator: using guard from cache. name: \"%s\"', guardToUse)\n return cachedGuard as ReturnType<KnownGuards[Guard]>\n }\n\n const guardFactory = this.#config.guards[guardToUse]\n\n /**\n * Construct guard and cache it\n */\n debug('authenticator: creating guard. name: \"%s\"', guardToUse)\n const guardInstance = guardFactory(this.#ctx)\n this.#guardsCache[guardToUse] = guardInstance\n\n return guardInstance as ReturnType<KnownGuards[Guard]>\n }\n\n /**\n * Authenticate current request using the default guard. Calling this\n * method multiple times triggers multiple authentication with the\n * guard.\n */\n async authenticate() {\n await this.authenticateUsing()\n return this.getUserOrFail()\n }\n\n /**\n * Silently attempt to authenticate the request using the default\n * guard. Calling this method multiple times triggers multiple\n * authentication with the guard.\n */\n async check() {\n this.#authenticationAttemptedViaGuard = this.defaultGuard\n const isAuthenticated = await this.use().check()\n if (isAuthenticated) {\n this.#authenticatedViaGuard = this.defaultGuard\n }\n\n return isAuthenticated\n }\n\n /**\n * Authenticate the request using all of the mentioned guards\n * or the default guard.\n *\n * The authentication process will stop after any of the mentioned\n * guards is able to authenticate the request successfully.\n *\n * Otherwise, \"E_UNAUTHORIZED_ACCESS\" will be raised.\n */\n async authenticateUsing(\n guards?: (keyof KnownGuards)[],\n options?: { loginRoute?: string }\n ): Promise<\n {\n [K in keyof KnownGuards]: ReturnType<ReturnType<KnownGuards[K]>['getUserOrFail']>\n }[keyof KnownGuards]\n > {\n const guardsToUse = guards || [this.defaultGuard]\n let lastUsedDriver: string | undefined\n\n for (let guardName of guardsToUse) {\n debug('attempting to authenticate using guard \"%s\"', guardName)\n\n this.#authenticationAttemptedViaGuard = guardName\n const guard = this.use(guardName)\n lastUsedDriver = guard.driverName\n\n if (await guard.check()) {\n this.#authenticatedViaGuard = guardName\n return this.getUserOrFail()\n }\n }\n\n throw new E_UNAUTHORIZED_ACCESS('Unauthorized access', {\n guardDriverName: lastUsedDriver!,\n redirectTo: options?.loginRoute,\n })\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\nimport debug from './debug.js'\nimport type { GuardFactory } from './types.js'\nimport { HttpContextFactory } from '@adonisjs/core/factories/http'\n\n/**\n * Authenticator client is used to create guard instances for testing.\n * It passes a fake HTTPContext to the guards, so make sure to not\n * call server side APIs that might be relying on a real\n * HTTPContext instance.\n */\nexport class AuthenticatorClient<KnownGuards extends Record<string, GuardFactory>> {\n /**\n * Registered guards\n */\n #config: {\n default: keyof KnownGuards\n guards: KnownGuards\n }\n\n /**\n * Cache of guards\n */\n #guardsCache: Partial<Record<keyof KnownGuards, unknown>> = {}\n\n /**\n * Name of the default guard\n */\n get defaultGuard(): keyof KnownGuards {\n return this.#config.default\n }\n\n constructor(config: { default: keyof KnownGuards; guards: KnownGuards }) {\n this.#config = config\n debug('creating authenticator client. config %O', this.#config)\n }\n\n /**\n * Returns an instance of a known guard. Guards instances are\n * cached during the lifecycle of an HTTP request.\n */\n use<Guard extends keyof KnownGuards>(guard?: Guard): ReturnType<KnownGuards[Guard]> {\n const guardToUse = guard || this.#config.default\n\n /**\n * Use cached copy if exists\n */\n const cachedGuard = this.#guardsCache[guardToUse]\n if (cachedGuard) {\n debug('authenticator client: using guard from cache. name: \"%s\"', guardToUse)\n return cachedGuard as ReturnType<KnownGuards[Guard]>\n }\n\n const guardFactory = this.#config.guards[guardToUse]\n\n /**\n * Construct guard and cache it\n */\n debug('authenticator client: creating guard. name: \"%s\"', guardToUse)\n const guardInstance = guardFactory(new HttpContextFactory().create())\n this.#guardsCache[guardToUse] = guardInstance\n\n return guardInstance as ReturnType<KnownGuards[Guard]>\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\nimport type { HttpContext } from '@adonisjs/core/http'\n\nimport type { GuardFactory } from './types.js'\nimport { Authenticator } from './authenticator.js'\nimport { AuthenticatorClient } from './authenticator_client.js'\n\n/**\n * Auth manager exposes the API to register and manage authentication\n * guards from the config\n */\nexport class AuthManager<KnownGuards extends Record<string, GuardFactory>> {\n /**\n * Name of the default guard\n */\n get defaultGuard() {\n return this.config.default\n }\n\n constructor(public config: { default: keyof KnownGuards; guards: KnownGuards }) {\n this.config = config\n }\n\n /**\n * Create an authenticator for a given HTTP request. The authenticator\n * is used to authenticated in incoming HTTP request\n */\n createAuthenticator(ctx: HttpContext) {\n return new Authenticator<KnownGuards>(ctx, this.config)\n }\n\n /**\n * Creates an instance of the authenticator client. The client is\n * used to setup authentication state during testing.\n */\n createAuthenticatorClient() {\n return new AuthenticatorClient<KnownGuards>(this.config)\n }\n}\n"],"mappings":";;;;;;;;AAUA,SAAS,wBAAwB;AAU1B,IAAM,gBAAN,MAAsE;AAAA;AAAA;AAAA;AAAA,EAI3E;AAAA;AAAA;AAAA;AAAA,EAQA,eAA4D,CAAC;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAU7D;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAUA;AAAA;AAAA;AAAA;AAAA,EAKA;AAAA;A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AA;AAAA;AAAA;AAAA;AAAA,EAMA,IAAqC,OAA+C;AAClF,UAAM,aAAa,SAAS,KAAK,QAAQ;AAKzC,UAAM,cAAc,KAAK,aAAa,UAAU;AAChD,QAAI,aAAa;AACf,oBAAM,4DAA4D,UAAU;AAC5E,aAAO;AAAA,IACT;AAEA,UAAM,eAAe,KAAK,QAAQ,OAAO,UAAU;AAKnD,kBAAM,oDAAoD,UAAU;AACpE,UAAM,gBAAgB,aAAa,IAAI,mBAAmB,EAAE,OAAO,CAAC;AACpE,SAAK,aAAa,UAAU,IAAI;AAEhC,WAAO;AAAA,EACT;AACF;;;ACrDO,IAAM,cAAN,MAAoE;AAAA,EAQzE,YAAmB,QAA6D;AAA7D;AACjB,SAAK,SAAS;AAAA,EAChB;AAAA;AAAA;AAAA;AAAA,EANA,IAAI,eAAe;AACjB,WAAO,KAAK,OAAO;AAAA,EACrB;AAAA;AAAA;AAAA;AAAA;AAAA,EAUA,oBAAoB,KAAkB;AACpC,WAAO,IAAI,cAA2B,KAAK,KAAK,MAAM;AAAA,EACxD;AAAA;AAAA;AAAA;AAAA;AAAA,EAMA,4BAA4B;AAC1B,WAAO,IAAI,oBAAiC,KAAK,MAAM;AAAA,EACzD;AACF;","names":[]}
|
package/build/index.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
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;AAA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 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../modules/access_tokens_guard/access_token.ts","../../../modules/access_tokens_guard/crc32.ts","../../../modules/access_tokens_guard/guard.ts","../../../modules/access_tokens_guard/token_providers/db.ts","../../../modules/access_tokens_guard/user_providers/lucid.ts","../../../modules/access_tokens_guard/define_config.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 { createHash } from 'node:crypto'\nimport string from '@adonisjs/core/helpers/string'\nimport { RuntimeException } from '@adonisjs/core/exceptions'\nimport { Secret, base64, safeEqual } from '@adonisjs/core/helpers'\n\nimport { CRC32 } from './crc32.js'\nimport { E_UNAUTHORIZED_ACCESS } from '../../src/errors.js'\n\n/**\n * Access token represents a token created for a user to authenticate\n * using the auth module.\n *\n * It encapsulates the logic of creating an opaque token, generating\n * its hash and verifying its hash.\n */\nexport class AccessToken {\n /**\n * Decodes a publicly shared token and return the series\n * and the token value from it.\n *\n * Returns null when unable to decode the token because of\n * invalid format or encoding.\n */\n static decode(\n prefix: string,\n value: string\n ): null | { identifier: string; secret: Secret<string> } {\n /**\n * Ensure value is a string and starts with the prefix.\n */\n if (typeof value !== 'string' || !value.startsWith(`${prefix}`)) {\n return null\n }\n\n /**\n * Remove prefix from the rest of the token.\n */\n const token = value.replace(new RegExp(`^${prefix}`), '')\n if (!token) {\n return null\n }\n\n const [identifier, ...tokenValue] = token.split('.')\n if (!identifier || tokenValue.length === 0) {\n return null\n }\n\n const decodedIdentifier = base64.urlDecode(identifier)\n const decodedSecret = base64.urlDecode(tokenValue.join('.'))\n if (!decodedIdentifier || !decodedSecret) {\n return null\n }\n\n return {\n identifier: decodedIdentifier,\n secret: new Secret(decodedSecret),\n }\n }\n\n /**\n * Creates a transient token that can be shared with the persistence\n * layer.\n */\n static createTransientToken(\n userId: string | number | BigInt,\n size: number,\n expiresIn?: string | number\n ) {\n let expiresAt: Date | undefined\n if (expiresIn) {\n expiresAt = new Date()\n expiresAt.setSeconds(expiresAt.getSeconds() + string.seconds.parse(expiresIn))\n }\n\n return {\n userId,\n expiresAt,\n ...this.seed(size),\n }\n }\n\n /**\n * Creates a secret opaque token and its hash. The secret is\n * suffixed with a crc32 checksum for secret scanning tools\n * to easily identify the token.\n */\n static seed(size: number) {\n const seed = string.random(size)\n const secret = new Secret(`${seed}${new CRC32().calculate(seed)}`)\n const hash = createHash('sha256').update(secret.release()).digest('hex')\n return { secret, hash }\n }\n\n /**\n * Identifer is a unique sequence to identify the\n * token within database. It should be the\n * primary/unique key\n */\n identifier: string | number | BigInt\n\n /**\n * Reference to the user id for whom the token\n * is generated.\n */\n tokenableId: string | number | BigInt\n\n /**\n * The value is a public representation of a token. It is created\n * by combining the \"identifier\".\"secret\"\n */\n value?: Secret<string>\n\n /**\n * Recognizable name for the token\n */\n name: string | null\n\n /**\n * A unique type to identify a bucket of tokens inside the\n * storage layer.\n */\n type: string\n\n /**\n * Hash is computed from the seed to later verify the validity\n * of seed\n */\n hash: string\n\n /**\n * Date/time when the token instance was created\n */\n createdAt: Date\n\n /**\n * Date/time when the token was updated\n */\n updatedAt: Date\n\n /**\n * Timestamp at which the token was used for authentication\n */\n lastUsedAt: Date | null\n\n /**\n * Timestamp at which the token will expire\n */\n expiresAt: Date | null\n\n /**\n * An array of abilities the token can perform. The abilities\n * is an array of abritary string values\n */\n abilities: string[]\n\n constructor(attributes: {\n identifier: string | number | BigInt\n tokenableId: string | number | BigInt\n type: string\n hash: string\n createdAt: Date\n updatedAt: Date\n lastUsedAt: Date | null\n expiresAt: Date | null\n name: string | null\n prefix?: string\n secret?: Secret<string>\n abilities?: string[]\n }) {\n this.identifier = attributes.identifier\n this.tokenableId = attributes.tokenableId\n this.name = attributes.name\n this.hash = attributes.hash\n this.type = attributes.type\n this.createdAt = attributes.createdAt\n this.updatedAt = attributes.updatedAt\n this.expiresAt = attributes.expiresAt\n this.lastUsedAt = attributes.lastUsedAt\n this.abilities = attributes.abilities || ['*']\n\n /**\n * Compute value when secret is provided\n */\n if (attributes.secret) {\n if (!attributes.prefix) {\n throw new RuntimeException('Cannot compute token value without the prefix')\n }\n this.value = new Secret(\n `${attributes.prefix}${base64.urlEncode(String(this.identifier))}.${base64.urlEncode(\n attributes.secret.release()\n )}`\n )\n }\n }\n\n /**\n * Check if the token allows the given ability.\n */\n allows(ability: string) {\n return this.abilities.includes(ability) || this.abilities.includes('*')\n }\n\n /**\n * Check if the token denies the ability.\n */\n denies(ability: string) {\n return !this.abilities.includes(ability) && !this.abilities.includes('*')\n }\n\n /**\n * Authorize ability access using the current access token\n */\n authorize(ability: string) {\n if (this.denies(ability)) {\n throw new E_UNAUTHORIZED_ACCESS('Unauthorized access', { guardDriverName: 'access_tokens' })\n }\n }\n\n /**\n * Check if the token has been expired. Verifies\n * the \"expiresAt\" timestamp with the current\n * date.\n *\n * Tokens with no expiry never expire\n */\n isExpired() {\n if (!this.expiresAt) {\n return false\n }\n\n return this.expiresAt < new Date()\n }\n\n /**\n * Verifies the value of a token against the pre-defined hash\n */\n verify(secret: Secret<string>): boolean {\n const newHash = createHash('sha256').update(secret.release()).digest('hex')\n return safeEqual(this.hash, newHash)\n }\n\n toJSON() {\n return {\n type: 'bearer',\n name: this.name,\n token: this.value ? this.value.release() : undefined,\n abilities: this.abilities,\n lastUsedAt: this.lastUsedAt,\n expiresAt: this.expiresAt,\n }\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\n/**\n * We use CRC32 just to add a recognizable checksum to tokens. This helps\n * secret scanning tools like https://docs.github.com/en/github/administering-a-repository/about-secret-scanning easily detect tokens generated by a given program.\n *\n * You can learn more about appending checksum to a hash here in this Github\n * article. https://github.blog/2021-04-05-behind-githubs-new-authentication-token-formats/\n *\n * Code taken from:\n * https://github.com/tsxper/crc32/blob/main/src/CRC32.ts\n */\n\nexport class CRC32 {\n /**\n * Lookup table calculated for 0xEDB88320 divisor\n */\n #lookupTable = [\n 0, 1996959894, 3993919788, 2567524794, 124634137, 1886057615, 3915621685, 2657392035, 249268274,\n 2044508324, 3772115230, 2547177864, 162941995, 2125561021, 3887607047, 2428444049, 498536548,\n 1789927666, 4089016648, 2227061214, 450548861, 1843258603, 4107580753, 2211677639, 325883990,\n 1684777152, 4251122042, 2321926636, 335633487, 1661365465, 4195302755, 2366115317, 997073096,\n 1281953886, 3579855332, 2724688242, 1006888145, 1258607687, 3524101629, 2768942443, 901097722,\n 1119000684, 3686517206, 2898065728, 853044451, 1172266101, 3705015759, 2882616665, 651767980,\n 1373503546, 3369554304, 3218104598, 565507253, 1454621731, 3485111705, 3099436303, 671266974,\n 1594198024, 3322730930, 2970347812, 795835527, 1483230225, 3244367275, 3060149565, 1994146192,\n 31158534, 2563907772, 4023717930, 1907459465, 112637215, 2680153253, 3904427059, 2013776290,\n 251722036, 2517215374, 3775830040, 2137656763, 141376813, 2439277719, 3865271297, 1802195444,\n 476864866, 2238001368, 4066508878, 1812370925, 453092731, 2181625025, 4111451223, 1706088902,\n 314042704, 2344532202, 4240017532, 1658658271, 366619977, 2362670323, 4224994405, 1303535960,\n 984961486, 2747007092, 3569037538, 1256170817, 1037604311, 2765210733, 3554079995, 1131014506,\n 879679996, 2909243462, 3663771856, 1141124467, 855842277, 2852801631, 3708648649, 1342533948,\n 654459306, 3188396048, 3373015174, 1466479909, 544179635, 3110523913, 3462522015, 1591671054,\n 702138776, 2966460450, 3352799412, 1504918807, 783551873, 3082640443, 3233442989, 3988292384,\n 2596254646, 62317068, 1957810842, 3939845945, 2647816111, 81470997, 1943803523, 3814918930,\n 2489596804, 225274430, 2053790376, 3826175755, 2466906013, 167816743, 2097651377, 4027552580,\n 2265490386, 503444072, 1762050814, 4150417245, 2154129355, 426522225, 1852507879, 4275313526,\n 2312317920, 282753626, 1742555852, 4189708143, 2394877945, 397917763, 1622183637, 3604390888,\n 2714866558, 953729732, 1340076626, 3518719985, 2797360999, 1068828381, 1219638859, 3624741850,\n 2936675148, 906185462, 1090812512, 3747672003, 2825379669, 829329135, 1181335161, 3412177804,\n 3160834842, 628085408, 1382605366, 3423369109, 3138078467, 570562233, 1426400815, 3317316542,\n 2998733608, 733239954, 1555261956, 3268935591, 3050360625, 752459403, 1541320221, 2607071920,\n 3965973030, 1969922972, 40735498, 2617837225, 3943577151, 1913087877, 83908371, 2512341634,\n 3803740692, 2075208622, 213261112, 2463272603, 3855990285, 2094854071, 198958881, 2262029012,\n 4057260610, 1759359992, 534414190, 2176718541, 4139329115, 1873836001, 414664567, 2282248934,\n 4279200368, 1711684554, 285281116, 2405801727, 4167216745, 1634467795, 376229701, 2685067896,\n 3608007406, 1308918612, 956543938, 2808555105, 3495958263, 1231636301, 1047427035, 2932959818,\n 3654703836, 1088359270, 936918000, 2847714899, 3736837829, 1202900863, 817233897, 3183342108,\n 3401237130, 1404277552, 615818150, 3134207493, 3453421203, 1423857449, 601450431, 3009837614,\n 3294710456, 1567103746, 711928724, 3020668471, 3272380065, 1510334235, 755167117,\n ]\n\n #initialCRC = 0xffffffff\n\n #calculateBytes(bytes: Uint8Array, accumulator?: number): number {\n let crc = accumulator || this.#initialCRC\n for (const byte of bytes) {\n const tableIndex = (crc ^ byte) & 0xff\n const tableVal = this.#lookupTable[tableIndex] as number\n crc = (crc >>> 8) ^ tableVal\n }\n return crc\n }\n\n #crcToUint(crc: number): number {\n return this.#toUint32(crc ^ 0xffffffff)\n }\n\n #strToBytes(input: string): Uint8Array {\n const encoder = new TextEncoder()\n return encoder.encode(input)\n }\n\n #toUint32(num: number): number {\n if (num >= 0) {\n return num\n }\n return 0xffffffff - num * -1 + 1\n }\n\n calculate(input: string): number {\n return this.forString(input)\n }\n\n forString(input: string): number {\n const bytes = this.#strToBytes(input)\n return this.forBytes(bytes)\n }\n\n forBytes(bytes: Uint8Array, accumulator?: number): number {\n const crc = this.#calculateBytes(bytes, accumulator)\n return this.#crcToUint(crc)\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\nimport { Secret } from '@adonisjs/core/helpers'\nimport type { HttpContext } from '@adonisjs/core/http'\nimport type { EmitterLike } from '@adonisjs/core/types/events'\n\nimport type { AccessToken } from './access_token.js'\nimport { E_UNAUTHORIZED_ACCESS } from '../../src/errors.js'\nimport type { AuthClientResponse, GuardContract } from '../../src/types.js'\nimport { GUARD_KNOWN_EVENTS, PROVIDER_REAL_USER } from '../../src/symbols.js'\nimport type { AccessTokensGuardEvents, AccessTokensUserProviderContract } from './types.js'\n\n/**\n * Implementation of access tokens guard for the Auth layer. The heavy lifting\n * of verifying tokens is done by the user provider. However, the guard is\n * used to seamlessly integrate with the auth layer of the package.\n */\nexport class AccessTokensGuard<UserProvider extends AccessTokensUserProviderContract<unknown>>\n implements\n GuardContract<UserProvider[typeof PROVIDER_REAL_USER] & { currentAccessToken: AccessToken }>\n{\n /**\n * Events emitted by the guard\n */\n declare [GUARD_KNOWN_EVENTS]: AccessTokensGuardEvents<\n UserProvider[typeof PROVIDER_REAL_USER] & { currentAccessToken: AccessToken }\n >\n\n /**\n * A unique name for the guard.\n */\n #name: string\n\n /**\n * Reference to the current HTTP context\n */\n #ctx: HttpContext\n\n /**\n * Provider to lookup user details\n */\n #userProvider: UserProvider\n\n /**\n * Emitter to emit events\n */\n #emitter: EmitterLike<\n AccessTokensGuardEvents<\n UserProvider[typeof PROVIDER_REAL_USER] & { currentAccessToken: AccessToken }\n >\n >\n\n /**\n * Driver name of the guard\n */\n driverName: 'access_tokens' = 'access_tokens'\n\n /**\n * Whether or not the authentication has been attempted\n * during the current request.\n */\n authenticationAttempted = false\n\n /**\n * A boolean to know if the current request has\n * been authenticated\n */\n isAuthenticated = false\n\n /**\n * Reference to an instance of the authenticated user.\n * The value only exists after calling one of the\n * following methods.\n *\n * - authenticate\n * - check\n *\n * You can use the \"getUserOrFail\" method to throw an exception if\n * the request is not authenticated.\n */\n user?: UserProvider[typeof PROVIDER_REAL_USER] & { currentAccessToken: AccessToken }\n\n constructor(\n name: string,\n ctx: HttpContext,\n emitter: EmitterLike<\n AccessTokensGuardEvents<\n UserProvider[typeof PROVIDER_REAL_USER] & { currentAccessToken: AccessToken }\n >\n >,\n userProvider: UserProvider\n ) {\n this.#name = name\n this.#ctx = ctx\n this.#emitter = emitter\n this.#userProvider = userProvider\n }\n\n /**\n * Emits authentication failure and returns an exception\n * to end the authentication cycle.\n */\n #authenticationFailed() {\n const error = new E_UNAUTHORIZED_ACCESS('Unauthorized access', {\n guardDriverName: this.driverName,\n })\n\n this.#emitter.emit('access_tokens_auth:authentication_failed', {\n ctx: this.#ctx,\n guardName: this.#name,\n error,\n })\n\n return error\n }\n\n /**\n * Returns the bearer token from the request headers or fails\n */\n #getBearerToken(): string {\n const bearerToken = this.#ctx.request.header('authorization', '')!\n const [, token] = bearerToken.split('Bearer ')\n if (!token) {\n throw this.#authenticationFailed()\n }\n\n return token\n }\n\n /**\n * Returns an instance of the authenticated user. Or throws\n * an exception if the request is not authenticated.\n */\n getUserOrFail(): UserProvider[typeof PROVIDER_REAL_USER] & { currentAccessToken: AccessToken } {\n if (!this.user) {\n throw new E_UNAUTHORIZED_ACCESS('Unauthorized access', {\n guardDriverName: this.driverName,\n })\n }\n\n return this.user\n }\n\n /**\n * Authenticate the current HTTP request by verifying the bearer\n * token or fails with an exception\n */\n async authenticate(): Promise<\n UserProvider[typeof PROVIDER_REAL_USER] & { currentAccessToken: AccessToken }\n > {\n /**\n * Return early when authentication has already\n * been attempted\n */\n if (this.authenticationAttempted) {\n return this.getUserOrFail()\n }\n\n /**\n * Notify we begin to attempt the authentication\n */\n this.authenticationAttempted = true\n this.#emitter.emit('access_tokens_auth:authentication_attempted', {\n ctx: this.#ctx,\n guardName: this.#name,\n })\n\n /**\n * Decode token or fail when unable to do so\n */\n const bearerToken = new Secret(this.#getBearerToken())\n\n /**\n * Verify for token via the user provider\n */\n const token = await this.#userProvider.verifyToken(bearerToken)\n if (!token) {\n throw this.#authenticationFailed()\n }\n\n /**\n * Check if a user for the token exists. Otherwise abort\n * authentication\n */\n const providerUser = await this.#userProvider.findById(token.tokenableId)\n if (!providerUser) {\n throw this.#authenticationFailed()\n }\n\n /**\n * Update local state\n */\n this.isAuthenticated = true\n this.user = providerUser.getOriginal() as UserProvider[typeof PROVIDER_REAL_USER] & {\n currentAccessToken: AccessToken\n }\n this.user!.currentAccessToken = token\n\n /**\n * Notify\n */\n this.#emitter.emit('access_tokens_auth:authentication_succeeded', {\n ctx: this.#ctx,\n token,\n guardName: this.#name,\n user: this.user,\n })\n\n return this.user\n }\n\n /**\n * Returns the Authorization header clients can use to authenticate\n * the request.\n */\n async authenticateAsClient(\n user: UserProvider[typeof PROVIDER_REAL_USER],\n abilities?: string[],\n options?: {\n expiresIn?: string | number\n name?: string\n }\n ): Promise<AuthClientResponse> {\n const token = await this.#userProvider.createToken(user, abilities, options)\n return {\n headers: {\n authorization: `Bearer ${token.value!.release()}`,\n },\n }\n }\n\n /**\n * Silently check if the user is authenticated or not. The\n * method is same the \"authenticate\" method but does not\n * throw any exceptions.\n */\n async check(): Promise<boolean> {\n try {\n await this.authenticate()\n return true\n } catch (error) {\n if (error instanceof E_UNAUTHORIZED_ACCESS) {\n return false\n }\n\n throw error\n }\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\nimport { inspect } from 'node:util'\nimport type { Secret } from '@adonisjs/core/helpers'\nimport { RuntimeException } from '@adonisjs/core/exceptions'\nimport type { LucidModel } from '@adonisjs/lucid/types/model'\n\nimport { AccessToken } from '../access_token.js'\nimport type {\n AccessTokenDbColumns,\n AccessTokensProviderContract,\n DbAccessTokensProviderOptions,\n} from '../types.js'\n\n/**\n * DbAccessTokensProvider uses lucid database service to fetch and\n * persist tokens for a given user.\n *\n * The user must be an instance of the associated user model.\n */\nexport class DbAccessTokensProvider<TokenableModel extends LucidModel>\n implements AccessTokensProviderContract<TokenableModel>\n{\n /**\n * Create tokens provider instance for a given Lucid model\n */\n static forModel<TokenableModel extends LucidModel>(\n model: DbAccessTokensProviderOptions<TokenableModel>['tokenableModel'],\n options?: Omit<DbAccessTokensProviderOptions<TokenableModel>, 'tokenableModel'>\n ) {\n return new DbAccessTokensProvider<TokenableModel>({ tokenableModel: model, ...(options || {}) })\n }\n\n /**\n * A unique type for the value. The type is used to identify a\n * bucket of tokens within the storage layer.\n *\n * Defaults to auth_token\n */\n protected type: string\n\n /**\n * A unique prefix to append to the publicly shared token value.\n *\n * Defaults to oat\n */\n protected prefix: string\n\n /**\n * Database table to use for querying access tokens\n */\n protected table: string\n\n /**\n * The length for the token secret. A secret is a cryptographically\n * secure random string.\n */\n protected tokenSecretLength: number\n\n constructor(protected options: DbAccessTokensProviderOptions<TokenableModel>) {\n this.table = options.table || 'auth_access_tokens'\n this.tokenSecretLength = options.tokenSecretLength || 40\n this.type = options.type || 'auth_token'\n this.prefix = options.prefix || 'oat_'\n }\n\n /**\n * Check if value is an object\n */\n #isObject(value: unknown) {\n return value !== null && typeof value === 'object' && !Array.isArray(value)\n }\n\n /**\n * Ensure the provided user is an instance of the user model and\n * has a primary key\n */\n #ensureIsPersisted(user: InstanceType<TokenableModel>) {\n const model = this.options.tokenableModel\n if (user instanceof model === false) {\n throw new RuntimeException(\n `Invalid user object. It must be an instance of the \"${model.name}\" model`\n )\n }\n\n if (!user.$primaryKeyValue) {\n throw new RuntimeException(\n `Cannot use \"${model.name}\" model for managing access tokens. The value of column \"${model.primaryKey}\" is undefined or null`\n )\n }\n }\n\n /**\n * Maps a database row to an instance token instance\n */\n protected dbRowToAccessToken(dbRow: AccessTokenDbColumns): AccessToken {\n return new AccessToken({\n identifier: dbRow.id,\n tokenableId: dbRow.tokenable_id,\n type: dbRow.type,\n name: dbRow.name,\n hash: dbRow.hash,\n abilities: JSON.parse(dbRow.abilities),\n createdAt:\n typeof dbRow.created_at === 'number' ? new Date(dbRow.created_at) : dbRow.created_at,\n updatedAt:\n typeof dbRow.updated_at === 'number' ? new Date(dbRow.updated_at) : dbRow.updated_at,\n lastUsedAt:\n typeof dbRow.last_used_at === 'number' ? new Date(dbRow.last_used_at) : dbRow.last_used_at,\n expiresAt:\n typeof dbRow.expires_at === 'number' ? new Date(dbRow.expires_at) : dbRow.expires_at,\n })\n }\n\n /**\n * Returns a query client instance from the parent model\n */\n protected async getDb() {\n const model = this.options.tokenableModel\n return model.$adapter.query(model).client\n }\n\n /**\n * Create a token for a user\n */\n async create(\n user: InstanceType<TokenableModel>,\n abilities: string[] = ['*'],\n options?: {\n name?: string\n expiresIn?: string | number\n }\n ) {\n this.#ensureIsPersisted(user)\n\n const queryClient = await this.getDb()\n\n /**\n * Creating a transient token. Transient token abstracts\n * the logic of creating a random secure secret and its\n * hash\n */\n const transientToken = AccessToken.createTransientToken(\n user.$primaryKeyValue!,\n this.tokenSecretLength,\n options?.expiresIn || this.options.expiresIn\n )\n\n /**\n * Row to insert inside the database. We expect exactly these\n * columns to exist.\n */\n const dbRow: Omit<AccessTokenDbColumns, 'id'> = {\n tokenable_id: transientToken.userId,\n type: this.type,\n name: options?.name || null,\n hash: transientToken.hash,\n abilities: JSON.stringify(abilities),\n created_at: new Date(),\n updated_at: new Date(),\n last_used_at: null,\n expires_at: transientToken.expiresAt || null,\n }\n\n /**\n * Insert data to the database.\n */\n const result = await queryClient.table(this.table).insert(dbRow).returning('id')\n const id = this.#isObject(result[0]) ? result[0].id : result[0]\n\n /**\n * Throw error when unable to find id in the return value of\n * the insert query\n */\n if (!id) {\n throw new RuntimeException(\n `Cannot save access token. The result \"${inspect(result)}\" of insert query is unexpected`\n )\n }\n\n /**\n * Convert db row to an access token\n */\n return new AccessToken({\n identifier: id,\n tokenableId: dbRow.tokenable_id,\n type: dbRow.type,\n prefix: this.prefix,\n secret: transientToken.secret,\n name: dbRow.name,\n hash: dbRow.hash,\n abilities: JSON.parse(dbRow.abilities),\n createdAt: dbRow.created_at,\n updatedAt: dbRow.updated_at,\n lastUsedAt: dbRow.last_used_at,\n expiresAt: dbRow.expires_at,\n })\n }\n\n /**\n * Find a token for a user by the token id\n */\n async find(user: InstanceType<TokenableModel>, identifier: string | number | BigInt) {\n this.#ensureIsPersisted(user)\n\n const queryClient = await this.getDb()\n const dbRow = await queryClient\n .query<AccessTokenDbColumns>()\n .from(this.table)\n .where({ id: identifier, tokenable_id: user.$primaryKeyValue, type: this.type })\n .limit(1)\n .first()\n\n if (!dbRow) {\n return null\n }\n\n return this.dbRowToAccessToken(dbRow)\n }\n\n /**\n * Delete a token by its id\n */\n async delete(\n user: InstanceType<TokenableModel>,\n identifier: string | number | BigInt\n ): Promise<number> {\n this.#ensureIsPersisted(user)\n\n const queryClient = await this.getDb()\n const affectedRows = await queryClient\n .query<number>()\n .from(this.table)\n .where({ id: identifier, tokenable_id: user.$primaryKeyValue, type: this.type })\n .del()\n .exec()\n\n return affectedRows as unknown as number\n }\n\n /**\n * Returns all the tokens a given user\n */\n async all(user: InstanceType<TokenableModel>) {\n this.#ensureIsPersisted(user)\n\n const queryClient = await this.getDb()\n const dbRows = await queryClient\n .query<AccessTokenDbColumns>()\n .from(this.table)\n .where({ tokenable_id: user.$primaryKeyValue, type: this.type })\n .ifDialect('postgres', (query) => {\n query.orderBy([\n {\n column: 'last_used_at',\n order: 'desc',\n nulls: 'last',\n },\n ])\n })\n .unlessDialect('postgres', (query) => {\n query.orderBy([\n {\n column: 'last_used_at',\n order: 'asc',\n nulls: 'last',\n },\n ])\n })\n .orderBy('id', 'desc')\n .exec()\n\n return dbRows.map((dbRow) => {\n return this.dbRowToAccessToken(dbRow)\n })\n }\n\n /**\n * Verifies a publicly shared access token and returns an\n * access token for it.\n *\n * Returns null when unable to verify the token or find it\n * inside the storage\n */\n async verify(tokenValue: Secret<string>) {\n const decodedToken = AccessToken.decode(this.prefix, tokenValue.release())\n if (!decodedToken) {\n return null\n }\n\n const db = await this.getDb()\n const dbRow = await db\n .query<AccessTokenDbColumns>()\n .from(this.table)\n .where({ id: decodedToken.identifier, type: this.type })\n .limit(1)\n .first()\n\n if (!dbRow) {\n return null\n }\n\n /**\n * Update last time the token is used\n */\n dbRow.last_used_at = new Date()\n await db\n .from(this.table)\n .where({ id: dbRow.id, type: dbRow.type })\n .update({ last_used_at: dbRow.last_used_at })\n\n /**\n * Convert to access token instance\n */\n const accessToken = this.dbRowToAccessToken(dbRow)\n\n /**\n * Ensure the token secret matches the token hash\n */\n if (!accessToken.verify(decodedToken.secret) || accessToken.isExpired()) {\n return null\n }\n\n return accessToken\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\nimport { Secret } from '@adonisjs/core/helpers'\nimport type { LucidRow } from '@adonisjs/lucid/types/model'\nimport { RuntimeException } from '@adonisjs/core/exceptions'\n\nimport { AccessToken } from '../access_token.js'\nimport { PROVIDER_REAL_USER } from '../../../src/symbols.js'\nimport type {\n LucidTokenable,\n AccessTokensGuardUser,\n AccessTokensUserProviderContract,\n AccessTokensLucidUserProviderOptions,\n} from '../types.js'\n\n/**\n * Uses a lucid model to verify access tokens and find a user during\n * authentication\n */\nexport class AccessTokensLucidUserProvider<\n TokenableProperty extends string,\n UserModel extends LucidTokenable<TokenableProperty>,\n> implements AccessTokensUserProviderContract<InstanceType<UserModel>>\n{\n declare [PROVIDER_REAL_USER]: InstanceType<UserModel>\n\n /**\n * Reference to the lazily imported model\n */\n protected model?: UserModel\n\n constructor(\n /**\n * Lucid provider options\n */\n protected options: AccessTokensLucidUserProviderOptions<TokenableProperty, UserModel>\n ) {}\n\n /**\n * Imports the model from the provider, returns and caches it\n * for further operations.\n */\n protected async getModel() {\n if (this.model && !('hot' in import.meta)) {\n return this.model\n }\n\n const importedModel = await this.options.model()\n this.model = importedModel.default\n return this.model\n }\n\n /**\n * Returns the tokens provider associated with the user model\n */\n protected async getTokensProvider() {\n const model = await this.getModel()\n\n if (!model[this.options.tokens]) {\n throw new RuntimeException(\n `Cannot use \"${model.name}\" model for verifying access tokens. Make sure to assign a token provider to the model.`\n )\n }\n\n return model[this.options.tokens]\n }\n\n /**\n * Creates an adapter user for the guard\n */\n async createUserForGuard(\n user: InstanceType<UserModel>\n ): Promise<AccessTokensGuardUser<InstanceType<UserModel>>> {\n const model = await this.getModel()\n if (user instanceof model === false) {\n throw new RuntimeException(\n `Invalid user object. It must be an instance of the \"${model.name}\" model`\n )\n }\n\n return {\n getId() {\n /**\n * Ensure user has a primary key\n */\n if (!user.$primaryKeyValue) {\n throw new RuntimeException(\n `Cannot use \"${model.name}\" model for authentication. The value of column \"${model.primaryKey}\" is undefined or null`\n )\n }\n\n return user.$primaryKeyValue\n },\n getOriginal() {\n return user\n },\n }\n }\n\n /**\n * Create a token for a given user\n */\n async createToken(\n user: InstanceType<UserModel>,\n abilities?: string[] | undefined,\n options?: {\n name?: string\n expiresIn?: string | number\n }\n ): Promise<AccessToken> {\n const tokensProvider = await this.getTokensProvider()\n return tokensProvider.create(user as LucidRow, abilities, options)\n }\n\n /**\n * Finds a user by the user id\n */\n async findById(\n identifier: string | number | BigInt\n ): Promise<AccessTokensGuardUser<InstanceType<UserModel>> | null> {\n const model = await this.getModel()\n const user = await model.find(identifier)\n\n if (!user) {\n return null\n }\n\n return this.createUserForGuard(user)\n }\n\n /**\n * Verifies a publicly shared access token and returns an\n * access token for it.\n */\n async verifyToken(tokenValue: Secret<string>): Promise<AccessToken | null> {\n const tokensProvider = await this.getTokensProvider()\n return tokensProvider.verify(tokenValue)\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\nimport type { HttpContext } from '@adonisjs/core/http'\nimport type { ConfigProvider } from '@adonisjs/core/types'\n\nimport { AccessTokensGuard } from './guard.js'\nimport type { GuardConfigProvider } from '../../src/types.js'\nimport { AccessTokensLucidUserProvider } from './user_providers/lucid.js'\nimport type {\n LucidTokenable,\n AccessTokensUserProviderContract,\n AccessTokensLucidUserProviderOptions,\n} from './types.js'\n\n/**\n * Configures access tokens guard for authentication\n */\nexport function tokensGuard<\n UserProvider extends AccessTokensUserProviderContract<unknown>,\n>(config: {\n provider: UserProvider | ConfigProvider<UserProvider>\n}): GuardConfigProvider<(ctx: HttpContext) => AccessTokensGuard<UserProvider>> {\n return {\n async resolver(name, app) {\n const emitter = await app.container.make('emitter')\n const provider =\n 'resolver' in config.provider ? await config.provider.resolver(app) : config.provider\n return (ctx) => new AccessTokensGuard(name, ctx, emitter as any, provider)\n },\n }\n}\n\n/**\n * Configures user provider that uses Lucid models to verify\n * access tokens and find users during authentication.\n */\nexport function tokensUserProvider<\n TokenableProperty extends string,\n Model extends LucidTokenable<TokenableProperty>,\n>(\n config: AccessTokensLucidUserProviderOptions<TokenableProperty, Model>\n): AccessTokensLucidUserProvider<TokenableProperty, Model> {\n return new AccessTokensLucidUserProvider(config)\n}\n"],"mappings":";;;;;;AASA,SAAS,kBAAkB;AAC3B,OAAO,YAAY;AACnB,SAAS,wBAAwB;AACjC,SAAS,QAAQ,QAAQ,iBAAiB;;;ACQnC,IAAM,QAAN,MAAY;AAAA;AAAA;AAAA;AAAA,EAIjB,eAAe;AAAA,IACb;AAAA,IAAG;AAAA,IAAY;AAAA,IAAY;AAAA,IAAY;AAAA,IAAW;AAAA,IAAY;AAAA,IAAY;AAAA,IAAY;AAAA,IACtF;AAAA,IAAY;AAAA,IAAY;AAAA,IAAY;AAAA,IAAW;AAAA,IAAY;AAAA,IAAY;AAAA,IAAY;AAAA,IACnF;AAAA,IAAY;AAAA,IAAY;AAAA,IAAY;AAAA,IAAW;AAAA,IAAY;AAAA,IAAY;AAAA,IAAY;AAAA,IACnF;AAAA,IAAY;AAAA,IAAY;AAAA,IAAY;AAAA,IAAW;AAAA,IAAY;AAAA,IAAY;AAAA,IAAY;AAAA,IACnF;AAAA,IAAY;AAAA,IAA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D;AACzD,SAAO,IAAI,8BAA8B,MAAM;AACjD;","names":["Secret","Secret","RuntimeException","RuntimeException","RuntimeException"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../modules/basic_auth_guard/guard.ts","../../../modules/basic_auth_guard/user_providers/lucid.ts","../../../modules/basic_auth_guard/define_config.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 auth from 'basic-auth'\nimport { base64 } from '@adonisjs/core/helpers'\nimport type { HttpContext } from '@adonisjs/core/http'\nimport type { EmitterLike } from '@adonisjs/core/types/events'\n\nimport { E_UNAUTHORIZED_ACCESS } from '../../src/errors.js'\nimport type { AuthClientResponse, GuardContract } from '../../src/types.js'\nimport { GUARD_KNOWN_EVENTS, PROVIDER_REAL_USER } from '../../src/symbols.js'\nimport type { BasicAuthGuardEvents, BasicAuthUserProviderContract } from './types.js'\n\n/**\n * BasicAuth guard implements the HTTP Authentication protocol\n */\nexport class BasicAuthGuard<UserProvider extends BasicAuthUserProviderContract<unknown>>\n implements GuardContract<UserProvider[typeof PROVIDER_REAL_USER]>\n{\n /**\n * Events emitted by the guard\n */\n declare [GUARD_KNOWN_EVENTS]: BasicAuthGuardEvents<UserProvider[typeof PROVIDER_REAL_USER]>\n\n /**\n * A unique name for the guard.\n */\n #name: string\n\n /**\n * Reference to the current HTTP context\n */\n #ctx: HttpContext\n\n /**\n * Provider to lookup user details\n */\n #userProvider: UserProvider\n\n /**\n * Emitter to emit events\n */\n #emitter: EmitterLike<BasicAuthGuardEvents<UserProvider[typeof PROVIDER_REAL_USER]>>\n\n /**\n * Driver name of the guard\n */\n driverName: 'basic_auth' = 'basic_auth'\n\n /**\n * Whether or not the authentication has been attempted\n * during the current request.\n */\n authenticationAttempted = false\n\n /**\n * A boolean to know if the current request has\n * been authenticated\n */\n isAuthenticated = false\n\n /**\n * Reference to an instance of the authenticated user.\n * The value only exists after calling one of the\n * following methods.\n *\n * - authenticate\n * - check\n *\n * You can use the \"getUserOrFail\" method to throw an exception if\n * the request is not authenticated.\n */\n user?: UserProvider[typeof PROVIDER_REAL_USER]\n\n constructor(\n name: string,\n ctx: HttpContext,\n emitter: EmitterLike<BasicAuthGuardEvents<UserProvider[typeof PROVIDER_REAL_USER]>>,\n userProvider: UserProvider\n ) {\n this.#name = name\n this.#ctx = ctx\n this.#emitter = emitter\n this.#userProvider = userProvider\n }\n\n /**\n * Emits authentication failure, updates the local state,\n * and returns an exception to end the authentication\n * cycle.\n */\n #authenticationFailed() {\n this.isAuthenticated = false\n this.user = undefined\n\n const error = new E_UNAUTHORIZED_ACCESS('Invalid basic auth credentials', {\n guardDriverName: this.driverName,\n })\n\n this.#emitter.emit('basic_auth:authentication_failed', {\n ctx: this.#ctx,\n guardName: this.#name,\n error,\n })\n\n return error\n }\n\n /**\n * Emits the authentication succeeded event and updates\n * the local state to reflect successful authentication\n */\n #authenticationSucceeded(user: UserProvider[typeof PROVIDER_REAL_USER]) {\n this.isAuthenticated = true\n this.user = user\n\n this.#emitter.emit('basic_auth:authentication_succeeded', {\n ctx: this.#ctx,\n guardName: this.#name,\n user,\n })\n }\n\n /**\n * Returns an instance of the authenticated user. Or throws\n * an exception if the request is not authenticated.\n */\n getUserOrFail(): UserProvider[typeof PROVIDER_REAL_USER] {\n if (!this.user) {\n throw new E_UNAUTHORIZED_ACCESS('Invalid basic auth credentials', {\n guardDriverName: this.driverName,\n })\n }\n\n return this.user\n }\n\n /**\n * Authenticates the incoming HTTP request by looking for BasicAuth\n * credentials inside the request authorization header.\n *\n * Returns the authenticated user or throws an exception.\n */\n async authenticate(): Promise<UserProvider[typeof PROVIDER_REAL_USER]> {\n /**\n * Avoid re-authenticating when already authenticated\n */\n if (this.authenticationAttempted) {\n return this.getUserOrFail()\n }\n\n /**\n * Beginning authentication attempt\n */\n this.authenticationAttempted = true\n this.#emitter.emit('basic_auth:authentication_attempted', {\n ctx: this.#ctx,\n guardName: this.#name,\n })\n\n /**\n * Fetch credentials from the header or fail\n */\n const credentials = auth(this.#ctx.request.request)\n if (!credentials) {\n throw this.#authenticationFailed()\n }\n\n /**\n * Verify user credentials or fail\n */\n const user = await this.#userProvider.verifyCredentials(credentials.name, credentials.pass)\n if (!user) {\n throw this.#authenticationFailed()\n }\n\n /**\n * Mark user as authenticated\n */\n this.#authenticationSucceeded(user.getOriginal())\n return this.getUserOrFail()\n }\n\n /**\n * Silently attempt to authenticate the user.\n *\n * The method returns a boolean indicating if the authentication\n * succeeded or failed.\n */\n async check(): Promise<boolean> {\n try {\n await this.authenticate()\n return true\n } catch (error) {\n if (error instanceof E_UNAUTHORIZED_ACCESS) {\n return false\n }\n\n throw error\n }\n }\n\n /**\n * Does not support authenticating as client. Instead use \"basicAuth\"\n * helper on Japa APIClient\n */\n async authenticateAsClient(uid: string, password: string): Promise<AuthClientResponse> {\n return {\n headers: {\n authorization: `Basic ${base64.encode(`${uid}:${password}`)}`,\n },\n }\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\nimport { RuntimeException } from '@adonisjs/core/exceptions'\nimport { PROVIDER_REAL_USER } from '../../../src/symbols.js'\nimport type {\n BasicAuthGuardUser,\n LucidAuthenticatable,\n BasicAuthUserProviderContract,\n BasicAuthLucidUserProviderOptions,\n} from '../types.js'\n\n/**\n * Uses a Lucid model to verify access tokens and find a user during\n * authentication\n */\nexport class BasicAuthLucidUserProvider<UserModel extends LucidAuthenticatable>\n implements BasicAuthUserProviderContract<InstanceType<UserModel>>\n{\n declare [PROVIDER_REAL_USER]: InstanceType<UserModel>\n\n /**\n * Reference to the lazily imported model\n */\n protected model?: UserModel\n\n constructor(\n /**\n * Lucid provider options\n */\n protected options: BasicAuthLucidUserProviderOptions<UserModel>\n ) {}\n\n /**\n * Imports the model from the provider, returns and caches it\n * for further operations.\n */\n protected async getModel() {\n if (this.model && !('hot' in import.meta)) {\n return this.model\n }\n\n const importedModel = await this.options.model()\n this.model = importedModel.default\n return this.model\n }\n\n /**\n * Creates an adapter user for the guard\n */\n async createUserForGuard(\n user: InstanceType<UserModel>\n ): Promise<BasicAuthGuardUser<InstanceType<UserModel>>> {\n const model = await this.getModel()\n if (user instanceof model === false) {\n throw new RuntimeException(\n `Invalid user object. It must be an instance of the \"${model.name}\" model`\n )\n }\n\n return {\n getId() {\n /**\n * Ensure user has a primary key\n */\n if (!user.$primaryKeyValue) {\n throw new RuntimeException(\n `Cannot use \"${model.name}\" model for authentication. The value of column \"${model.primaryKey}\" is undefined or null`\n )\n }\n\n return user.$primaryKeyValue\n },\n getOriginal() {\n return user\n },\n }\n }\n\n /**\n * Verifies credentials using the underlying model\n */\n async verifyCredentials(\n uid: string,\n password: string\n ): Promise<BasicAuthGuardUser<InstanceType<UserModel>> | null> {\n const model = await this.getModel()\n try {\n const user = await model.verifyCredentials(uid, password)\n return this.createUserForGuard(user as InstanceType<UserModel>)\n } catch {\n return null\n }\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\nimport type { HttpContext } from '@adonisjs/core/http'\nimport type { ConfigProvider } from '@adonisjs/core/types'\n\nimport { BasicAuthGuard } from './guard.js'\nimport type { GuardConfigProvider } from '../../src/types.js'\nimport { BasicAuthLucidUserProvider } from './user_providers/lucid.js'\nimport type {\n LucidAuthenticatable,\n BasicAuthUserProviderContract,\n BasicAuthLucidUserProviderOptions,\n} from './types.js'\n\n/**\n * Configures basic auth guard for authentication\n */\nexport function basicAuthGuard<\n UserProvider extends BasicAuthUserProviderContract<unknown>,\n>(config: {\n provider: UserProvider | ConfigProvider<UserProvider>\n}): GuardConfigProvider<(ctx: HttpContext) => BasicAuthGuard<UserProvider>> {\n return {\n async resolver(name, app) {\n const emitter = await app.container.make('emitter')\n const provider =\n 'resolver' in config.provider ? await config.provider.resolver(app) : config.provider\n return (ctx) => new BasicAuthGuard(name, ctx, emitter as any, provider)\n },\n }\n}\n\n/**\n * Configures user provider that uses Lucid models to authenticate\n * users using basic auth\n */\nexport function basicAuthUserProvider<Model extends LucidAuthenticatable>(\n config: BasicAuthLucidUserProviderOptions<Model>\n): BasicAuthLucidUserProvider<Model> {\n return new BasicAuthLucidUserProvider(config)\n}\n"],"mappings":";;;;;;AASA,OAAO,UAAU;AACjB,SAAS,cAAc;AAYhB,IAAM,iBAAN,MAEP;AAAA;AAAA;AAAA;AAAA,EASE;AAAA;AAAA;AAAA;AAAA,EAKA;AAAA;AAAA;AAAA;AAAA,EAKA;AAAA;AAAA;AAAA;AAAA,EAKA;AAAA;AAAA;AAAA;AAAA,EAKA,aAA2B;AAAA;AAAA;AAAA;AAAA;AAAA,EAM3B,0BAA0B;AAAA;AAAA;AAAA;AAAA;AAAA,EAM1B,kBAAkB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAalB;AAAA,EAEA,YACE,MACA,KACA,SACA,cACA;AACA,SAAK,QAAQ;AACb,SAAK,OAAO;AACZ,SAAK,WAAW;AAChB,SAAK,gBAAgB;AAAA,EACvB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOA,wBAAwB;AACtB,SAAK,kBAAkB;AACvB,SAAK,OAAO;AAEZ,UAAM,QAAQ,IAAI,sBAAsB,kCAAkC;AAAA,MACxE,iBAAiB,KAAK;AAAA,IACxB,CAAC;AAED,SAAK,SAAS,KAAK,oCAAoC;AAAA,MACrD,KAAK,KAAK;AAAA,MACV,WAAW,KAAK;AAAA,MAChB;AAAA,IACF,CAAC;AAED,WAAO;AAAA,EACT;AAAA;AAAA;AAAA;AAAA;AAAA,EAMA,yBAAyB,MAA+C;AACtE,SAAK,kBAAkB;AACvB,SAAK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AAM,WACJ,cAAc,OAAO,WAAW,MAAM,OAAO,SAAS,SAAS,GAAG,IAAI,OAAO;AAC/E,aAAO,CAAC,QAAQ,IAAI,eAAe,MAAM,KAAK,SAAgB,QAAQ;AAAA,IACxE;AAAA,EACF;AACF;AAMO,SAAS,sBACd,QACmC;AACnC,SAAO,IAAI,2BAA2B,MAAM;AAC9C;","names":[]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../modules/session_guard/remember_me_token.ts","../../../modules/session_guard/guard.ts","../../../modules/session_guard/token_providers/db.ts","../../../modules/session_guard/user_providers/lucid.ts","../../../modules/session_guard/define_config.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 { createHash } from 'node:crypto'\nimport string from '@adonisjs/core/helpers/string'\nimport { Secret, base64, safeEqual } from '@adonisjs/core/helpers'\n\n/**\n * Remember me token represents an opaque token that can be\n * used to automatically login a user without asking them\n * to re-login\n */\nexport class RememberMeToken {\n /**\n * Decodes a publicly shared token and return the series\n * and the token value from it.\n *\n * Returns null when unable to decode the token because of\n * invalid format or encoding.\n */\n static decode(value: string): null | { identifier: string; secret: Secret<string> } {\n /**\n * Ensure value is a string and starts with the prefix.\n */\n if (typeof value !== 'string') {\n return null\n }\n\n /**\n * Remove prefix from the rest of the token.\n */\n if (!value) {\n return null\n }\n\n const [identifier, ...tokenValue] = value.split('.')\n if (!identifier || tokenValue.length === 0) {\n return null\n }\n\n const decodedIdentifier = base64.urlDecode(identifier)\n const decodedSecret = base64.urlDecode(tokenValue.join('.'))\n if (!decodedIdentifier || !decodedSecret) {\n return null\n }\n\n return {\n identifier: decodedIdentifier,\n secret: new Secret(decodedSecret),\n }\n }\n\n /**\n * Creates a transient token that can be shared with the persistence\n * layer.\n */\n static createTransientToken(\n userId: string | number | BigInt,\n size: number,\n expiresIn: string | number\n ) {\n const expiresAt = new Date()\n expiresAt.setSeconds(expiresAt.getSeconds() + string.seconds.parse(expiresIn))\n\n return {\n userId,\n expiresAt,\n ...this.seed(size),\n }\n }\n\n /**\n * Creates a secret opaque token and its hash.\n */\n static seed(size: number) {\n const seed = string.random(size)\n const secret = new Secret(seed)\n const hash = createHash('sha256').update(secret.release()).digest('hex')\n return { secret, hash }\n }\n\n /**\n * Identifer is a unique sequence to identify the\n * token within database. It should be the\n * primary/unique key\n */\n identifier: string | number | BigInt\n\n /**\n * Reference to the user id for whom the token\n * is generated.\n */\n tokenableId: string | number | BigInt\n\n /**\n * The value is a public representation of a token. It is created\n * by combining the \"identifier\".\"secret\"\n */\n value?: Secret<string>\n\n /**\n * Hash is computed from the seed to later verify the validity\n * of seed\n */\n hash: string\n\n /**\n * Date/time when the token instance was created\n */\n createdAt: Date\n\n /**\n * Date/time when the token was updated\n */\n updatedAt: Date\n\n /**\n * Timestamp at which the token will expire\n */\n expiresAt: Date\n\n constructor(attributes: {\n identifier: string | number | BigInt\n tokenableId: string | number | BigInt\n hash: string\n createdAt: Date\n updatedAt: Date\n expiresAt: Date\n secret?: Secret<string>\n }) {\n this.identifier = attributes.identifier\n this.tokenableId = attributes.tokenableId\n this.hash = attributes.hash\n this.createdAt = attributes.createdAt\n this.updatedAt = attributes.updatedAt\n this.expiresAt = attributes.expiresAt\n\n /**\n * Compute value when secret is provided\n */\n if (attributes.secret) {\n this.value = new Secret(\n `${base64.urlEncode(String(this.identifier))}.${base64.urlEncode(\n attributes.secret.release()\n )}`\n )\n }\n }\n\n /**\n * Check if the token has been expired. Verifies\n * the \"expiresAt\" timestamp with the current\n * date.\n */\n isExpired() {\n return this.expiresAt < new Date()\n }\n\n /**\n * Verifies the value of a token against the pre-defined hash\n */\n verify(secret: Secret<string>): boolean {\n const newHash = createHash('sha256').update(secret.release()).digest('hex')\n return safeEqual(this.hash, newHash)\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\nimport { Secret } from '@adonisjs/core/helpers'\nimport type { HttpContext } from '@adonisjs/core/http'\nimport { RuntimeException } from '@adonisjs/core/exceptions'\nimport type { EmitterLike } from '@adonisjs/core/types/events'\n\nimport { RememberMeToken } from './remember_me_token.js'\nimport { E_UNAUTHORIZED_ACCESS } from '../../src/errors.js'\nimport type { AuthClientResponse, GuardContract } from '../../src/types.js'\nimport { GUARD_KNOWN_EVENTS, PROVIDER_REAL_USER } from '../../src/symbols.js'\nimport type {\n SessionGuardEvents,\n SessionGuardOptions,\n SessionUserProviderContract,\n SessionWithTokensUserProviderContract,\n} from './types.js'\n\n/**\n * Session guard uses AdonisJS session store to track logged-in\n * user information.\n */\nexport class SessionGuard<\n UseRememberTokens extends boolean,\n UserProvider extends UseRememberTokens extends true\n ? SessionWithTokensUserProviderContract<unknown>\n : SessionUserProviderContract<unknown>,\n> implements GuardContract<UserProvider[typeof PROVIDER_REAL_USER]>\n{\n /**\n * Events emitted by the guard\n */\n declare [GUARD_KNOWN_EVENTS]: SessionGuardEvents<UserProvider[typeof PROVIDER_REAL_USER]>\n\n /**\n * A unique name for the guard.\n */\n #name: string\n\n /**\n * Reference to the current HTTP context\n */\n #ctx: HttpContext\n\n /**\n * Options accepted by the session guard\n */\n #options: Required<SessionGuardOptions<UseRememberTokens>>\n\n /**\n * Provider to lookup user details\n */\n #userProvider: UserProvider\n\n /**\n * Emitter to emit events\n */\n #emitter: EmitterLike<SessionGuardEvents<UserProvider[typeof PROVIDER_REAL_USER]>>\n\n /**\n * Driver name of the guard\n */\n driverName: 'session' = 'session'\n\n /**\n * Whether or not the authentication has been attempted\n * during the current request.\n */\n authenticationAttempted = false\n\n /**\n * A boolean to know if a remember me token was used in attempt\n * to login a user.\n */\n attemptedViaRemember = false\n\n /**\n * A boolean to know if the current request has\n * been authenticated\n */\n isAuthenticated = false\n\n /**\n * A boolean to know if the current request is authenticated\n * using the \"rememember_me\" token.\n */\n viaRemember = false\n\n /**\n * Find if the user has been logged out during\n * the current request\n */\n isLoggedOut = false\n\n /**\n * Reference to an instance of the authenticated user.\n * The value only exists after calling one of the\n * following methods.\n *\n * - authenticate\n * - check\n *\n * You can use the \"getUserOrFail\" method to throw an exception if\n * the request is not authenticated.\n */\n user?: UserProvider[typeof PROVIDER_REAL_USER]\n\n /**\n * The key used to store the logged-in user id inside\n * session\n */\n get sessionKeyName() {\n return `auth_${this.#name}`\n }\n\n /**\n * The key used to store the remember me token cookie\n */\n get rememberMeKeyName() {\n return `remember_${this.#name}`\n }\n\n constructor(\n name: string,\n ctx: HttpContext,\n options: SessionGuardOptions<UseRememberTokens>,\n emitter: EmitterLike<SessionGuardEvents<UserProvider[typeof PROVIDER_REAL_USER]>>,\n userProvider: UserProvider\n ) {\n this.#name = name\n this.#ctx = ctx\n this.#options = { rememberMeTokensAge: '2 years', ...options }\n this.#emitter = emitter\n this.#userProvider = userProvider\n }\n\n /**\n * Returns the session instance for the given request,\n * ensuring the property exists\n */\n #getSession() {\n if (!('session' in this.#ctx)) {\n throw new RuntimeException(\n 'Cannot authenticate user. Install and configure \"@adonisjs/session\" package'\n )\n }\n\n return this.#ctx.session\n }\n\n /**\n * Emits authentication failure, updates the local state,\n * and returns an exception to end the authentication\n * cycle.\n */\n #authenticationFailed(sessionId: string) {\n this.isAuthenticated = false\n this.viaRemember = false\n this.user = undefined\n this.isLoggedOut = false\n\n const error = new E_UNAUTHORIZED_ACCESS('Invalid or expired user session', {\n guardDriverName: this.driverName,\n })\n\n this.#emitter.emit('session_auth:authentication_failed', {\n ctx: this.#ctx,\n guardName: this.#name,\n error,\n sessionId,\n })\n\n return error\n }\n\n /**\n * Emits the authentication succeeded event and updates\n * the local state to reflect successful authentication\n */\n #authenticationSucceeded(\n sessionId: string,\n user: UserProvider[typeof PROVIDER_REAL_USER],\n rememberMeToken?: RememberMeToken\n ) {\n this.isAuthenticated = true\n this.viaRemember = !!rememberMeToken\n this.user = user\n this.isLoggedOut = false\n\n this.#emitter.emit('session_auth:authentication_succeeded', {\n ctx: this.#ctx,\n guardName: this.#name,\n sessionId,\n user,\n rememberMeToken,\n })\n }\n\n /**\n * Emits the login succeeded event and updates the login\n * state\n */\n #loginSucceeded(\n sessionId: string,\n user: UserProvider[typeof PROVIDER_REAL_USER],\n rememberMeToken?: RememberMeToken\n ) {\n this.user = user\n this.isLoggedOut = false\n\n this.#emitter.emit('session_auth:login_succeeded', {\n ctx: this.#ctx,\n guardName: this.#name,\n sessionId,\n user,\n rememberMeToken,\n })\n }\n\n /**\n * Creates session for a given user by their user id.\n */\n #createSessionForUser(userId: string | number | BigInt) {\n const session = this.#getSession()\n session.put(this.sessionKeyName, userId)\n session.regenerate()\n }\n\n /**\n * Creates the remember me cookie\n */\n #createRememberMeCookie(value: Secret<string>) {\n this.#ctx.response.encryptedCookie(this.rememberMeKeyName, value.release(), {\n maxAge: this.#options.rememberMeTokensAge,\n httpOnly: true,\n })\n }\n\n /**\n * Authenticates the user using its id read from the session\n * store.\n *\n * - We check the user exists in the db\n * - If not, throw exception.\n * - Otherwise, update local state to mark the user as logged-in\n */\n async #authenticateViaId(userId: string | number | BigInt, sessionId: string) {\n const providerUser = await this.#userProvider.findById(userId)\n if (!providerUser) {\n throw this.#authenticationFailed(sessionId)\n }\n\n this.#authenticationSucceeded(sessionId, providerUser.getOriginal())\n return this.user!\n }\n\n /**\n * Authenticates user from the remember me cookie. Creates a fresh\n * session for them and recycles the remember me token as well.\n */\n async #authenticateViaRememberCookie(rememberMeCookie: string, sessionId: string) {\n /**\n * This method is only invoked when \"options.useRememberTokens\" is set to\n * true and hence the user provider will have methods to manage tokens\n */\n const userProvider = this.#userProvider as SessionWithTokensUserProviderContract<\n UserProvider[typeof PROVIDER_REAL_USER]\n >\n\n /**\n * Verify the token using the user provider.\n */\n const token = await userProvider.verifyRememberToken(new Secret(rememberMeCookie))\n if (!token) {\n throw this.#authenticationFailed(sessionId)\n }\n\n /**\n * Check if a user for the token exists. Otherwise abort\n * authentication\n */\n const providerUser = await userProvider.findById(token.tokenableId)\n if (!providerUser) {\n throw this.#authenticationFailed(sessionId)\n }\n\n /**\n * Recycle remember token and the remember me cookie\n */\n const recycledToken = await userProvider.recycleRememberToken(\n providerUser.getOriginal(),\n token.identifier,\n this.#options.rememberMeTokensAge\n )\n\n /**\n * Persist remember token inside the cookie\n */\n this.#createRememberMeCookie(recycledToken.value!)\n\n /**\n * Create session\n */\n this.#createSessionForUser(providerUser.getId())\n\n /**\n * Emit event and update local state\n */\n this.#authenticationSucceeded(sessionId, providerUser.getOriginal(), token)\n\n return this.user!\n }\n\n /**\n * Returns an instance of the authenticated user. Or throws\n * an exception if the request is not authenticated.\n */\n getUserOrFail(): UserProvider[typeof PROVIDER_REAL_USER] {\n if (!this.user) {\n throw new E_UNAUTHORIZED_ACCESS('Invalid or expired user session', {\n guardDriverName: this.driverName,\n })\n }\n\n return this.user\n }\n\n /**\n * Login user using sessions. Optionally, you can also create\n * a remember me token to automatically login user when their\n * session expires.\n */\n async login(user: UserProvider[typeof PROVIDER_REAL_USER], remember: boolean = false) {\n const session = this.#getSession()\n const providerUser = await this.#userProvider.createUserForGuard(user)\n\n this.#emitter.emit('session_auth:login_attempted', {\n ctx: this.#ctx,\n user,\n guardName: this.#name,\n })\n\n /**\n * Create remember me token and persist it with the provider\n * when remember me token is true.\n */\n let token: RememberMeToken | undefined\n if (remember) {\n if (!this.#options.useRememberMeTokens) {\n throw new RuntimeException('Cannot use \"rememberMe\" feature. It has been disabled')\n }\n\n /**\n * Here we assume the userProvider has implemented APIs to manage remember\n * me tokens, since the \"useRememberMeTokens\" flag is enabled.\n */\n const userProvider = this.#userProvider as SessionWithTokensUserProviderContract<\n UserProvider[typeof PROVIDER_REAL_USER]\n >\n\n token = await userProvider.createRememberToken(\n providerUser.getOriginal(),\n this.#options.rememberMeTokensAge\n )\n }\n\n /**\n * Persist remember token inside the cookie (if exists)\n * Otherwise remove the cookie\n */\n if (token) {\n this.#createRememberMeCookie(token.value!)\n } else {\n this.#ctx.response.clearCookie(this.rememberMeKeyName)\n }\n\n /**\n * Create session\n */\n this.#createSessionForUser(providerUser.getId())\n\n /**\n * Mark user as logged-in\n */\n this.#loginSucceeded(session.sessionId, providerUser.getOriginal(), token)\n }\n\n /**\n * Logout a user by removing its state from the session\n * store and delete the remember me cookie (if any).\n */\n async logout() {\n const session = this.#getSession()\n const rememberMeCookie = this.#ctx.request.encryptedCookie(this.rememberMeKeyName)\n\n /**\n * Clear client side state\n */\n session.forget(this.sessionKeyName)\n this.#ctx.response.clearCookie(this.rememberMeKeyName)\n\n /**\n * Delete remember me token when\n *\n * - Tokens are enabled\n * - A cookie exists\n * - And we know about the user already\n */\n if (this.user && rememberMeCookie && this.#options.useRememberMeTokens) {\n /**\n * Here we assume the userProvider has implemented APIs to manage remember\n * me tokens, since the \"useRememberMeTokens\" flag is enabled.\n */\n const userProvider = this.#userProvider as SessionWithTokensUserProviderContract<\n UserProvider[typeof PROVIDER_REAL_USER]\n >\n\n const token = await userProvider.verifyRememberToken(new Secret(rememberMeCookie))\n if (token) {\n await userProvider.deleteRemeberToken(this.user, token.identifier)\n }\n }\n\n /**\n * Update local state\n */\n this.user = undefined\n this.viaRemember = false\n this.isAuthenticated = false\n this.isLoggedOut = true\n\n /**\n * Notify the user has been logged out\n */\n this.#emitter.emit('session_auth:logged_out', {\n ctx: this.#ctx,\n guardName: this.#name,\n user: this.user || null,\n sessionId: session.sessionId,\n })\n }\n\n /**\n * Authenticate the current HTTP request by verifying the bearer\n * token or fails with an exception\n */\n async authenticate(): Promise<UserProvider[typeof PROVIDER_REAL_USER]> {\n /**\n * Return early when authentication has already been\n * attempted\n */\n if (this.authenticationAttempted) {\n return this.getUserOrFail()\n }\n\n /**\n * Notify we begin to attempt the authentication\n */\n this.authenticationAttempted = true\n const session = this.#getSession()\n\n this.#emitter.emit('session_auth:authentication_attempted', {\n ctx: this.#ctx,\n sessionId: session.sessionId,\n guardName: this.#name,\n })\n\n /**\n * Check if there is a user id inside the session store.\n * If yes, fetch the user from the persistent storage\n * and mark them as logged-in\n */\n const authUserId = session.get(this.sessionKeyName)\n if (authUserId) {\n return this.#authenticateViaId(authUserId, session.sessionId)\n }\n\n /**\n * If user provider supports remember me tokens and the remember me\n * cookie exists, then attempt to login + authenticate via\n * the remember me token.\n */\n const rememberMeCookie = this.#ctx.request.encryptedCookie(this.rememberMeKeyName)\n if (rememberMeCookie && this.#options.useRememberMeTokens) {\n this.attemptedViaRemember = true\n return this.#authenticateViaRememberCookie(rememberMeCookie, session.sessionId)\n }\n\n /**\n * Otherwise throw an exception\n */\n throw this.#authenticationFailed(session.sessionId)\n }\n\n /**\n * Silently check if the user is authenticated or not, without\n * throwing any exceptions\n */\n async check(): Promise<boolean> {\n try {\n await this.authenticate()\n return true\n } catch (error) {\n if (error instanceof E_UNAUTHORIZED_ACCESS) {\n return false\n }\n\n throw error\n }\n }\n\n /**\n * Returns the session info for the clients to send during\n * an HTTP request to mark the user as logged-in.\n */\n async authenticateAsClient(\n user: UserProvider[typeof PROVIDER_REAL_USER]\n ): Promise<AuthClientResponse> {\n const providerUser = await this.#userProvider.createUserForGuard(user)\n const userId = providerUser.getId()\n\n return {\n session: {\n [this.sessionKeyName]: userId,\n },\n }\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\nimport { inspect } from 'node:util'\nimport type { Secret } from '@adonisjs/core/helpers'\nimport { RuntimeException } from '@adonisjs/core/exceptions'\nimport type { LucidModel } from '@adonisjs/lucid/types/model'\n\nimport { RememberMeToken } from '../remember_me_token.js'\nimport type {\n RememberMeTokenDbColumns,\n RememberMeTokensProviderContract,\n DbRememberMeTokensProviderOptions,\n} from '../types.js'\n\n/**\n * DbRememberMeTokensProvider uses lucid database service to fetch and\n * persist tokens for a given user.\n *\n * The user must be an instance of the associated user model.\n */\nexport class DbRememberMeTokensProvider<TokenableModel extends LucidModel>\n implements RememberMeTokensProviderContract<TokenableModel>\n{\n /**\n * Create tokens provider instance for a given Lucid model\n */\n static forModel<TokenableModel extends LucidModel>(\n model: DbRememberMeTokensProviderOptions<TokenableModel>['tokenableModel'],\n options?: Omit<DbRememberMeTokensProviderOptions<TokenableModel>, 'tokenableModel'>\n ) {\n return new DbRememberMeTokensProvider<TokenableModel>({\n tokenableModel: model,\n ...(options || {}),\n })\n }\n\n /**\n * Database table to use for querying remember me tokens\n */\n protected table: string\n\n /**\n * The length for the token secret. A secret is a cryptographically\n * secure random string.\n */\n protected tokenSecretLength: number\n\n constructor(protected options: DbRememberMeTokensProviderOptions<TokenableModel>) {\n this.table = options.table || 'remember_me_tokens'\n this.tokenSecretLength = options.tokenSecretLength || 40\n }\n\n /**\n * Check if value is an object\n */\n #isObject(value: unknown) {\n return value !== null && typeof value === 'object' && !Array.isArray(value)\n }\n\n /**\n * Ensure the provided user is an instance of the user model and\n * has a primary key\n */\n #ensureIsPersisted(user: InstanceType<TokenableModel>) {\n const model = this.options.tokenableModel\n if (user instanceof model === false) {\n throw new RuntimeException(\n `Invalid user object. It must be an instance of the \"${model.name}\" model`\n )\n }\n\n if (!user.$primaryKeyValue) {\n throw new RuntimeException(\n `Cannot use \"${model.name}\" model for managing remember me tokens. The value of column \"${model.primaryKey}\" is undefined or null`\n )\n }\n }\n\n /**\n * Maps a database row to an instance token instance\n */\n protected dbRowToRememberMeToken(dbRow: RememberMeTokenDbColumns): RememberMeToken {\n return new RememberMeToken({\n identifier: dbRow.id,\n tokenableId: dbRow.tokenable_id,\n hash: dbRow.hash,\n createdAt:\n typeof dbRow.created_at === 'number' ? new Date(dbRow.created_at) : dbRow.created_at,\n updatedAt:\n typeof dbRow.updated_at === 'number' ? new Date(dbRow.updated_at) : dbRow.updated_at,\n expiresAt:\n typeof dbRow.expires_at === 'number' ? new Date(dbRow.expires_at) : dbRow.expires_at,\n })\n }\n\n /**\n * Returns a query client instance from the parent model\n */\n protected async getDb() {\n const model = this.options.tokenableModel\n return model.$adapter.query(model).client\n }\n\n /**\n * Create a token for a user\n */\n async create(user: InstanceType<TokenableModel>, expiresIn: string | number) {\n this.#ensureIsPersisted(user)\n\n const queryClient = await this.getDb()\n\n /**\n * Creating a transient token. Transient token abstracts\n * the logic of creating a random secure secret and its\n * hash\n */\n const transientToken = RememberMeToken.createTransientToken(\n user.$primaryKeyValue!,\n this.tokenSecretLength,\n expiresIn\n )\n\n /**\n * Row to insert inside the database. We expect exactly these\n * columns to exist.\n */\n const dbRow: Omit<RememberMeTokenDbColumns, 'id'> = {\n tokenable_id: transientToken.userId,\n hash: transientToken.hash,\n created_at: new Date(),\n updated_at: new Date(),\n expires_at: transientToken.expiresAt,\n }\n\n /**\n * Insert data to the database.\n */\n const result = await queryClient.table(this.table).insert(dbRow).returning('id')\n const id = this.#isObject(result[0]) ? result[0].id : result[0]\n\n /**\n * Throw error when unable to find id in the return value of\n * the insert query\n */\n if (!id) {\n throw new RuntimeException(\n `Cannot save access token. The result \"${inspect(result)}\" of insert query is unexpected`\n )\n }\n\n /**\n * Convert db row to a remember token\n */\n return new RememberMeToken({\n identifier: id,\n tokenableId: dbRow.tokenable_id,\n secret: transientToken.secret,\n hash: dbRow.hash,\n createdAt: dbRow.created_at,\n updatedAt: dbRow.updated_at,\n expiresAt: dbRow.expires_at,\n })\n }\n\n /**\n * Find a token for a user by the token id\n */\n async find(user: InstanceType<TokenableModel>, identifier: string | number | BigInt) {\n this.#ensureIsPersisted(user)\n\n const queryClient = await this.getDb()\n const dbRow = await queryClient\n .query<RememberMeTokenDbColumns>()\n .from(this.table)\n .where({ id: identifier, tokenable_id: user.$primaryKeyValue })\n .limit(1)\n .first()\n\n if (!dbRow) {\n return null\n }\n\n return this.dbRowToRememberMeToken(dbRow)\n }\n\n /**\n * Delete a token by its id\n */\n async delete(\n user: InstanceType<TokenableModel>,\n identifier: string | number | BigInt\n ): Promise<number> {\n this.#ensureIsPersisted(user)\n\n const queryClient = await this.getDb()\n const affectedRows = await queryClient\n .query<number>()\n .from(this.table)\n .where({ id: identifier, tokenable_id: user.$primaryKeyValue })\n .del()\n .exec()\n\n return affectedRows as unknown as number\n }\n\n /**\n * Returns all the tokens a given user\n */\n async all(user: InstanceType<TokenableModel>) {\n this.#ensureIsPersisted(user)\n\n const queryClient = await this.getDb()\n const dbRows = await queryClient\n .query<RememberMeTokenDbColumns>()\n .from(this.table)\n .where({ tokenable_id: user.$primaryKeyValue })\n .orderBy('id', 'desc')\n .exec()\n\n return dbRows.map((dbRow) => {\n return this.dbRowToRememberMeToken(dbRow)\n })\n }\n\n /**\n * Verifies a publicly shared remember me token and returns an\n * RememberMeToken for it.\n *\n * Returns null when unable to verify the token or find it\n * inside the storage\n */\n async verify(tokenValue: Secret<string>) {\n const decodedToken = RememberMeToken.decode(tokenValue.release())\n if (!decodedToken) {\n return null\n }\n\n const db = await this.getDb()\n const dbRow = await db\n .query<RememberMeTokenDbColumns>()\n .from(this.table)\n .where({ id: decodedToken.identifier })\n .limit(1)\n .first()\n\n if (!dbRow) {\n return null\n }\n\n /**\n * Convert to remember me token instance\n */\n const rememberMeToken = this.dbRowToRememberMeToken(dbRow)\n\n /**\n * Ensure the token secret matches the token hash\n */\n if (!rememberMeToken.verify(decodedToken.secret) || rememberMeToken.isExpired()) {\n return null\n }\n\n return rememberMeToken\n }\n\n /**\n * Recycles a remember me token by deleting the old one and\n * creates a new one.\n *\n * Ideally, the recycle should update the existing token, but we\n * skip that for now and come back to it later and handle race\n * conditions as well.\n */\n async recycle(\n user: InstanceType<TokenableModel>,\n identifier: string | number | BigInt,\n expiresIn: string | number\n ): Promise<RememberMeToken> {\n await this.delete(user, identifier)\n return this.create(user, expiresIn)\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\nimport { Secret } from '@adonisjs/core/helpers'\nimport { RuntimeException } from '@adonisjs/core/exceptions'\n\nimport { RememberMeToken } from '../remember_me_token.js'\nimport { PROVIDER_REAL_USER } from '../../../src/symbols.js'\nimport type {\n SessionGuardUser,\n LucidAuthenticatable,\n SessionLucidUserProviderOptions,\n SessionUserProviderContract,\n} from '../types.js'\n\n/**\n * Uses a lucid model to verify access tokens and find a user during\n * authentication\n */\nexport class SessionLucidUserProvider<UserModel extends LucidAuthenticatable>\n implements SessionUserProviderContract<InstanceType<UserModel>>\n{\n declare [PROVIDER_REAL_USER]: InstanceType<UserModel>\n\n /**\n * Reference to the lazily imported model\n */\n protected model?: UserModel\n\n constructor(\n /**\n * Lucid provider options\n */\n protected options: SessionLucidUserProviderOptions<UserModel>\n ) {}\n\n /**\n * Imports the model from the provider, returns and caches it\n * for further operations.\n */\n protected async getModel() {\n if (this.model && !('hot' in import.meta)) {\n return this.model\n }\n\n const importedModel = await this.options.model()\n this.model = importedModel.default\n return this.model\n }\n\n /**\n * Returns the tokens provider associated with the user model\n */\n protected async getTokensProvider() {\n const model = await this.getModel()\n\n if (!model.rememberMeTokens) {\n throw new RuntimeException(\n `Cannot use \"${model.name}\" model for verifying remember me tokens. Make sure to assign a token provider to the model.`\n )\n }\n\n return model.rememberMeTokens\n }\n\n /**\n * Creates an adapter user for the guard\n */\n async createUserForGuard(\n user: InstanceType<UserModel>\n ): Promise<SessionGuardUser<InstanceType<UserModel>>> {\n const model = await this.getModel()\n if (user instanceof model === false) {\n throw new RuntimeException(\n `Invalid user object. It must be an instance of the \"${model.name}\" model`\n )\n }\n\n return {\n getId() {\n /**\n * Ensure user has a primary key\n */\n if (!user.$primaryKeyValue) {\n throw new RuntimeException(\n `Cannot use \"${model.name}\" model for authentication. The value of column \"${model.primaryKey}\" is undefined or null`\n )\n }\n\n return user.$primaryKeyValue\n },\n getOriginal() {\n return user\n },\n }\n }\n\n /**\n * Finds a user by their primary key value\n */\n async findById(\n identifier: string | number | BigInt\n ): Promise<SessionGuardUser<InstanceType<UserModel>> | null> {\n const model = await this.getModel()\n const user = await model.find(identifier)\n\n if (!user) {\n return null\n }\n\n return this.createUserForGuard(user)\n }\n\n /**\n * Creates a remember token for a given user\n */\n async createRememberToken(\n user: InstanceType<UserModel>,\n expiresIn: string | number\n ): Promise<RememberMeToken> {\n const tokensProvider = await this.getTokensProvider()\n return tokensProvider.create(user, expiresIn)\n }\n\n /**\n * Verify a token by its publicly shared value\n */\n async verifyRememberToken(tokenValue: Secret<string>): Promise<RememberMeToken | null> {\n const tokensProvider = await this.getTokensProvider()\n return tokensProvider.verify(tokenValue)\n }\n\n /**\n * Delete a token for a user by the token identifier\n */\n async deleteRemeberToken(\n user: InstanceType<UserModel>,\n identifier: string | number | BigInt\n ): Promise<number> {\n const tokensProvider = await this.getTokensProvider()\n return tokensProvider.delete(user, identifier)\n }\n\n /**\n * Recycle a token for a user by the token identifier\n */\n async recycleRememberToken(\n user: InstanceType<UserModel>,\n identifier: string | number | BigInt,\n expiresIn: string | number\n ) {\n const tokensProvider = await this.getTokensProvider()\n return tokensProvider.recycle(user, identifier, expiresIn)\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\nimport type { HttpContext } from '@adonisjs/core/http'\nimport type { ConfigProvider } from '@adonisjs/core/types'\n\nimport { SessionGuard } from './guard.js'\nimport type { GuardConfigProvider } from '../../src/types.js'\nimport { SessionLucidUserProvider } from './user_providers/lucid.js'\nimport type {\n SessionGuardOptions,\n LucidAuthenticatable,\n SessionUserProviderContract,\n SessionLucidUserProviderOptions,\n SessionWithTokensUserProviderContract,\n} from './types.js'\n\n/**\n * Configures session tokens guard for authentication\n */\nexport function sessionGuard<\n UseRememberTokens extends boolean,\n UserProvider extends UseRememberTokens extends true\n ? SessionWithTokensUserProviderContract<unknown>\n : SessionUserProviderContract<unknown>,\n>(\n config: {\n provider: UserProvider | ConfigProvider<UserProvider>\n } & SessionGuardOptions<UseRememberTokens>\n): GuardConfigProvider<(ctx: HttpContext) => SessionGuard<UseRememberTokens, UserProvider>> {\n return {\n async resolver(name, app) {\n const emitter = await app.container.make('emitter')\n const provider =\n 'resolver' in config.provider ? await config.provider.resolver(app) : config.provider\n return (ctx) => new SessionGuard(name, ctx, config, emitter as any, provider)\n },\n }\n}\n\n/**\n * Configures user provider that uses Lucid models to authenticate\n * users using sessions\n */\nexport function sessionUserProvider<Model extends LucidAuthenticatable>(\n config: SessionLucidUserProviderOptions<Model>\n): SessionLucidUserProvider<Model> {\n return new SessionLucidUserProvider(config)\n}\n"],"mappings":";;;;;;AASA,SAAS,kBAAkB;AAC3B,OAAO,YAAY;AACnB,SAAS,QAAQ,QAAQ,iBAAiB;AAOnC,IAAM,kBAAN,MAAsB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQ3B,OAAO,OAAO,OAAsE;AAIlF,QAAI,OAAO,UAAU,UAAU;AAC7B,aAAO;AAAA,IACT;AAKA,QAAI,CAAC,OAAO;AACV,aAAO;AAAA,IACT;AAEA,UAAM,CAAC,YAAY,GAAG,UAAU,IAAI,MAAM,MAAM,GAAG;AACnD,QAAI,CAAC,cAAc,WAAW,WAAW,GAAG;AAC1C,aAAO;AAAA,IACT;AAEA,UAAM,oBAAoB,OAAO,UAAU,UAAU;AACrD,UAAM,gBAAgB,OAAO,UAAU,WAAW,KAAK,GAAG,CAAC;AAC3D,QAAI,CAAC,qBAAqB,CAAC,eAAe;AACxC,aAAO;AAAA,IACT;AAEA,WAAO;AAAA,MACL,YAAY;AAAA,MACZ,QAAQ,IAAI,OAAO,aAAa;AAAA,IAClC;AAAA,EACF;AAAA;AAAA;AAAA;AAAA;AAAA,EAMA,OAAO,qBACL,QACA,MACA,WACA;AACA,UAAM,YAAY,oBAAI,KAAK;AAC3B,cAAU,WAAW,UAAU,WAAW,IAAI,OAAO,QAAQ,MAAM,SAAS,CAAC;AAE7E,WAAO;AAAA,MACL;AAAA,MACA;AAAA,MACA,GAAG,KA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B,IAAI;AAAA,EACrC;AAAA;AAAA;AAAA;AAAA,EAKA,MAAM,oBACJ,MACA,WAC0B;AAC1B,UAAM,iBAAiB,MAAM,KAAK,kBAAkB;AACpD,WAAO,eAAe,OAAO,MAAM,SAAS;AAAA,EAC9C;AAAA;AAAA;AAAA;AAAA,EAKA,MAAM,oBAAoB,YAA6D;AACrF,UAAM,iBAAiB,MAAM,KAAK,kBAAkB;AACpD,WAAO,eAAe,OAAO,UAAU;AAAA,EACzC;AAAA;AAAA;AAAA;AAAA,EAKA,MAAM,mBACJ,MACA,YACiB;AACjB,UAAM,iBAAiB,MAAM,KAAK,kBAAkB;AACpD,WAAO,eAAe,OAAO,MAAM,UAAU;AAAA,EAC/C;AAAA;AAAA;AAAA;AAAA,EAKA,MAAM,qBACJ,MACA,YACA,WACA;AACA,UAAM,iBAAiB,MAAM,KAAK,kBAAkB;AACpD,WAAO,eAAe,QAAQ,MAAM,YAAY,SAAS;AAAA,EAC3D;AACF;;;ACtIO,SAAS,aAMd,QAG0F;AAC1F,SAAO;AAAA,IACL,MAAM,SAAS,MAAM,KAAK;AACxB,YAAM,UAAU,MAAM,IAAI,UAAU,KAAK,SAAS;AAClD,YAAM,WACJ,cAAc,OAAO,WAAW,MAAM,OAAO,SAAS,SAAS,GAAG,IAAI,OAAO;AAC/E,aAAO,CAAC,QAAQ,IAAI,aAAa,MAAM,KAAK,QAAQ,SAAgB,QAAQ;AAAA,IAC9E;AAAA,EACF;AACF;AAMO,SAAS,oBACd,QACiC;AACjC,SAAO,IAAI,yBAAyB,MAAM;AAC5C;","names":["Secret","Secret","RuntimeException","RuntimeException","RuntimeException"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../providers/auth_provider.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 { configProvider } from '@adonisjs/core'\nimport { RuntimeException } from '@poppinss/utils'\nimport type { ApplicationService } from '@adonisjs/core/types'\n\nimport type { AuthService } from '../src/types.js'\nimport { AuthManager } from '../src/auth_manager.js'\n\ndeclare module '@adonisjs/core/types' {\n export interface ContainerBindings {\n 'auth.manager': AuthService\n }\n}\n\nexport default class AuthProvider {\n constructor(protected app: ApplicationService) {}\n\n register() {\n this.app.container.singleton('auth.manager', async () => {\n const authConfigProvider = this.app.config.get('auth')\n const config = await configProvider.resolve<any>(this.app, authConfigProvider)\n\n if (!config) {\n throw new RuntimeException(\n 'Invalid config exported from \"config/auth.ts\" file. Make sure to use the defineConfig method'\n )\n }\n\n return new AuthManager(config)\n })\n }\n}\n"],"mappings":";;;;;;;;AASA,SAAS,sBAAsB;AAC/B,SAAS,wBAAwB;AAYjC,IAAqB,eAArB,MAAkC;AAAA,EAChC,YAAsB,KAAyB;AAAzB;AAAA,EAA0B;AAAA,EAEhD,WAAW;AACT,SAAK,IAAI,UAAU,UAAU,gBAAgB,YAAY;AACvD,YAAM,qBAAqB,KAAK,IAAI,OAAO,IAAI,MAAM;AACrD,YAAM,SAAS,MAAM,eAAe,QAAa,KAAK,KAAK,kBAAkB;AAE7E,UAAI,CAAC,QAAQ;AACX,cAAM,IAAI;AAAA,UACR;AAAA,QACF;AAAA,MACF;AAEA,aAAO,IAAI,YAAY,MAAM;AAAA,IAC/B,CAAC;AAAA,EACH;AACF;","names":[]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../services/auth.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 app from '@adonisjs/core/services/app'\nimport { AuthService } from '../src/types.js'\n\nlet auth: AuthService\n\n/**\n * Returns a singleton instance of the Auth manager class\n */\nawait app.booted(async () => {\n auth = await app.container.make('auth.manager')\n})\n\nexport { auth as default }\n"],"mappings":";;;AASA,OAAO,SAAS;AAGhB,IAAI;AAKJ,MAAM,IAAI,OAAO,YAAY;AAC3B,SAAO,MAAM,IAAI,UAAU,KAAK,cAAc;AAChD,CAAC;","names":[]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/middleware/initialize_auth_middleware.ts"],"sourcesContent":["/// <reference types=\"@adonisjs/core/providers/edge_provider\" />\n\nimport type { HttpContext } from '@adonisjs/core/http'\nimport type { NextFn } from '@adonisjs/core/types/http'\n\nimport type { Authenticator } from '../authenticator.js'\nimport type { Authenticators, GuardFactory } from '../types.js'\n\n/**\n * The \"InitializeAuthMiddleware\" is used to create a request\n * specific authenticator instance for every HTTP request.\n *\n * This middleware does not protect routes from unauthenticated\n * users. Please use the \"auth\" middleware for that.\n */\nexport default class InitializeAuthMiddleware {\n async handle(ctx: HttpContext, next: NextFn) {\n const auth = await ctx.containerResolver.make('auth.manager')\n\n /**\n * Initialize the authenticator for the current HTTP\n * request\n */\n ctx.auth = auth.createAuthenticator(ctx)\n\n /**\n * Sharing authenticator with templates\n */\n if ('view' in ctx) {\n ctx.view.share({ auth: ctx.auth })\n }\n\n return next()\n }\n}\n\ndeclare module '@adonisjs/core/http' {\n export interface HttpContext {\n auth: Authenticator<\n Authenticators extends Record<string, GuardFactory> ? Authenticators : never\n >\n }\n}\n"],"mappings":";;;AAeA,IAAqB,2BAArB,MAA8C;AAAA,EAC5C,MAAM,OAAO,KAAkB,MAAc;AAC3C,UAAM,OAAO,MAAM,IAAI,kBAAkB,KAAK,cAAc;AAM5D,QAAI,OAAO,KAAK,oBAAoB,GAAG;AAKvC,QAAI,UAAU,KAAK;AACjB,UAAI,KAAK,MAAM,EAAE,MAAM,IAAI,KAAK,CAAC;AAAA,IACnC;AAEA,WAAO,KAAK;AAAA,EACd;AACF;","names":[]}
|
|
@@ -1 +0,0 @@
|
|
|
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 if (await user.verifyPassword(password)) {\n return user\n }\n\n throw new E_INVALID_CREDENTIALS('Invalid user credentials')\n }\n\n /**\n * Verifies the plain password against the user's password\n * hash\n */\n verifyPassword(plainPassword: string): Promise<boolean> {\n const passwordHash = (this as any)[options.passwordColumnName]\n if (!passwordHash) {\n throw new RuntimeException(\n `Cannot verify password. The value for \"${options.passwordColumnName}\" column is undefined or null`\n )\n }\n return hash().verify(passwordHash, plainPassword)\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,YAAI,MAAM,KAAK,eAAe,QAAQ,GAAG;AACvC,iBAAO;AAAA,QACT;AAEA,cAAM,IAAI,sBAAsB,0BAA0B;AAAA,MAC5D;AAAA;AAAA;AAAA;AAAA;AAAA,MAMA,eAAe,eAAyC;AACtD,cAAM,eAAgB,KAAa,QAAQ,kBAAkB;AAC7D,YAAI,CAAC,cAAc;AACjB,gBAAM,IAAI;AAAA,YACR,0CAA0C,QAAQ,kBAAkB;AAAA,UACtE;AAAA,QACF;AACA,eAAO,KAAK,EAAE,OAAO,cAAc,aAAa;AAAA,MAClD;AAAA,IACF;AApEe;AAAA,MADZ,WAAW;AAAA,OALR,oBAMS;AAsEf,WAAO;AAAA,EACT;AACF;","names":[]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/plugins/japa/api_client.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\n/// <reference types=\"@adonisjs/session/plugins/api_client\" />\n\nimport type { PluginFn } from '@japa/runner/types'\nimport { ApiClient, ApiRequest } from '@japa/api-client'\nimport type { ApplicationService } from '@adonisjs/core/types'\n\nimport debug from '../../debug.js'\nimport type { Authenticators, GuardContract, GuardFactory } from '../../types.js'\n\ndeclare module '@japa/api-client' {\n export interface ApiRequest {\n authData: {\n guard: keyof Authenticators | '__default__'\n args: [unknown, ...any[]]\n }\n\n /**\n * Login a user using the default authentication guard\n * when making an API call\n */\n loginAs(\n ...args: {\n [K in keyof Authenticators]: Authenticators[K] extends GuardFactory\n ? ReturnType<Authenticators[K]> extends GuardContract<unknown>\n ? Parameters<ReturnType<Authenticators[K]>['authenticateAsClient']>\n : never\n : never\n }[keyof Authenticators]\n ): this\n\n /**\n * Define the authentication guard for login\n */\n withGuard<K extends keyof Authenticators, Self extends ApiRequest>(\n this: Self,\n guard: K\n ): {\n /**\n * Login a user using a specific auth guard\n */\n loginAs(\n ...args: ReturnType<Authenticators[K]> extends GuardContract<any>\n ? Parameters<ReturnType<Authenticators[K]>['authenticateAsClient']>\n : never\n ): Self\n }\n }\n}\n\n/**\n * Auth API client to authenticate users when making\n * HTTP requests using the Japa API client\n */\nexport const authApiClient = (app: ApplicationService) => {\n const pluginFn: PluginFn = function () {\n debug('installing auth api client plugin')\n\n /**\n * Login a user using the default authentication guard\n * when making an API call\n */\n ApiRequest.macro('loginAs', function (this: ApiRequest, user, ...args: any[]) {\n this.authData = {\n guard: '__default__',\n args: [user, ...args],\n }\n return this\n })\n\n /**\n * Define the authentication guard for login\n */\n ApiRequest.macro('withGuard', function <\n K extends keyof Authenticators,\n Self extends ApiRequest,\n >(this: Self, guard: K) {\n return {\n loginAs: (...args) => {\n this.authData = {\n guard,\n args: args,\n }\n return this\n },\n }\n })\n\n /**\n * Hook into the request and login the user\n */\n ApiClient.setup(async (request) => {\n const auth = await app.container.make('auth.manager')\n const authData = request['authData']\n if (!authData) {\n return\n }\n\n const client = auth.createAuthenticatorClient()\n const guard = authData.guard === '__default__' ? client.use() : client.use(authData.guard)\n const requestData = await (guard as GuardContract<unknown>).authenticateAsClient(\n ...authData.args\n )\n\n /* c8 ignore next 13 */\n if (requestData.headers) {\n debug('defining headers with api client request %O', requestData.headers)\n request.headers(requestData.headers)\n }\n if (requestData.session) {\n debug('defining session with api client request %O', requestData.session)\n request.withSession(requestData.session)\n }\n if (requestData.cookies) {\n debug('defining session with api client request %O', requestData.session)\n request.cookies(requestData.cookies)\n }\n })\n }\n\n return pluginFn\n}\n"],"mappings":";;;;;;AAYA,SAAS,WAAW,kBAAkB;AAkD/B,IAAM,gBAAgB,CAAC,QAA4B;AACxD,QAAM,WAAqB,WAAY;AACrC,kBAAM,mCAAmC;AAMzC,eAAW,MAAM,WAAW,SAA4B,SAAS,MAAa;AAC5E,WAAK,WAAW;AAAA,QACd,OAAO;AAAA,QACP,MAAM,CAAC,MAAM,GAAG,IAAI;AAAA,MACtB;AACA,aAAO;AAAA,IACT,CAAC;AAKD,eAAW,MAAM,aAAa,SAGhB,OAAU;AACtB,aAAO;AAAA,QACL,SAAS,IAAI,SAAS;AACpB,eAAK,WAAW;AAAA,YACd;AAAA,YACA;AAAA,UACF;AACA,iBAAO;AAAA,QACT;AAAA,MACF;AAAA,IACF,CAAC;AAKD,cAAU,MAAM,OAAO,YAAY;AACjC,YAAM,OAAO,MAAM,IAAI,UAAU,KAAK,cAAc;AACpD,YAAM,WAAW,QAAQ,UAAU;AACnC,UAAI,CAAC,UAAU;AACb;AAAA,MACF;AAEA,YAAM,SAAS,KAAK,0BAA0B;AAC9C,YAAM,QAAQ,SAAS,UAAU,gBAAgB,OAAO,IAAI,IAAI,OAAO,IAAI,SAAS,KAAK;AACzF,YAAM,cAAc,MAAO,MAAiC;AAAA,QAC1D,GAAG,SAAS;AAAA,MACd;AAGA,UAAI,YAAY,SAAS;AACvB,sBAAM,+CAA+C,YAAY,OAAO;AACxE,gBAAQ,QAAQ,YAAY,OAAO;AAAA,MACrC;AACA,UAAI,YAAY,SAAS;AACvB,sBAAM,+CAA+C,YAAY,OAAO;AACxE,gBAAQ,YAAY,YAAY,OAAO;AAAA,MACzC;AACA,UAAI,YAAY,SAAS;AACvB,sBAAM,+CAA+C,YAAY,OAAO;AACxE,gBAAQ,QAAQ,YAAY,OAAO;AAAA,MACrC;AAAA,IACF,CAAC;AAAA,EACH;AAEA,SAAO;AACT;","names":[]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/plugins/japa/browser_client.ts"],"sourcesContent":["/*\n * @adoniss/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\n/// <reference types=\"@japa/plugin-adonisjs\" />\n/// <reference types=\"@adonisjs/session/plugins/browser_client\" />\n\nimport type { PluginFn } from '@japa/runner/types'\nimport { decoratorsCollection } from '@japa/browser-client'\nimport { RuntimeException } from '@adonisjs/core/exceptions'\nimport type { ApplicationService } from '@adonisjs/core/types'\n\nimport debug from '../../debug.js'\nimport type { Authenticators, GuardContract, GuardFactory } from '../../types.js'\n\ndeclare module 'playwright' {\n export interface BrowserContext {\n /**\n * Login a user using the default authentication guard when\n * using the browser context to make page visits\n */\n loginAs(\n ...args: {\n [K in keyof Authenticators]: Authenticators[K] extends GuardFactory\n ? ReturnType<Authenticators[K]> extends GuardContract<unknown>\n ? Parameters<ReturnType<Authenticators[K]>['authenticateAsClient']>\n : never\n : never\n }[keyof Authenticators]\n ): Promise<void>\n\n /**\n * Define the authentication guard for login\n */\n withGuard<K extends keyof Authenticators>(\n guard: K\n ): {\n /**\n * Login a user using a specific auth guard\n */\n loginAs(\n ...args: ReturnType<Authenticators[K]> extends GuardContract<unknown>\n ? Parameters<ReturnType<Authenticators[K]>['authenticateAsClient']>\n : never\n ): Promise<void>\n }\n }\n}\n\n/**\n * Browser API client to authenticate users when making\n * HTTP requests using the Japa Browser client.\n */\nexport const authBrowserClient = (app: ApplicationService) => {\n const pluginFn: PluginFn = async function () {\n debug('installing auth browser client plugin')\n\n const auth = await app.container.make('auth.manager')\n\n decoratorsCollection.register({\n context(context) {\n /**\n * Define the authentication guard for login and perform\n * login\n */\n context.withGuard = function (guardName) {\n return {\n async loginAs(...args) {\n const client = auth.createAuthenticatorClient()\n const guard = client.use(guardName) as GuardContract<unknown>\n const requestData = await guard.authenticateAsClient(\n ...(args as [user: unknown, ...any[]])\n )\n\n /* c8 ignore next 17 */\n if (requestData.headers) {\n throw new RuntimeException(\n `Cannot use \"${guard.driverName}\" guard with browser client`\n )\n }\n\n if (requestData.cookies) {\n debug('defining cookies with browser context %O', requestData.cookies)\n Object.keys(requestData.cookies).forEach((cookie) => {\n context.setCookie(cookie, requestData.cookies![cookie])\n })\n }\n\n if (requestData.session) {\n debug('defining session with browser context %O', requestData.session)\n context.setSession(requestData.session)\n }\n },\n }\n }\n\n /**\n * Login a user using the default authentication guard when\n * using the browser context to make page visits\n */\n context.loginAs = async function (user, ...args) {\n const client = auth.createAuthenticatorClient()\n const guard = client.use() as GuardContract<unknown>\n const requestData = await guard.authenticateAsClient(user, ...args)\n\n /* c8 ignore next 15 */\n if (requestData.headers) {\n throw new RuntimeException(`Cannot use \"${guard.driverName}\" guard with browser client`)\n }\n\n if (requestData.cookies) {\n debug('defining cookies with browser context %O', requestData.cookies)\n Object.keys(requestData.cookies).forEach((cookie) => {\n context.setCookie(cookie, requestData.cookies![cookie])\n })\n }\n\n if (requestData.session) {\n debug('defining session with browser context %O', requestData.session)\n context.setSession(requestData.session)\n }\n }\n },\n })\n }\n\n return pluginFn\n}\n"],"mappings":";;;;;;AAaA,SAAS,4BAA4B;AACrC,SAAS,wBAAwB;AA4C1B,IAAM,oBAAoB,CAAC,QAA4B;AAC5D,QAAM,WAAqB,iBAAkB;AAC3C,kBAAM,uCAAuC;AAE7C,UAAM,OAAO,MAAM,IAAI,UAAU,KAAK,cAAc;AAEpD,yBAAqB,SAAS;AAAA,MAC5B,QAAQ,SAAS;AAKf,gBAAQ,YAAY,SAAU,WAAW;AACvC,iBAAO;AAAA,YACL,MAAM,WAAW,MAAM;AACrB,oBAAM,SAAS,KAAK,0BAA0B;AAC9C,oBAAM,QAAQ,OAAO,IAAI,SAAS;AAClC,oBAAM,cAAc,MAAM,MAAM;AAAA,gBAC9B,GAAI;AAAA,cACN;AAGA,kBAAI,YAAY,SAAS;AACvB,sBAAM,IAAI;AAAA,kBACR,eAAe,MAAM,UAAU;AAAA,gBACjC;AAAA,cACF;AAEA,kBAAI,YAAY,SAAS;AACvB,8BAAM,4CAA4C,YAAY,OAAO;AACrE,uBAAO,KAAK,YAAY,OAAO,EAAE,QAAQ,CAAC,WAAW;AACnD,0BAAQ,UAAU,QAAQ,YAAY,QAAS,MAAM,CAAC;AAAA,gBACxD,CAAC;AAAA,cACH;AAEA,kBAAI,YAAY,SAAS;AACvB,8BAAM,4CAA4C,YAAY,OAAO;AACrE,wBAAQ,WAAW,YAAY,OAAO;AAAA,cACxC;AAAA,YACF;AAAA,UACF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