@eienjs/adonisjs-simple-auth 1.0.1 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/{LICENSE.md → LICENSE} +1 -1
- package/README.md +26 -3
- package/build/_virtual/_@oxc-project_runtime@0.137.0/helpers/esm/decorate.js +9 -0
- package/build/commands/generate_api_key.d.ts +11 -7
- package/build/commands/generate_api_key.js +23 -347
- package/build/configure.d.ts +6 -2
- package/build/configure.js +18 -0
- package/build/index.d.ts +6 -5
- package/build/index.js +6 -49
- package/build/middleware/simple_auth_middleware.d.ts +12 -0
- package/build/middleware/simple_auth_middleware.js +14 -0
- package/build/plugins/api_client.d.ts +14 -0
- package/build/plugins/api_client.js +23 -0
- package/build/providers/simple_auth_provider.d.ts +13 -9
- package/build/providers/simple_auth_provider.js +16 -26
- package/build/src/define_config.d.ts +7 -3
- package/build/src/define_config.js +13 -0
- package/build/src/errors.d.ts +20 -16
- package/build/src/errors.js +41 -0
- package/build/src/helpers/crc32.js +308 -0
- package/build/src/simple_auth.d.ts +14 -10
- package/build/src/simple_auth.js +23 -0
- package/build/stubs/main.d.ts +4 -5
- package/build/stubs/main.js +4 -0
- package/build/types.d.ts +13 -0
- package/build/types.js +1 -0
- package/package.json +91 -92
- package/build/chunk-EUXUH3YW.js +0 -15
- package/build/chunk-EUXUH3YW.js.map +0 -1
- package/build/chunk-JUF7K25A.js +0 -80
- package/build/chunk-JUF7K25A.js.map +0 -1
- package/build/chunk-TVVNPJ4M.js +0 -19
- package/build/chunk-TVVNPJ4M.js.map +0 -1
- package/build/commands/generate_api_key.js.map +0 -1
- package/build/index.js.map +0 -1
- package/build/metafile-esm.json +0 -1
- package/build/providers/simple_auth_provider.js.map +0 -1
- package/build/src/helpers/crc32.d.ts +0 -24
- package/build/src/middleware/simple_auth_middleware.d.ts +0 -8
- package/build/src/middleware/simple_auth_middleware.js +0 -9
- package/build/src/middleware/simple_auth_middleware.js.map +0 -1
- package/build/src/plugins/japa/api_client.d.ts +0 -11
- package/build/src/plugins/japa/api_client.js +0 -34
- package/build/src/plugins/japa/api_client.js.map +0 -1
- package/build/src/types.d.ts +0 -9
- package/build/src/types.js +0 -1
- package/build/src/types.js.map +0 -1
- /package/build/{config.stub → stubs/config.stub} +0 -0
- /package/build/{middleware → stubs/middleware}/api_key.stub +0 -0
package/{LICENSE.md → LICENSE}
RENAMED
package/README.md
CHANGED
|
@@ -7,15 +7,38 @@
|
|
|
7
7
|
[![Build Status][badge-build]][build]
|
|
8
8
|
[![Total Downloads][badge-downloads]][downloads]
|
|
9
9
|
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
> Single authentication key that allows authenticate
|
|
10
|
+
> Single authentication key that allows authenticate on your adonisjs v7 application
|
|
13
11
|
|
|
14
12
|
## Introduction
|
|
15
13
|
|
|
16
14
|
This package enables you to create a single authentication key that allows you to authenticate just by including the key.
|
|
17
15
|
This simplicity also allows a user to make calls easily, with cURL, with interactive docs, or even in their browser.
|
|
18
16
|
|
|
17
|
+
## Quick Start
|
|
18
|
+
|
|
19
|
+
Install the package from npm using the following command:
|
|
20
|
+
|
|
21
|
+
```sh
|
|
22
|
+
node ace add @eienjs/adonisjs-simple-auth
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
Automatically the command will register the provider and the command. You will be able to use the package immediately. Now you need run the command to generate your api key
|
|
26
|
+
|
|
27
|
+
```sh
|
|
28
|
+
node ace generate:api-key
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
So, protect your routes with the following middleware
|
|
32
|
+
|
|
33
|
+
```typescript
|
|
34
|
+
import router from '@adonisjs/core/services/router';
|
|
35
|
+
import { middleware } from '#start/kernel';
|
|
36
|
+
|
|
37
|
+
/// ...other routes
|
|
38
|
+
|
|
39
|
+
router.get('/', () => 'Hello World').use(middleware.apiKey());
|
|
40
|
+
```
|
|
41
|
+
|
|
19
42
|
## Documentation
|
|
20
43
|
|
|
21
44
|
The documentation is available on [EienJS](https://eienjs.com/packages/adonisjs-simple-auth/getting-started/).
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
//#region \0@oxc-project+runtime@0.137.0/helpers/esm/decorate.js
|
|
2
|
+
function __decorate(decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
}
|
|
8
|
+
//#endregion
|
|
9
|
+
export { __decorate as default };
|
|
@@ -1,8 +1,12 @@
|
|
|
1
|
-
import { BaseCommand } from
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
1
|
+
import { BaseCommand } from "@adonisjs/core/ace";
|
|
2
|
+
|
|
3
|
+
//#region commands/generate_api_key.d.ts
|
|
4
|
+
declare class GenerateApiKey extends BaseCommand {
|
|
5
|
+
static readonly commandName = "generate:api-key";
|
|
6
|
+
static readonly description = "Generate a a cryptographically secure random value suffixed with a CRC32 checksum";
|
|
7
|
+
show: boolean;
|
|
8
|
+
force: boolean;
|
|
9
|
+
run(): Promise<void>;
|
|
8
10
|
}
|
|
11
|
+
//#endregion
|
|
12
|
+
export { GenerateApiKey as default };
|
|
@@ -1,353 +1,29 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
} from "
|
|
4
|
-
|
|
5
|
-
// commands/generate_api_key.ts
|
|
1
|
+
import { CRC32 } from "../src/helpers/crc32.js";
|
|
2
|
+
import __decorate from "../_virtual/_@oxc-project_runtime@0.137.0/helpers/esm/decorate.js";
|
|
3
|
+
import { Secret, base64 } from "@adonisjs/core/helpers";
|
|
6
4
|
import process from "node:process";
|
|
7
5
|
import { BaseCommand, flags } from "@adonisjs/core/ace";
|
|
8
6
|
import { EnvEditor } from "@adonisjs/core/env/editor";
|
|
9
|
-
import { base64, Secret } from "@adonisjs/core/helpers";
|
|
10
7
|
import string from "@adonisjs/core/helpers/string";
|
|
11
|
-
|
|
12
|
-
// src/helpers/crc32.ts
|
|
13
|
-
import { TextEncoder } from "node:util";
|
|
14
|
-
var CRC32 = class {
|
|
15
|
-
/**
|
|
16
|
-
* Lookup table calculated for 0xEDB88320 divisor
|
|
17
|
-
*/
|
|
18
|
-
lookupTable = [
|
|
19
|
-
0,
|
|
20
|
-
1996959894,
|
|
21
|
-
3993919788,
|
|
22
|
-
2567524794,
|
|
23
|
-
124634137,
|
|
24
|
-
1886057615,
|
|
25
|
-
3915621685,
|
|
26
|
-
2657392035,
|
|
27
|
-
249268274,
|
|
28
|
-
2044508324,
|
|
29
|
-
3772115230,
|
|
30
|
-
2547177864,
|
|
31
|
-
162941995,
|
|
32
|
-
2125561021,
|
|
33
|
-
3887607047,
|
|
34
|
-
2428444049,
|
|
35
|
-
498536548,
|
|
36
|
-
1789927666,
|
|
37
|
-
4089016648,
|
|
38
|
-
2227061214,
|
|
39
|
-
450548861,
|
|
40
|
-
1843258603,
|
|
41
|
-
4107580753,
|
|
42
|
-
2211677639,
|
|
43
|
-
325883990,
|
|
44
|
-
1684777152,
|
|
45
|
-
4251122042,
|
|
46
|
-
2321926636,
|
|
47
|
-
335633487,
|
|
48
|
-
1661365465,
|
|
49
|
-
4195302755,
|
|
50
|
-
2366115317,
|
|
51
|
-
997073096,
|
|
52
|
-
1281953886,
|
|
53
|
-
3579855332,
|
|
54
|
-
2724688242,
|
|
55
|
-
1006888145,
|
|
56
|
-
1258607687,
|
|
57
|
-
3524101629,
|
|
58
|
-
2768942443,
|
|
59
|
-
901097722,
|
|
60
|
-
1119000684,
|
|
61
|
-
3686517206,
|
|
62
|
-
2898065728,
|
|
63
|
-
853044451,
|
|
64
|
-
1172266101,
|
|
65
|
-
3705015759,
|
|
66
|
-
2882616665,
|
|
67
|
-
651767980,
|
|
68
|
-
1373503546,
|
|
69
|
-
3369554304,
|
|
70
|
-
3218104598,
|
|
71
|
-
565507253,
|
|
72
|
-
1454621731,
|
|
73
|
-
3485111705,
|
|
74
|
-
3099436303,
|
|
75
|
-
671266974,
|
|
76
|
-
1594198024,
|
|
77
|
-
3322730930,
|
|
78
|
-
2970347812,
|
|
79
|
-
795835527,
|
|
80
|
-
1483230225,
|
|
81
|
-
3244367275,
|
|
82
|
-
3060149565,
|
|
83
|
-
1994146192,
|
|
84
|
-
31158534,
|
|
85
|
-
2563907772,
|
|
86
|
-
4023717930,
|
|
87
|
-
1907459465,
|
|
88
|
-
112637215,
|
|
89
|
-
2680153253,
|
|
90
|
-
3904427059,
|
|
91
|
-
2013776290,
|
|
92
|
-
251722036,
|
|
93
|
-
2517215374,
|
|
94
|
-
3775830040,
|
|
95
|
-
2137656763,
|
|
96
|
-
141376813,
|
|
97
|
-
2439277719,
|
|
98
|
-
3865271297,
|
|
99
|
-
1802195444,
|
|
100
|
-
476864866,
|
|
101
|
-
2238001368,
|
|
102
|
-
4066508878,
|
|
103
|
-
1812370925,
|
|
104
|
-
453092731,
|
|
105
|
-
2181625025,
|
|
106
|
-
4111451223,
|
|
107
|
-
1706088902,
|
|
108
|
-
314042704,
|
|
109
|
-
2344532202,
|
|
110
|
-
4240017532,
|
|
111
|
-
1658658271,
|
|
112
|
-
366619977,
|
|
113
|
-
2362670323,
|
|
114
|
-
4224994405,
|
|
115
|
-
1303535960,
|
|
116
|
-
984961486,
|
|
117
|
-
2747007092,
|
|
118
|
-
3569037538,
|
|
119
|
-
1256170817,
|
|
120
|
-
1037604311,
|
|
121
|
-
2765210733,
|
|
122
|
-
3554079995,
|
|
123
|
-
1131014506,
|
|
124
|
-
879679996,
|
|
125
|
-
2909243462,
|
|
126
|
-
3663771856,
|
|
127
|
-
1141124467,
|
|
128
|
-
855842277,
|
|
129
|
-
2852801631,
|
|
130
|
-
3708648649,
|
|
131
|
-
1342533948,
|
|
132
|
-
654459306,
|
|
133
|
-
3188396048,
|
|
134
|
-
3373015174,
|
|
135
|
-
1466479909,
|
|
136
|
-
544179635,
|
|
137
|
-
3110523913,
|
|
138
|
-
3462522015,
|
|
139
|
-
1591671054,
|
|
140
|
-
702138776,
|
|
141
|
-
2966460450,
|
|
142
|
-
3352799412,
|
|
143
|
-
1504918807,
|
|
144
|
-
783551873,
|
|
145
|
-
3082640443,
|
|
146
|
-
3233442989,
|
|
147
|
-
3988292384,
|
|
148
|
-
2596254646,
|
|
149
|
-
62317068,
|
|
150
|
-
1957810842,
|
|
151
|
-
3939845945,
|
|
152
|
-
2647816111,
|
|
153
|
-
81470997,
|
|
154
|
-
1943803523,
|
|
155
|
-
3814918930,
|
|
156
|
-
2489596804,
|
|
157
|
-
225274430,
|
|
158
|
-
2053790376,
|
|
159
|
-
3826175755,
|
|
160
|
-
2466906013,
|
|
161
|
-
167816743,
|
|
162
|
-
2097651377,
|
|
163
|
-
4027552580,
|
|
164
|
-
2265490386,
|
|
165
|
-
503444072,
|
|
166
|
-
1762050814,
|
|
167
|
-
4150417245,
|
|
168
|
-
2154129355,
|
|
169
|
-
426522225,
|
|
170
|
-
1852507879,
|
|
171
|
-
4275313526,
|
|
172
|
-
2312317920,
|
|
173
|
-
282753626,
|
|
174
|
-
1742555852,
|
|
175
|
-
4189708143,
|
|
176
|
-
2394877945,
|
|
177
|
-
397917763,
|
|
178
|
-
1622183637,
|
|
179
|
-
3604390888,
|
|
180
|
-
2714866558,
|
|
181
|
-
953729732,
|
|
182
|
-
1340076626,
|
|
183
|
-
3518719985,
|
|
184
|
-
2797360999,
|
|
185
|
-
1068828381,
|
|
186
|
-
1219638859,
|
|
187
|
-
3624741850,
|
|
188
|
-
2936675148,
|
|
189
|
-
906185462,
|
|
190
|
-
1090812512,
|
|
191
|
-
3747672003,
|
|
192
|
-
2825379669,
|
|
193
|
-
829329135,
|
|
194
|
-
1181335161,
|
|
195
|
-
3412177804,
|
|
196
|
-
3160834842,
|
|
197
|
-
628085408,
|
|
198
|
-
1382605366,
|
|
199
|
-
3423369109,
|
|
200
|
-
3138078467,
|
|
201
|
-
570562233,
|
|
202
|
-
1426400815,
|
|
203
|
-
3317316542,
|
|
204
|
-
2998733608,
|
|
205
|
-
733239954,
|
|
206
|
-
1555261956,
|
|
207
|
-
3268935591,
|
|
208
|
-
3050360625,
|
|
209
|
-
752459403,
|
|
210
|
-
1541320221,
|
|
211
|
-
2607071920,
|
|
212
|
-
3965973030,
|
|
213
|
-
1969922972,
|
|
214
|
-
40735498,
|
|
215
|
-
2617837225,
|
|
216
|
-
3943577151,
|
|
217
|
-
1913087877,
|
|
218
|
-
83908371,
|
|
219
|
-
2512341634,
|
|
220
|
-
3803740692,
|
|
221
|
-
2075208622,
|
|
222
|
-
213261112,
|
|
223
|
-
2463272603,
|
|
224
|
-
3855990285,
|
|
225
|
-
2094854071,
|
|
226
|
-
198958881,
|
|
227
|
-
2262029012,
|
|
228
|
-
4057260610,
|
|
229
|
-
1759359992,
|
|
230
|
-
534414190,
|
|
231
|
-
2176718541,
|
|
232
|
-
4139329115,
|
|
233
|
-
1873836001,
|
|
234
|
-
414664567,
|
|
235
|
-
2282248934,
|
|
236
|
-
4279200368,
|
|
237
|
-
1711684554,
|
|
238
|
-
285281116,
|
|
239
|
-
2405801727,
|
|
240
|
-
4167216745,
|
|
241
|
-
1634467795,
|
|
242
|
-
376229701,
|
|
243
|
-
2685067896,
|
|
244
|
-
3608007406,
|
|
245
|
-
1308918612,
|
|
246
|
-
956543938,
|
|
247
|
-
2808555105,
|
|
248
|
-
3495958263,
|
|
249
|
-
1231636301,
|
|
250
|
-
1047427035,
|
|
251
|
-
2932959818,
|
|
252
|
-
3654703836,
|
|
253
|
-
1088359270,
|
|
254
|
-
936918e3,
|
|
255
|
-
2847714899,
|
|
256
|
-
3736837829,
|
|
257
|
-
1202900863,
|
|
258
|
-
817233897,
|
|
259
|
-
3183342108,
|
|
260
|
-
3401237130,
|
|
261
|
-
1404277552,
|
|
262
|
-
615818150,
|
|
263
|
-
3134207493,
|
|
264
|
-
3453421203,
|
|
265
|
-
1423857449,
|
|
266
|
-
601450431,
|
|
267
|
-
3009837614,
|
|
268
|
-
3294710456,
|
|
269
|
-
1567103746,
|
|
270
|
-
711928724,
|
|
271
|
-
3020668471,
|
|
272
|
-
3272380065,
|
|
273
|
-
1510334235,
|
|
274
|
-
755167117
|
|
275
|
-
];
|
|
276
|
-
initialCRC = 4294967295;
|
|
277
|
-
calculateBytes(bytes, accumulator) {
|
|
278
|
-
let crc = accumulator ?? this.initialCRC;
|
|
279
|
-
for (const byte of bytes) {
|
|
280
|
-
const tableIndex = (crc ^ byte) & 255;
|
|
281
|
-
const tableVal = this.lookupTable[tableIndex];
|
|
282
|
-
crc = crc >>> 8 ^ tableVal;
|
|
283
|
-
}
|
|
284
|
-
return crc;
|
|
285
|
-
}
|
|
286
|
-
crcToUint(crc) {
|
|
287
|
-
return this.toUint32(crc ^ 4294967295);
|
|
288
|
-
}
|
|
289
|
-
strToBytes(input) {
|
|
290
|
-
const encoder = new TextEncoder();
|
|
291
|
-
return encoder.encode(input);
|
|
292
|
-
}
|
|
293
|
-
toUint32(num) {
|
|
294
|
-
if (num >= 0) {
|
|
295
|
-
return num;
|
|
296
|
-
}
|
|
297
|
-
return 4294967295 - num * -1 + 1;
|
|
298
|
-
}
|
|
299
|
-
calculate(input) {
|
|
300
|
-
return this.forString(input);
|
|
301
|
-
}
|
|
302
|
-
forString(input) {
|
|
303
|
-
const bytes = this.strToBytes(input);
|
|
304
|
-
return this.forBytes(bytes);
|
|
305
|
-
}
|
|
306
|
-
forBytes(bytes, accumulator) {
|
|
307
|
-
const crc = this.calculateBytes(bytes, accumulator);
|
|
308
|
-
return this.crcToUint(crc);
|
|
309
|
-
}
|
|
310
|
-
};
|
|
311
|
-
|
|
312
|
-
// commands/generate_api_key.ts
|
|
8
|
+
//#region commands/generate_api_key.ts
|
|
313
9
|
var GenerateApiKey = class extends BaseCommand {
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
const tokenString = result.release();
|
|
330
|
-
if (writeToFile) {
|
|
331
|
-
const editor = await EnvEditor.create(this.app.appRoot);
|
|
332
|
-
editor.add("API_KEY", tokenString, true);
|
|
333
|
-
await editor.save();
|
|
334
|
-
this.logger.action("add API_KEY to .env").succeeded();
|
|
335
|
-
} else {
|
|
336
|
-
this.logger.log(`API_KEY = ${tokenString}`);
|
|
337
|
-
}
|
|
338
|
-
}
|
|
339
|
-
};
|
|
340
|
-
__decorateClass([
|
|
341
|
-
flags.boolean({
|
|
342
|
-
description: "Display the token on the terminal, instead of writing it to .env file"
|
|
343
|
-
})
|
|
344
|
-
], GenerateApiKey.prototype, "show", 2);
|
|
345
|
-
__decorateClass([
|
|
346
|
-
flags.boolean({
|
|
347
|
-
description: "Force update .env file in production environment"
|
|
348
|
-
})
|
|
349
|
-
], GenerateApiKey.prototype, "force", 2);
|
|
350
|
-
export {
|
|
351
|
-
GenerateApiKey as default
|
|
10
|
+
static commandName = "generate:api-key";
|
|
11
|
+
static description = "Generate a a cryptographically secure random value suffixed with a CRC32 checksum";
|
|
12
|
+
async run() {
|
|
13
|
+
let shouldWriteToFile = this.force ? true : process.env.NODE_ENV !== "production";
|
|
14
|
+
if (this.show) shouldWriteToFile = false;
|
|
15
|
+
const seed = string.random(40);
|
|
16
|
+
const tokenSecret = new Secret(`${seed}${new CRC32().calculate(seed)}`);
|
|
17
|
+
const tokenString = new Secret(`oat_${base64.urlEncode(string.random(2))}.${base64.urlEncode(tokenSecret.release())}`).release();
|
|
18
|
+
if (shouldWriteToFile) {
|
|
19
|
+
const editor = await EnvEditor.create(this.app.appRoot);
|
|
20
|
+
editor.add("API_KEY", tokenString, true);
|
|
21
|
+
await editor.save();
|
|
22
|
+
this.logger.action("add API_KEY to .env").succeeded();
|
|
23
|
+
} else this.logger.log(`API_KEY = ${tokenString}`);
|
|
24
|
+
}
|
|
352
25
|
};
|
|
353
|
-
|
|
26
|
+
__decorate([flags.boolean({ description: "Display the token on the terminal, instead of writing it to .env file" })], GenerateApiKey.prototype, "show", void 0);
|
|
27
|
+
__decorate([flags.boolean({ description: "Force update .env file in production environment" })], GenerateApiKey.prototype, "force", void 0);
|
|
28
|
+
//#endregion
|
|
29
|
+
export { GenerateApiKey as default };
|
package/build/configure.d.ts
CHANGED
|
@@ -1,2 +1,6 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
1
|
+
import Configure from "@adonisjs/core/commands/configure";
|
|
2
|
+
|
|
3
|
+
//#region configure.d.ts
|
|
4
|
+
declare const configure: (command: Configure) => Promise<void>;
|
|
5
|
+
//#endregion
|
|
6
|
+
export { configure };
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { stubsRoot } from "./stubs/main.js";
|
|
2
|
+
//#region configure.ts
|
|
3
|
+
const configure = async (command) => {
|
|
4
|
+
const codemods = await command.createCodemods();
|
|
5
|
+
await codemods.updateRcFile((rcFile) => {
|
|
6
|
+
rcFile.addCommand("@eienjs/adonisjs-simple-auth/commands");
|
|
7
|
+
rcFile.addProvider("@eienjs/adonisjs-simple-auth/providers/simple_auth_provider");
|
|
8
|
+
});
|
|
9
|
+
await codemods.makeUsingStub(stubsRoot, "config.stub", {});
|
|
10
|
+
await codemods.makeUsingStub(stubsRoot, "middleware/api_key.stub", { entity: command.app.generators.createEntity("api_key") });
|
|
11
|
+
await codemods.registerMiddleware("router", [{ path: "@eienjs/adonisjs-simple-auth/middleware/simple_auth_middleware" }]);
|
|
12
|
+
await codemods.registerMiddleware("named", [{
|
|
13
|
+
name: "apiKey",
|
|
14
|
+
path: "#middleware/api_key_middleware"
|
|
15
|
+
}]);
|
|
16
|
+
};
|
|
17
|
+
//#endregion
|
|
18
|
+
export { configure };
|
package/build/index.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
import { configure } from "./configure.js";
|
|
2
|
+
import { defineConfig } from "./src/define_config.js";
|
|
3
|
+
import { SimpleAuthException } from "./src/errors.js";
|
|
4
|
+
import { SimpleAuth } from "./src/simple_auth.js";
|
|
5
|
+
import { stubsRoot } from "./stubs/main.js";
|
|
6
|
+
export { SimpleAuth, SimpleAuthException, configure, defineConfig, stubsRoot };
|
package/build/index.js
CHANGED
|
@@ -1,49 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
} from "./
|
|
5
|
-
import "./
|
|
6
|
-
|
|
7
|
-
// stubs/main.ts
|
|
8
|
-
import { getDirname } from "@adonisjs/core/helpers";
|
|
9
|
-
var stubsRoot = getDirname(import.meta.url);
|
|
10
|
-
|
|
11
|
-
// configure.ts
|
|
12
|
-
var configure = async (command) => {
|
|
13
|
-
const codemods = await command.createCodemods();
|
|
14
|
-
await codemods.updateRcFile((rcFile) => {
|
|
15
|
-
rcFile.addCommand("@eienjs/adonisjs-simple-auth/commands");
|
|
16
|
-
rcFile.addProvider("@eienjs/adonisjs-simple-auth/simple_auth_provider");
|
|
17
|
-
});
|
|
18
|
-
await codemods.makeUsingStub(stubsRoot, "config.stub", {});
|
|
19
|
-
await codemods.makeUsingStub(stubsRoot, "middleware/api_key.stub", {
|
|
20
|
-
entity: command.app.generators.createEntity("api_key")
|
|
21
|
-
});
|
|
22
|
-
await codemods.registerMiddleware("router", [{ path: "@eienjs/adonisjs-simple-auth/simple_auth_middleware" }]);
|
|
23
|
-
await codemods.registerMiddleware("named", [
|
|
24
|
-
{
|
|
25
|
-
name: "apiKey",
|
|
26
|
-
path: "#middleware/api_key_middleware"
|
|
27
|
-
}
|
|
28
|
-
]);
|
|
29
|
-
};
|
|
30
|
-
|
|
31
|
-
// src/define_config.ts
|
|
32
|
-
import { configProvider } from "@adonisjs/core";
|
|
33
|
-
import { Secret } from "@adonisjs/core/helpers";
|
|
34
|
-
var defineConfig = (config) => {
|
|
35
|
-
return configProvider.create(async (_) => {
|
|
36
|
-
return {
|
|
37
|
-
apiKeyHeader: config.apiKeyHeader ?? "x-api-key",
|
|
38
|
-
apiKeyValue: new Secret(config.apiKeyValue)
|
|
39
|
-
};
|
|
40
|
-
});
|
|
41
|
-
};
|
|
42
|
-
export {
|
|
43
|
-
SimpleAuth,
|
|
44
|
-
SimpleAuthException,
|
|
45
|
-
configure,
|
|
46
|
-
defineConfig,
|
|
47
|
-
stubsRoot
|
|
48
|
-
};
|
|
49
|
-
//# sourceMappingURL=index.js.map
|
|
1
|
+
import { stubsRoot } from "./stubs/main.js";
|
|
2
|
+
import { configure } from "./configure.js";
|
|
3
|
+
import { defineConfig } from "./src/define_config.js";
|
|
4
|
+
import { SimpleAuthException } from "./src/errors.js";
|
|
5
|
+
import { SimpleAuth } from "./src/simple_auth.js";
|
|
6
|
+
export { SimpleAuth, SimpleAuthException, configure, defineConfig, stubsRoot };
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { ResolvedSimpleAuthConfig } from "../types.js";
|
|
2
|
+
import { HttpContext } from "@adonisjs/core/http";
|
|
3
|
+
import { NextFn } from "@adonisjs/core/types/http";
|
|
4
|
+
|
|
5
|
+
//#region src/middleware/simple_auth_middleware.d.ts
|
|
6
|
+
declare class SimpleAuthMiddleware {
|
|
7
|
+
protected config: ResolvedSimpleAuthConfig;
|
|
8
|
+
constructor(config: ResolvedSimpleAuthConfig);
|
|
9
|
+
handle(ctx: HttpContext, next: NextFn): Promise<unknown>;
|
|
10
|
+
}
|
|
11
|
+
//#endregion
|
|
12
|
+
export { SimpleAuthMiddleware as default };
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { SimpleAuth } from "../src/simple_auth.js";
|
|
2
|
+
//#region src/middleware/simple_auth_middleware.ts
|
|
3
|
+
var SimpleAuthMiddleware = class {
|
|
4
|
+
config;
|
|
5
|
+
constructor(config) {
|
|
6
|
+
this.config = config;
|
|
7
|
+
}
|
|
8
|
+
async handle(ctx, next) {
|
|
9
|
+
ctx.simpleAuth = new SimpleAuth(ctx, this.config);
|
|
10
|
+
return next();
|
|
11
|
+
}
|
|
12
|
+
};
|
|
13
|
+
//#endregion
|
|
14
|
+
export { SimpleAuthMiddleware as default };
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { ApplicationService } from "@adonisjs/core/types";
|
|
2
|
+
import { PluginFn } from "@japa/runner/types";
|
|
3
|
+
|
|
4
|
+
//#region src/plugins/japa/api_client.d.ts
|
|
5
|
+
declare const API_KEY_ENABLED: unique symbol;
|
|
6
|
+
declare module '@japa/api-client' {
|
|
7
|
+
interface ApiRequest {
|
|
8
|
+
[API_KEY_ENABLED]: boolean;
|
|
9
|
+
withApiKey: () => this;
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
declare const simpleAuthApiClient: (app: ApplicationService) => PluginFn;
|
|
13
|
+
//#endregion
|
|
14
|
+
export { simpleAuthApiClient };
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { configProvider } from "@adonisjs/core";
|
|
2
|
+
import { RuntimeException } from "@adonisjs/core/exceptions";
|
|
3
|
+
import { ApiClient, ApiRequest } from "@japa/api-client";
|
|
4
|
+
//#region src/plugins/japa/api_client.ts
|
|
5
|
+
const API_KEY_ENABLED = Symbol.for("API_KEY_ENABLED");
|
|
6
|
+
const simpleAuthApiClient = (app) => {
|
|
7
|
+
const pluginFn = async function() {
|
|
8
|
+
const simpleAuthConfigProvider = app.config.get("simpleauth");
|
|
9
|
+
const config = await configProvider.resolve(app, simpleAuthConfigProvider);
|
|
10
|
+
if (!config) throw new RuntimeException("Invalid \"config/simpleauth.ts\" file. Make sure you are using the \"defineConfig\" method");
|
|
11
|
+
ApiRequest.macro("withApiKey", function() {
|
|
12
|
+
this[API_KEY_ENABLED] = true;
|
|
13
|
+
return this;
|
|
14
|
+
});
|
|
15
|
+
ApiClient.setup(async (request) => {
|
|
16
|
+
if (!request[API_KEY_ENABLED]) return;
|
|
17
|
+
request.header(config.apiKeyHeader, config.apiKeyValue.release());
|
|
18
|
+
});
|
|
19
|
+
};
|
|
20
|
+
return pluginFn;
|
|
21
|
+
};
|
|
22
|
+
//#endregion
|
|
23
|
+
export { simpleAuthApiClient };
|
|
@@ -1,15 +1,19 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { SimpleAuth } from "../src/simple_auth.js";
|
|
2
|
+
import { ApplicationService } from "@adonisjs/core/types";
|
|
3
|
+
|
|
4
|
+
//#region providers/simple_auth_provider.d.ts
|
|
3
5
|
/**
|
|
4
6
|
* HttpContext augmentations
|
|
5
7
|
*/
|
|
6
8
|
declare module '@adonisjs/core/http' {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
9
|
+
interface HttpContext {
|
|
10
|
+
simpleAuth: SimpleAuth;
|
|
11
|
+
}
|
|
10
12
|
}
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
13
|
+
declare class SimpleAuthProvider {
|
|
14
|
+
protected app: ApplicationService;
|
|
15
|
+
constructor(app: ApplicationService);
|
|
16
|
+
register(): void;
|
|
15
17
|
}
|
|
18
|
+
//#endregion
|
|
19
|
+
export { SimpleAuthProvider as default };
|