@aenode/nest-auth 0.0.0-stage → 0.0.37
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/README.md +24 -2
- package/assets/favicon.svg +1 -0
- package/bin/nest-auth.mjs +3 -0
- package/dist/index.js +3 -0
- package/dist/index.js.map +1 -0
- package/dist/lib/guards/auth.guard.js +33 -0
- package/dist/lib/guards/auth.guard.js.map +1 -0
- package/dist/lib/index.js +7 -0
- package/dist/lib/index.js.map +1 -0
- package/dist/lib/nest-auth.js +5 -0
- package/dist/lib/nest-auth.js.map +1 -0
- package/dist/lib/utils/extract-bearer-token.js +19 -0
- package/dist/lib/utils/extract-bearer-token.js.map +1 -0
- package/dist/lib/utils/index.js +4 -0
- package/dist/lib/utils/index.js.map +1 -0
- package/dist/main.js +4 -0
- package/dist/main.js.map +1 -0
- package/package.json +63 -4
package/README.md
CHANGED
|
@@ -1,3 +1,25 @@
|
|
|
1
|
-
|
|
1
|
+
   
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
<p align="center">
|
|
4
|
+
<img src="https://aenode.github.io/aenode/libs/nest-auth/assets/favicon.svg" alt="aenode Logo" height="128" width="128" style="border-radius: 32px;"/>
|
|
5
|
+
</p>
|
|
6
|
+
|
|
7
|
+
## @aenode/nest-auth
|
|
8
|
+
|
|
9
|
+
- [ ] Add project description
|
|
10
|
+
|
|
11
|
+
## Install
|
|
12
|
+
|
|
13
|
+
```sh
|
|
14
|
+
bun add @aenode/nest-auth
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
## Examples
|
|
18
|
+
|
|
19
|
+
```ts
|
|
20
|
+
const message = 'Hello there';
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
---
|
|
24
|
+
|
|
25
|
+
[](https://cash.app/$puqlib) [](mailto:aenode+aenode+aenode-nest-auth@proton.me)
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 48 48" height="48px" width="48px" fill="#5985E1"><path d="M22.93,41.57Q22.5,41.14 22.5,40.5V27.6l-9.1,9.1q-0.44,0.45-1.04,0.45T11.3,36.71t-0.45-1.05T11.3,34.6l9.1-9.1H7.5q-0.64,0-1.07-0.43T6,23.99t0.43-1.07T7.5,22.5H20.45L11.3,13.35q-0.45-0.44-0.45-1.05t0.44-1.05t1.05-0.45t1.06,0.45l9.1,9.1V7.5q0-0.64 0.43-1.07T24.01,6t1.07,0.43T25.5,7.5V20.4l9.15-9.15q0.44-0.45 1.05-0.45t1.05,0.44t0.45,1.05t-0.45,1.06L27.6,22.5H40.5q0.64,0 1.07,0.43T42,24.01t-0.43,1.07T40.5,25.5H27.65l9.1,9.1q0.45,0.44 0.45,1.04T36.76,36.7t-1.05,0.45T34.65,36.7L25.5,27.55V40.5q0,0.64-0.43,1.07T23.99,42t-1.07-0.43Z"/></svg>
|
package/dist/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["export * from './lib/index.js';\n"],"names":[],"mappings":"AAAA,cAAc,iBAAiB"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { _ as _ts_decorate } from "@swc/helpers/_/_ts_decorate";
|
|
2
|
+
import { _ as _ts_metadata } from "@swc/helpers/_/_ts_metadata";
|
|
3
|
+
import { isPublic } from '@aenode/nest-decorators';
|
|
4
|
+
import { Injectable, Scope, UnauthorizedException } from '@aenode/nest/common';
|
|
5
|
+
import { extractBearerToken } from '../utils/index.js';
|
|
6
|
+
export class AuthGuard {
|
|
7
|
+
constructor(reflector){
|
|
8
|
+
this.reflector = reflector;
|
|
9
|
+
}
|
|
10
|
+
async canActivate(context) {
|
|
11
|
+
const req = context.switchToHttp().getRequest();
|
|
12
|
+
const isPublicResource = isPublic(context, this.reflector);
|
|
13
|
+
if (isPublicResource) {
|
|
14
|
+
return true;
|
|
15
|
+
}
|
|
16
|
+
const token = extractBearerToken(req);
|
|
17
|
+
if (!token) {
|
|
18
|
+
throw new UnauthorizedException('Authentication token is not provided');
|
|
19
|
+
}
|
|
20
|
+
return true;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
AuthGuard = _ts_decorate([
|
|
24
|
+
Injectable({
|
|
25
|
+
scope: Scope.REQUEST
|
|
26
|
+
}),
|
|
27
|
+
_ts_metadata("design:type", Function),
|
|
28
|
+
_ts_metadata("design:paramtypes", [
|
|
29
|
+
typeof Reflector === "undefined" ? Object : Reflector
|
|
30
|
+
])
|
|
31
|
+
], AuthGuard);
|
|
32
|
+
|
|
33
|
+
//# sourceMappingURL=auth.guard.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/lib/guards/auth.guard.ts"],"sourcesContent":["import { isPublic } from '@aenode/nest-decorators';\nimport {\n Injectable,\n Scope,\n UnauthorizedException,\n type CanActivate,\n type ExecutionContext,\n} from '@aenode/nest/common';\nimport type { Reflector } from '@aenode/nest/core';\nimport { type Request } from '@aenode/nest/express';\nimport { type ExtendedRequest } from '@aenode/types';\nimport { extractBearerToken } from '../utils/index.js';\n\n/**\n * Check the target resource is public or check the user is authenciated and save the user information to the `request.user`.\n *\n */\n@Injectable({ scope: Scope.REQUEST })\nexport class AuthGuard implements CanActivate {\n constructor(protected readonly reflector: Reflector) {}\n\n async canActivate(context: ExecutionContext): Promise<boolean> {\n const req = context.switchToHttp().getRequest<ExtendedRequest & Request>();\n\n const isPublicResource = isPublic(context, this.reflector);\n\n if (isPublicResource) {\n return true;\n }\n\n const token = extractBearerToken(req);\n\n if (!token) {\n throw new UnauthorizedException('Authentication token is not provided');\n }\n\n return true;\n }\n}\n"],"names":["isPublic","Injectable","Scope","UnauthorizedException","extractBearerToken","AuthGuard","reflector","canActivate","context","req","switchToHttp","getRequest","isPublicResource","token","scope","REQUEST"],"mappings":";;AAAA,SAASA,QAAQ,QAAQ,0BAA0B;AACnD,SACEC,UAAU,EACVC,KAAK,EACLC,qBAAqB,QAGhB,sBAAsB;AAI7B,SAASC,kBAAkB,QAAQ,oBAAoB;AAOvD,OAAO,MAAMC;IACX,YAAY,AAAmBC,SAAoB,CAAE;aAAtBA,YAAAA;IAAuB;IAEtD,MAAMC,YAAYC,OAAyB,EAAoB;QAC7D,MAAMC,MAAMD,QAAQE,YAAY,GAAGC,UAAU;QAE7C,MAAMC,mBAAmBZ,SAASQ,SAAS,IAAI,CAACF,SAAS;QAEzD,IAAIM,kBAAkB;YACpB,OAAO;QACT;QAEA,MAAMC,QAAQT,mBAAmBK;QAEjC,IAAI,CAACI,OAAO;YACV,MAAM,IAAIV,sBAAsB;QAClC;QAEA,OAAO;IACT;AACF;;;QArBcW,OAAOZ,MAAMa,OAAO"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
// @index(['./**/*.ts', '!./**/*.spec.ts','!./**/index.ts', '!./**/_*.ts','!./**/{main,bootstrap}.ts', '!./**/generated/**'], f => `export * from '${f.path}.js'`)
|
|
2
|
+
export * from './guards/auth.guard.js';
|
|
3
|
+
export * from './meta/public.js';
|
|
4
|
+
export * from './nest-auth.js';
|
|
5
|
+
export * from './utils/extract-bearer-token.js';
|
|
6
|
+
|
|
7
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/lib/index.ts"],"sourcesContent":["// @index(['./**/*.ts', '!./**/*.spec.ts','!./**/index.ts', '!./**/_*.ts','!./**/{main,bootstrap}.ts', '!./**/generated/**'], f => `export * from '${f.path}.js'`)\nexport * from './guards/auth.guard.js';\nexport * from './meta/public.js';\nexport * from './nest-auth.js';\nexport * from './utils/extract-bearer-token.js';\n"],"names":[],"mappings":"AAAA,kKAAkK;AAClK,cAAc,yBAAyB;AACvC,cAAc,mBAAmB;AACjC,cAAc,iBAAiB;AAC/B,cAAc,kCAAkC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/lib/nest-auth.ts"],"sourcesContent":["export function nestAuth() {\n return 'nest-auth';\n}\n"],"names":["nestAuth"],"mappings":"AAAA,OAAO,SAASA;IACd,OAAO;AACT"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { UnauthorizedException } from '@aenode/nest/common';
|
|
2
|
+
/**
|
|
3
|
+
* Extract the bearer token from the authorization header, validate, and return.
|
|
4
|
+
*
|
|
5
|
+
* @param request Express request
|
|
6
|
+
* @returns authentication token
|
|
7
|
+
*/ export function extractBearerToken(request) {
|
|
8
|
+
const bearerRaw = request.headers.authorization;
|
|
9
|
+
if (!bearerRaw) {
|
|
10
|
+
throw new UnauthorizedException('Bearer token is not provided');
|
|
11
|
+
}
|
|
12
|
+
const [type, token] = bearerRaw.split(' ');
|
|
13
|
+
if (type !== 'Bearer' || !token) {
|
|
14
|
+
throw new UnauthorizedException('Invalid bearer format');
|
|
15
|
+
}
|
|
16
|
+
return token;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
//# sourceMappingURL=extract-bearer-token.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/lib/utils/extract-bearer-token.ts"],"sourcesContent":["import { UnauthorizedException } from '@aenode/nest/common';\nimport type { Request } from '@aenode/nest/express';\nimport type { ExtendedRequest } from '@aenode/types';\n\n/**\n * Extract the bearer token from the authorization header, validate, and return.\n *\n * @param request Express request\n * @returns authentication token\n */\nexport function extractBearerToken(request: ExtendedRequest & Request) {\n const bearerRaw = request.headers.authorization;\n\n if (!bearerRaw) {\n throw new UnauthorizedException('Bearer token is not provided');\n }\n\n const [type, token] = bearerRaw.split(' ');\n\n if (type !== 'Bearer' || !token) {\n throw new UnauthorizedException('Invalid bearer format');\n }\n\n return token;\n}\n"],"names":["UnauthorizedException","extractBearerToken","request","bearerRaw","headers","authorization","type","token","split"],"mappings":"AAAA,SAASA,qBAAqB,QAAQ,sBAAsB;AAI5D;;;;;CAKC,GACD,OAAO,SAASC,mBAAmBC,OAAkC;IACnE,MAAMC,YAAYD,QAAQE,OAAO,CAACC,aAAa;IAE/C,IAAI,CAACF,WAAW;QACd,MAAM,IAAIH,sBAAsB;IAClC;IAEA,MAAM,CAACM,MAAMC,MAAM,GAAGJ,UAAUK,KAAK,CAAC;IAEtC,IAAIF,SAAS,YAAY,CAACC,OAAO;QAC/B,MAAM,IAAIP,sBAAsB;IAClC;IAEA,OAAOO;AACT"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/lib/utils/index.ts"],"sourcesContent":["// @index(['./**/*.ts', '!./**/*.spec.ts','!./**/index.ts', '!./**/_*.ts','!./**/main.ts', '!./**/generated/**'], f => `export * from '${f.path}.js'`)\nexport * from './extract-bearer-token.js';\n"],"names":[],"mappings":"AAAA,sJAAsJ;AACtJ,cAAc,4BAA4B"}
|
package/dist/main.js
ADDED
package/dist/main.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/main.ts"],"sourcesContent":["#!/usr/bin/env node\n\nconsole.log(`Hello from @aenode/nest-auth`);\n"],"names":["console","log"],"mappings":";AAEAA,QAAQC,GAAG,CAAC,CAAC,4BAA4B,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,65 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aenode/nest-auth",
|
|
3
|
-
"version": "0.0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.0.37",
|
|
4
|
+
"description": "Nest auth module",
|
|
5
|
+
"author": {
|
|
6
|
+
"name": "Ahmet Emrebas",
|
|
7
|
+
"email": "aenode+aenode+aenode-nest-auth@proton.me",
|
|
8
|
+
"url": "https://aenode.github.io/#profile"
|
|
9
|
+
},
|
|
10
|
+
"bin": {
|
|
11
|
+
"aenode-nest-auth": "./bin/nest-auth.mjs"
|
|
12
|
+
},
|
|
13
|
+
"funding": "https://cash.app/$puqlib",
|
|
14
|
+
"homepage": "https://aenode.github.io/aenode/libs/nest-auth",
|
|
15
|
+
"repository": {
|
|
16
|
+
"directory": "libs/nest-auth",
|
|
17
|
+
"type": "github",
|
|
18
|
+
"url": "https://github.com/aenode/aenode/tree/main/libs/nest-auth"
|
|
19
|
+
},
|
|
20
|
+
"icon": "https://aenode.github.io/aenode/libs/nest-auth/assets/favicon.svg",
|
|
21
|
+
"keywords": [
|
|
22
|
+
"lib"
|
|
23
|
+
],
|
|
24
|
+
"publishConfig": {
|
|
25
|
+
"access": "public",
|
|
26
|
+
"tag": "latest"
|
|
27
|
+
},
|
|
28
|
+
"type": "module",
|
|
29
|
+
"main": "./dist/index.js",
|
|
30
|
+
"module": "./dist/index.js",
|
|
31
|
+
"types": "./dist/index.d.ts",
|
|
32
|
+
"exports": {
|
|
33
|
+
"./package.json": "./package.json",
|
|
34
|
+
".": {
|
|
35
|
+
"bun": "./src/index.ts",
|
|
36
|
+
"types": "./dist/index.d.ts",
|
|
37
|
+
"import": "./dist/index.js",
|
|
38
|
+
"default": "./dist/index.js"
|
|
39
|
+
}
|
|
40
|
+
},
|
|
41
|
+
"files": [
|
|
42
|
+
"assets",
|
|
43
|
+
"bin",
|
|
44
|
+
"dist",
|
|
45
|
+
"generators.json",
|
|
46
|
+
"!**/*.tsbuildinfo"
|
|
47
|
+
],
|
|
48
|
+
"nx": {
|
|
49
|
+
"sourceRoot": "libs/nest-auth/src",
|
|
50
|
+
"projectType": "library",
|
|
51
|
+
"tags": [
|
|
52
|
+
"lib:module"
|
|
53
|
+
],
|
|
54
|
+
"targets": {
|
|
55
|
+
"build": {},
|
|
56
|
+
"doc": {}
|
|
57
|
+
}
|
|
58
|
+
},
|
|
59
|
+
"dependencies": {
|
|
60
|
+
"@aenode/nest": "workspace:*",
|
|
61
|
+
"@aenode/nest-decorators": "workspace:*",
|
|
62
|
+
"@aenode/types": "workspace:*",
|
|
63
|
+
"@swc/helpers": "~0.5.18"
|
|
64
|
+
}
|
|
65
|
+
}
|