@eienjs/adonisjs-simple-auth 1.0.0-0 → 1.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/chunk-JUF7K25A.js +80 -0
- package/build/chunk-JUF7K25A.js.map +1 -0
- package/build/{chunk-QSRPDOI7.js → chunk-TVVNPJ4M.js} +2 -2
- package/build/index.js +1 -1
- package/build/metafile-esm.json +1 -1
- package/build/providers/simple_auth_provider.js +2 -2
- package/build/src/errors.d.ts +14 -2
- package/build/src/middleware/simple_auth_middleware.js +2 -2
- package/package.json +3 -2
- package/build/chunk-UBUHVXKH.js +0 -37
- package/build/chunk-UBUHVXKH.js.map +0 -1
- /package/build/{chunk-QSRPDOI7.js.map → chunk-TVVNPJ4M.js.map} +0 -0
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
// src/errors.ts
|
|
2
|
+
import { Exception } from "@adonisjs/core/exceptions";
|
|
3
|
+
var SimpleAuthException = class _SimpleAuthException extends Exception {
|
|
4
|
+
static code = "E_SIMPLE_UNAUTHORIZED_ACCESS";
|
|
5
|
+
static status = 401;
|
|
6
|
+
/**
|
|
7
|
+
* Translation identifier. Can be customized
|
|
8
|
+
*/
|
|
9
|
+
identifier = `errors.${_SimpleAuthException.code}`;
|
|
10
|
+
/**
|
|
11
|
+
* Returns the message to be sent in the HTTP response.
|
|
12
|
+
* Feel free to override this method and return a custom
|
|
13
|
+
* response.
|
|
14
|
+
*/
|
|
15
|
+
getResponseMessage(error, ctx) {
|
|
16
|
+
if ("i18n" in ctx) {
|
|
17
|
+
return ctx.i18n.t(error.identifier, {}, error.message);
|
|
18
|
+
}
|
|
19
|
+
return error.message;
|
|
20
|
+
}
|
|
21
|
+
async handle(error, ctx) {
|
|
22
|
+
const message = this.getResponseMessage(error, ctx);
|
|
23
|
+
switch (ctx.request.accepts(["html", "application/vnd.api+json", "json"])) {
|
|
24
|
+
case "html":
|
|
25
|
+
case null:
|
|
26
|
+
case "json": {
|
|
27
|
+
ctx.response.status(error.status).send({
|
|
28
|
+
errors: [
|
|
29
|
+
{
|
|
30
|
+
message
|
|
31
|
+
}
|
|
32
|
+
]
|
|
33
|
+
});
|
|
34
|
+
break;
|
|
35
|
+
}
|
|
36
|
+
case "application/vnd.api+json": {
|
|
37
|
+
ctx.response.status(error.status).send({
|
|
38
|
+
errors: [
|
|
39
|
+
{
|
|
40
|
+
code: error.code,
|
|
41
|
+
title: message
|
|
42
|
+
}
|
|
43
|
+
]
|
|
44
|
+
});
|
|
45
|
+
break;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
// src/simple_auth.ts
|
|
52
|
+
var SimpleAuth = class {
|
|
53
|
+
constructor(ctx, config) {
|
|
54
|
+
this.ctx = ctx;
|
|
55
|
+
this.config = config;
|
|
56
|
+
}
|
|
57
|
+
authenticationFailed() {
|
|
58
|
+
return new SimpleAuthException("Unauthorized access");
|
|
59
|
+
}
|
|
60
|
+
getApiKeyRequest() {
|
|
61
|
+
const apiKey = this.ctx.request.header(this.config.apiKeyHeader, "");
|
|
62
|
+
if (!apiKey.trim()) {
|
|
63
|
+
throw this.authenticationFailed();
|
|
64
|
+
}
|
|
65
|
+
return apiKey;
|
|
66
|
+
}
|
|
67
|
+
authenticate() {
|
|
68
|
+
const apiKeyTokenRequest = this.getApiKeyRequest();
|
|
69
|
+
const apiKeyTokenConfig = this.config.apiKeyValue;
|
|
70
|
+
if (apiKeyTokenRequest !== apiKeyTokenConfig.release()) {
|
|
71
|
+
throw this.authenticationFailed();
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
};
|
|
75
|
+
|
|
76
|
+
export {
|
|
77
|
+
SimpleAuthException,
|
|
78
|
+
SimpleAuth
|
|
79
|
+
};
|
|
80
|
+
//# sourceMappingURL=chunk-JUF7K25A.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/errors.ts","../src/simple_auth.ts"],"sourcesContent":["import { Exception } from '@adonisjs/core/exceptions';\nimport { type HttpContext } from '@adonisjs/core/http';\nimport { type I18n } from '@adonisjs/i18n';\n\nexport class SimpleAuthException extends Exception {\n public static readonly code = 'E_SIMPLE_UNAUTHORIZED_ACCESS';\n\n public static readonly status = 401;\n\n /**\n * Translation identifier. Can be customized\n */\n public identifier = `errors.${SimpleAuthException.code}`;\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 public getResponseMessage(error: this, ctx: HttpContext): string {\n if ('i18n' in ctx) {\n return (ctx.i18n as I18n).t(error.identifier, {}, error.message);\n }\n\n return error.message;\n }\n\n public async handle(error: this, ctx: HttpContext): Promise<void> {\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 case 'json': {\n ctx.response.status(error.status).send({\n errors: [\n {\n message,\n },\n ],\n });\n break;\n }\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","import { type HttpContext } from '@adonisjs/core/http';\nimport { SimpleAuthException } from './errors.js';\nimport { type ResolvedSimpleAuthConfig } from './types.js';\n\nexport class SimpleAuth {\n public constructor(\n protected ctx: HttpContext,\n protected config: ResolvedSimpleAuthConfig,\n ) {}\n\n protected authenticationFailed(): SimpleAuthException {\n return new SimpleAuthException('Unauthorized access');\n }\n\n protected getApiKeyRequest(): string {\n const apiKey = this.ctx.request.header(this.config.apiKeyHeader, '')!;\n if (!apiKey.trim()) {\n throw this.authenticationFailed();\n }\n\n return apiKey;\n }\n\n public authenticate(): void {\n const apiKeyTokenRequest = this.getApiKeyRequest();\n const apiKeyTokenConfig = this.config.apiKeyValue;\n\n if (apiKeyTokenRequest !== apiKeyTokenConfig.release()) {\n throw this.authenticationFailed();\n }\n }\n}\n"],"mappings":";AAAA,SAAS,iBAAiB;AAInB,IAAM,sBAAN,MAAM,6BAA4B,UAAU;AAAA,EACjD,OAAuB,OAAO;AAAA,EAE9B,OAAuB,SAAS;AAAA;AAAA;AAAA;AAAA,EAKzB,aAAa,UAAU,qBAAoB,IAAI;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAO/C,mBAAmB,OAAa,KAA0B;AAC/D,QAAI,UAAU,KAAK;AACjB,aAAQ,IAAI,KAAc,EAAE,MAAM,YAAY,CAAC,GAAG,MAAM,OAAO;AAAA,IACjE;AAEA,WAAO,MAAM;AAAA,EACf;AAAA,EAEA,MAAa,OAAO,OAAa,KAAiC;AAChE,UAAM,UAAU,KAAK,mBAAmB,OAAO,GAAG;AAElD,YAAQ,IAAI,QAAQ,QAAQ,CAAC,QAAQ,4BAA4B,MAAM,CAAC,GAAG;AAAA,MACzE,KAAK;AAAA,MACL,KAAK;AAAA,MACL,KAAK,QAAQ;AACX,YAAI,SAAS,OAAO,MAAM,MAAM,EAAE,KAAK;AAAA,UACrC,QAAQ;AAAA,YACN;AAAA,cACE;AAAA,YACF;AAAA,UACF;AAAA,QACF,CAAC;AACD;AAAA,MACF;AAAA,MACA,KAAK,4BAA4B;AAC/B,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,MACF;AAAA,IACF;AAAA,EACF;AACF;;;ACpDO,IAAM,aAAN,MAAiB;AAAA,EACf,YACK,KACA,QACV;AAFU;AACA;AAAA,EACT;AAAA,EAEO,uBAA4C;AACpD,WAAO,IAAI,oBAAoB,qBAAqB;AAAA,EACtD;AAAA,EAEU,mBAA2B;AACnC,UAAM,SAAS,KAAK,IAAI,QAAQ,OAAO,KAAK,OAAO,cAAc,EAAE;AACnE,QAAI,CAAC,OAAO,KAAK,GAAG;AAClB,YAAM,KAAK,qBAAqB;AAAA,IAClC;AAEA,WAAO;AAAA,EACT;AAAA,EAEO,eAAqB;AAC1B,UAAM,qBAAqB,KAAK,iBAAiB;AACjD,UAAM,oBAAoB,KAAK,OAAO;AAEtC,QAAI,uBAAuB,kBAAkB,QAAQ,GAAG;AACtD,YAAM,KAAK,qBAAqB;AAAA,IAClC;AAAA,EACF;AACF;","names":[]}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import {
|
|
2
2
|
SimpleAuth
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-JUF7K25A.js";
|
|
4
4
|
|
|
5
5
|
// src/middleware/simple_auth_middleware.ts
|
|
6
6
|
var SimpleAuthMiddleware = class {
|
|
@@ -16,4 +16,4 @@ var SimpleAuthMiddleware = class {
|
|
|
16
16
|
export {
|
|
17
17
|
SimpleAuthMiddleware
|
|
18
18
|
};
|
|
19
|
-
//# sourceMappingURL=chunk-
|
|
19
|
+
//# sourceMappingURL=chunk-TVVNPJ4M.js.map
|
package/build/index.js
CHANGED
package/build/metafile-esm.json
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"inputs":{"stubs/main.ts":{"bytes":233,"imports":[{"path":"@adonisjs/core/helpers","kind":"import-statement","external":true}],"format":"esm"},"configure.ts":{"bytes":995,"imports":[{"path":"stubs/main.ts","kind":"import-statement","original":"./stubs/main.js"}],"format":"esm"},"src/define_config.ts":{"bytes":526,"imports":[{"path":"@adonisjs/core","kind":"import-statement","external":true},{"path":"@adonisjs/core/helpers","kind":"import-statement","external":true},{"path":"@adonisjs/core/types","kind":"import-statement","external":true},{"path":"./types.js","kind":"import-statement","external":true}],"format":"esm"},"src/errors.ts":{"bytes":
|
|
1
|
+
{"inputs":{"stubs/main.ts":{"bytes":233,"imports":[{"path":"@adonisjs/core/helpers","kind":"import-statement","external":true}],"format":"esm"},"configure.ts":{"bytes":995,"imports":[{"path":"stubs/main.ts","kind":"import-statement","original":"./stubs/main.js"}],"format":"esm"},"src/define_config.ts":{"bytes":526,"imports":[{"path":"@adonisjs/core","kind":"import-statement","external":true},{"path":"@adonisjs/core/helpers","kind":"import-statement","external":true},{"path":"@adonisjs/core/types","kind":"import-statement","external":true},{"path":"./types.js","kind":"import-statement","external":true}],"format":"esm"},"src/errors.ts":{"bytes":1478,"imports":[{"path":"@adonisjs/core/exceptions","kind":"import-statement","external":true},{"path":"@adonisjs/core/http","kind":"import-statement","external":true},{"path":"@adonisjs/i18n","kind":"import-statement","external":true}],"format":"esm"},"src/simple_auth.ts":{"bytes":899,"imports":[{"path":"@adonisjs/core/http","kind":"import-statement","external":true},{"path":"src/errors.ts","kind":"import-statement","original":"./errors.js"},{"path":"./types.js","kind":"import-statement","external":true}],"format":"esm"},"index.ts":{"bytes":250,"imports":[{"path":"configure.ts","kind":"import-statement","original":"./configure.js"},{"path":"src/define_config.ts","kind":"import-statement","original":"./src/define_config.js"},{"path":"src/errors.ts","kind":"import-statement","original":"./src/errors.js"},{"path":"src/simple_auth.ts","kind":"import-statement","original":"./src/simple_auth.js"},{"path":"stubs/main.ts","kind":"import-statement","original":"./stubs/main.js"}],"format":"esm"},"src/helpers/crc32.ts":{"bytes":4896,"imports":[{"path":"node:util","kind":"import-statement","external":true}],"format":"esm"},"commands/generate_api_key.ts":{"bytes":1616,"imports":[{"path":"node:process","kind":"import-statement","external":true},{"path":"@adonisjs/core/ace","kind":"import-statement","external":true},{"path":"@adonisjs/core/env/editor","kind":"import-statement","external":true},{"path":"@adonisjs/core/helpers","kind":"import-statement","external":true},{"path":"@adonisjs/core/helpers/string","kind":"import-statement","external":true},{"path":"src/helpers/crc32.ts","kind":"import-statement","original":"../src/helpers/crc32.js"},{"path":"<runtime>","kind":"import-statement","external":true}],"format":"esm"},"src/middleware/simple_auth_middleware.ts":{"bytes":473,"imports":[{"path":"@adonisjs/core/http","kind":"import-statement","external":true},{"path":"@adonisjs/core/types/http","kind":"import-statement","external":true},{"path":"src/simple_auth.ts","kind":"import-statement","original":"../simple_auth.js"},{"path":"../types.js","kind":"import-statement","external":true}],"format":"esm"},"providers/simple_auth_provider.ts":{"bytes":1187,"imports":[{"path":"@adonisjs/core","kind":"import-statement","external":true},{"path":"@adonisjs/core/exceptions","kind":"import-statement","external":true},{"path":"@adonisjs/core/types","kind":"import-statement","external":true},{"path":"src/middleware/simple_auth_middleware.ts","kind":"import-statement","original":"../src/middleware/simple_auth_middleware.js"},{"path":"../src/simple_auth.js","kind":"import-statement","external":true},{"path":"../src/types.js","kind":"import-statement","external":true}],"format":"esm"},"src/types.ts":{"bytes":241,"imports":[{"path":"@adonisjs/core/helpers","kind":"import-statement","external":true}],"format":"esm"},"src/plugins/japa/api_client.ts":{"bytes":1434,"imports":[{"path":"@adonisjs/core","kind":"import-statement","external":true},{"path":"@adonisjs/core/exceptions","kind":"import-statement","external":true},{"path":"@adonisjs/core/types","kind":"import-statement","external":true},{"path":"@japa/api-client","kind":"import-statement","external":true},{"path":"@japa/runner/types","kind":"import-statement","external":true},{"path":"../../types.js","kind":"import-statement","external":true}],"format":"esm"}},"outputs":{"build/index.js.map":{"imports":[],"exports":[],"inputs":{},"bytes":2665},"build/index.js":{"imports":[{"path":"build/chunk-JUF7K25A.js","kind":"import-statement"},{"path":"build/chunk-EUXUH3YW.js","kind":"import-statement"},{"path":"@adonisjs/core/helpers","kind":"import-statement","external":true},{"path":"@adonisjs/core","kind":"import-statement","external":true},{"path":"@adonisjs/core/helpers","kind":"import-statement","external":true}],"exports":["SimpleAuth","SimpleAuthException","configure","defineConfig","stubsRoot"],"entryPoint":"index.ts","inputs":{"stubs/main.ts":{"bytesInOutput":98},"configure.ts":{"bytesInOutput":726},"index.ts":{"bytesInOutput":0},"src/define_config.ts":{"bytesInOutput":312}},"bytes":1391},"build/commands/generate_api_key.js.map":{"imports":[],"exports":[],"inputs":{},"bytes":11126},"build/commands/generate_api_key.js":{"imports":[{"path":"build/chunk-EUXUH3YW.js","kind":"import-statement"},{"path":"node:process","kind":"import-statement","external":true},{"path":"@adonisjs/core/ace","kind":"import-statement","external":true},{"path":"@adonisjs/core/env/editor","kind":"import-statement","external":true},{"path":"@adonisjs/core/helpers","kind":"import-statement","external":true},{"path":"@adonisjs/core/helpers/string","kind":"import-statement","external":true},{"path":"node:util","kind":"import-statement","external":true}],"exports":["default"],"entryPoint":"commands/generate_api_key.ts","inputs":{"commands/generate_api_key.ts":{"bytesInOutput":1557},"src/helpers/crc32.ts":{"bytesInOutput":5029}},"bytes":6775},"build/providers/simple_auth_provider.js.map":{"imports":[],"exports":[],"inputs":{},"bytes":1739},"build/providers/simple_auth_provider.js":{"imports":[{"path":"build/chunk-TVVNPJ4M.js","kind":"import-statement"},{"path":"build/chunk-JUF7K25A.js","kind":"import-statement"},{"path":"build/chunk-EUXUH3YW.js","kind":"import-statement"},{"path":"@adonisjs/core","kind":"import-statement","external":true},{"path":"@adonisjs/core/exceptions","kind":"import-statement","external":true}],"exports":["default"],"entryPoint":"providers/simple_auth_provider.ts","inputs":{"providers/simple_auth_provider.ts":{"bytesInOutput":671}},"bytes":878},"build/src/types.js.map":{"imports":[],"exports":[],"inputs":{},"bytes":93},"build/src/types.js":{"imports":[],"exports":[],"entryPoint":"src/types.ts","inputs":{"src/types.ts":{"bytesInOutput":0}},"bytes":0},"build/src/middleware/simple_auth_middleware.js.map":{"imports":[],"exports":[],"inputs":{},"bytes":93},"build/src/middleware/simple_auth_middleware.js":{"imports":[{"path":"build/chunk-TVVNPJ4M.js","kind":"import-statement"},{"path":"build/chunk-JUF7K25A.js","kind":"import-statement"},{"path":"build/chunk-EUXUH3YW.js","kind":"import-statement"}],"exports":["default"],"entryPoint":"src/middleware/simple_auth_middleware.ts","inputs":{},"bytes":180},"build/chunk-TVVNPJ4M.js.map":{"imports":[],"exports":[],"inputs":{},"bytes":800},"build/chunk-TVVNPJ4M.js":{"imports":[{"path":"build/chunk-JUF7K25A.js","kind":"import-statement"}],"exports":["SimpleAuthMiddleware"],"inputs":{"src/middleware/simple_auth_middleware.ts":{"bytesInOutput":198}},"bytes":331},"build/chunk-JUF7K25A.js.map":{"imports":[],"exports":[],"inputs":{},"bytes":3865},"build/chunk-JUF7K25A.js":{"imports":[{"path":"@adonisjs/core/exceptions","kind":"import-statement","external":true}],"exports":["SimpleAuth","SimpleAuthException"],"inputs":{"src/errors.ts":{"bytesInOutput":1263},"src/simple_auth.ts":{"bytesInOutput":633}},"bytes":1985},"build/src/plugins/japa/api_client.js.map":{"imports":[],"exports":[],"inputs":{},"bytes":2170},"build/src/plugins/japa/api_client.js":{"imports":[{"path":"build/chunk-EUXUH3YW.js","kind":"import-statement"},{"path":"@adonisjs/core","kind":"import-statement","external":true},{"path":"@adonisjs/core/exceptions","kind":"import-statement","external":true},{"path":"@japa/api-client","kind":"import-statement","external":true}],"exports":["simpleAuthApiClient"],"entryPoint":"src/plugins/japa/api_client.ts","inputs":{"src/plugins/japa/api_client.ts":{"bytesInOutput":979}},"bytes":1085},"build/chunk-EUXUH3YW.js.map":{"imports":[],"exports":[],"inputs":{},"bytes":93},"build/chunk-EUXUH3YW.js":{"imports":[],"exports":["__decorateClass"],"inputs":{},"bytes":524}}}
|
package/build/src/errors.d.ts
CHANGED
|
@@ -1,5 +1,17 @@
|
|
|
1
1
|
import { Exception } from '@adonisjs/core/exceptions';
|
|
2
|
+
import { type HttpContext } from '@adonisjs/core/http';
|
|
2
3
|
export declare class SimpleAuthException extends Exception {
|
|
3
|
-
static readonly code
|
|
4
|
-
static readonly status
|
|
4
|
+
static readonly code = "E_SIMPLE_UNAUTHORIZED_ACCESS";
|
|
5
|
+
static readonly status = 401;
|
|
6
|
+
/**
|
|
7
|
+
* Translation identifier. Can be customized
|
|
8
|
+
*/
|
|
9
|
+
identifier: string;
|
|
10
|
+
/**
|
|
11
|
+
* Returns the message to be sent in the HTTP response.
|
|
12
|
+
* Feel free to override this method and return a custom
|
|
13
|
+
* response.
|
|
14
|
+
*/
|
|
15
|
+
getResponseMessage(error: this, ctx: HttpContext): string;
|
|
16
|
+
handle(error: this, ctx: HttpContext): Promise<void>;
|
|
5
17
|
}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@eienjs/adonisjs-simple-auth",
|
|
3
3
|
"description": "Single authentication api key that allows authenticate",
|
|
4
|
-
"version": "1.0.
|
|
4
|
+
"version": "1.0.1",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"module": "build/index.js",
|
|
7
7
|
"types": "build/index.d.ts",
|
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
"exports": {
|
|
14
14
|
".": "./build/index.js",
|
|
15
15
|
"./types": "./build/src/types.js",
|
|
16
|
-
"./commands": "./build/commands/
|
|
16
|
+
"./commands": "./build/commands/main.js",
|
|
17
17
|
"./commands/*": "./build/commands/*.js",
|
|
18
18
|
"./simple_auth_provider": "./build/providers/simple_auth_provider.js",
|
|
19
19
|
"./plugins/api_client": "./build/src/plugins/japa/api_client.js",
|
|
@@ -22,6 +22,7 @@
|
|
|
22
22
|
"devDependencies": {
|
|
23
23
|
"@adonisjs/assembler": "^7.8.2",
|
|
24
24
|
"@adonisjs/core": "^6.17.2",
|
|
25
|
+
"@adonisjs/i18n": "^2.2.0",
|
|
25
26
|
"@commitlint/cli": "^19.8.1",
|
|
26
27
|
"@commitlint/config-conventional": "^19.8.1",
|
|
27
28
|
"@japa/api-client": "^3.1.0",
|
package/build/chunk-UBUHVXKH.js
DELETED
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
// src/errors.ts
|
|
2
|
-
import { Exception } from "@adonisjs/core/exceptions";
|
|
3
|
-
var SimpleAuthException = class extends Exception {
|
|
4
|
-
static code;
|
|
5
|
-
static status;
|
|
6
|
-
};
|
|
7
|
-
|
|
8
|
-
// src/simple_auth.ts
|
|
9
|
-
var SimpleAuth = class {
|
|
10
|
-
constructor(ctx, config) {
|
|
11
|
-
this.ctx = ctx;
|
|
12
|
-
this.config = config;
|
|
13
|
-
}
|
|
14
|
-
authenticationFailed() {
|
|
15
|
-
return new SimpleAuthException("Unauthorized access");
|
|
16
|
-
}
|
|
17
|
-
getApiKeyRequest() {
|
|
18
|
-
const apiKey = this.ctx.request.header(this.config.apiKeyHeader, "");
|
|
19
|
-
if (!apiKey.trim()) {
|
|
20
|
-
throw this.authenticationFailed();
|
|
21
|
-
}
|
|
22
|
-
return apiKey;
|
|
23
|
-
}
|
|
24
|
-
authenticate() {
|
|
25
|
-
const apiKeyTokenRequest = this.getApiKeyRequest();
|
|
26
|
-
const apiKeyTokenConfig = this.config.apiKeyValue;
|
|
27
|
-
if (apiKeyTokenRequest !== apiKeyTokenConfig.release()) {
|
|
28
|
-
throw this.authenticationFailed();
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
};
|
|
32
|
-
|
|
33
|
-
export {
|
|
34
|
-
SimpleAuthException,
|
|
35
|
-
SimpleAuth
|
|
36
|
-
};
|
|
37
|
-
//# sourceMappingURL=chunk-UBUHVXKH.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/errors.ts","../src/simple_auth.ts"],"sourcesContent":["import { Exception } from '@adonisjs/core/exceptions';\n\nexport class SimpleAuthException extends Exception {\n public static readonly code: 'E_SIMPLE_UNAUTHORIZED_ACCESS';\n\n public static readonly status: 401;\n}\n","import { type HttpContext } from '@adonisjs/core/http';\nimport { SimpleAuthException } from './errors.js';\nimport { type ResolvedSimpleAuthConfig } from './types.js';\n\nexport class SimpleAuth {\n public constructor(\n protected ctx: HttpContext,\n protected config: ResolvedSimpleAuthConfig,\n ) {}\n\n protected authenticationFailed(): SimpleAuthException {\n return new SimpleAuthException('Unauthorized access');\n }\n\n protected getApiKeyRequest(): string {\n const apiKey = this.ctx.request.header(this.config.apiKeyHeader, '')!;\n if (!apiKey.trim()) {\n throw this.authenticationFailed();\n }\n\n return apiKey;\n }\n\n public authenticate(): void {\n const apiKeyTokenRequest = this.getApiKeyRequest();\n const apiKeyTokenConfig = this.config.apiKeyValue;\n\n if (apiKeyTokenRequest !== apiKeyTokenConfig.release()) {\n throw this.authenticationFailed();\n }\n }\n}\n"],"mappings":";AAAA,SAAS,iBAAiB;AAEnB,IAAM,sBAAN,cAAkC,UAAU;AAAA,EACjD,OAAuB;AAAA,EAEvB,OAAuB;AACzB;;;ACFO,IAAM,aAAN,MAAiB;AAAA,EACf,YACK,KACA,QACV;AAFU;AACA;AAAA,EACT;AAAA,EAEO,uBAA4C;AACpD,WAAO,IAAI,oBAAoB,qBAAqB;AAAA,EACtD;AAAA,EAEU,mBAA2B;AACnC,UAAM,SAAS,KAAK,IAAI,QAAQ,OAAO,KAAK,OAAO,cAAc,EAAE;AACnE,QAAI,CAAC,OAAO,KAAK,GAAG;AAClB,YAAM,KAAK,qBAAqB;AAAA,IAClC;AAEA,WAAO;AAAA,EACT;AAAA,EAEO,eAAqB;AAC1B,UAAM,qBAAqB,KAAK,iBAAiB;AACjD,UAAM,oBAAoB,KAAK,OAAO;AAEtC,QAAI,uBAAuB,kBAAkB,QAAQ,GAAG;AACtD,YAAM,KAAK,qBAAqB;AAAA,IAClC;AAAA,EACF;AACF;","names":[]}
|
|
File without changes
|