@antelopejs/auth-jwt 1.0.3 → 1.0.4

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 CHANGED
@@ -1,80 +1,154 @@
1
- ![Auth JWT](.github/social-card.png)
2
-
3
1
  # @antelopejs/auth-jwt
4
2
 
5
3
  <div align="center">
6
- <a href="https://www.npmjs.com/package/@antelopejs/auth-jwt"><img alt="NPM version" src="https://img.shields.io/npm/v/@antelopejs/auth-jwt.svg?style=for-the-badge&labelColor=000000"></a>
7
- <a href="./LICENSE"><img alt="License" src="https://img.shields.io/npm/l/@antelopejs/auth-jwt.svg?style=for-the-badge&labelColor=000000"></a>
4
+ <a href="https://www.npmjs.com/package/@antelopejs/auth-jwt"><img alt="npm" src="https://img.shields.io/npm/v/@antelopejs/auth-jwt?style=for-the-badge&labelColor=000000&color=000000"></a>
5
+ <a href="./LICENSE"><img alt="License" src="https://img.shields.io/npm/l/@antelopejs/auth-jwt?style=for-the-badge&labelColor=000000&color=000000"></a>
8
6
  <a href="https://discord.gg/sjK28QHrA7"><img src="https://img.shields.io/badge/Discord-18181B?logo=discord&style=for-the-badge&color=000000" alt="Discord"></a>
9
- <a href="https://antelopejs.com/modules/auth-jwt"><img src="https://img.shields.io/badge/Docs-18181B?style=for-the-badge&color=000000" alt="Documentation"></a>
7
+ <a href="https://interfaces.antelopejs.com/docs/auth/introduction"><img src="https://img.shields.io/badge/Docs-18181B?style=for-the-badge&color=000000" alt="Documentation"></a>
10
8
  </div>
11
9
 
12
- A flexible authentication and authorization module that implements the Auth interface of antelopejs with JWT.
10
+ The AntelopeJS authentication module: it signs and verifies the auth interface's tokens as JSON Web Tokens, with [`jsonwebtoken`](https://github.com/auth0/node-jsonwebtoken).
11
+
12
+ ## Interfaces
13
+
14
+ | Interface | Documentation |
15
+ | ---------------------------------------------------------------------------- | ---------------------------------------------------------------- |
16
+ | [`@antelopejs/interface-auth`](https://github.com/AntelopeJS/interface-auth) | [Auth](https://interfaces.antelopejs.com/docs/auth/introduction) |
17
+
18
+ The `@Authentication` decorator, custom auth decorators, token sources and cookies are documented on the interface pages. The module also depends on [`@antelopejs/interface-api`](https://interfaces.antelopejs.com/docs/api/introduction), implemented by [`@antelopejs/api`](https://github.com/AntelopeJS/api).
13
19
 
14
- ## Installation
20
+ ## Install
15
21
 
16
22
  ```bash
17
23
  ajs project modules add @antelopejs/auth-jwt
24
+ ajs project modules install
18
25
  ```
19
26
 
20
- ## Interfaces
27
+ `ajs project modules install` adds `@antelopejs/api` when no module of the project implements the API interface yet.
21
28
 
22
- This module implements the Auth interface it can be integrated with your application to handle user authentication, token generation, verification, and access control. The interface is installed separately to maintain modularity and minimize dependencies.
29
+ ## Configuration
23
30
 
24
- | Name | Install command | |
25
- | ------------- | --------------------------------------- | ------------------------------------------------------------- |
26
- | Auth | `ajs module imports add auth` | [Documentation](https://github.com/AntelopeJS/interface-auth) |
31
+ Sign with a shared secret:
32
+
33
+ ```typescript [antelope.config.ts]
34
+ import { defineConfig } from "@antelopejs/interface-core/config";
35
+
36
+ export default defineConfig({
37
+ name: "my-project",
38
+ modules: {
39
+ "auth-jwt": {
40
+ source: {
41
+ type: "package",
42
+ package: "@antelopejs/auth-jwt",
43
+ version: "^1.0.3",
44
+ },
45
+ config: {
46
+ secret: "change-me",
47
+ signOptions: { expiresIn: "1h" },
48
+ verifyOptions: { ignoreExpiration: false },
49
+ },
50
+ },
51
+ },
52
+ envOverrides: {
53
+ JWT_SECRET: "modules.auth-jwt.config.secret",
54
+ },
55
+ });
56
+ ```
27
57
 
28
- ## Configuration
58
+ Or with a key pair read from disk at startup:
59
+
60
+ ```typescript
61
+ config: {
62
+ signKey: "./keys/private.pem",
63
+ verifyKey: "./keys/public.pem",
64
+ signOptions: { algorithm: "RS256", expiresIn: "1h" },
65
+ verifyOptions: { algorithms: ["RS256"] },
66
+ },
67
+ ```
29
68
 
30
- The Auth module can be configured with the following options:
69
+ | Key | Description |
70
+ | --------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
71
+ | `secret` | Shared secret that signs and verifies tokens. Takes precedence over `signKey` and `verifyKey`. |
72
+ | `signKey` | Path of the private key file. Used with `verifyKey` when `secret` is not set. |
73
+ | `verifyKey` | Path of the public key file. |
74
+ | `signOptions` | Default [`jsonwebtoken` sign options](https://github.com/auth0/node-jsonwebtoken#jwtsignpayload-secretorprivatekey-options-callback). `SignRaw` options override `expiresIn` and `notBefore`. |
75
+ | `verifyOptions` | Default [`jsonwebtoken` verify options](https://github.com/auth0/node-jsonwebtoken#jwtverifytoken-secretorpublickey-options-callback). |
31
76
 
32
- ```json
33
- {
34
- "secret": "your-secret-key",
35
- "signKey": "path-to-private-key-file",
36
- "verifyKey": "path-to-public-key-file",
37
- "signOptions": {
38
- "expiresIn": "1h",
39
- "algorithm": "RS256"
40
- },
41
- "verifyOptions": {
42
- "ignoreExpiration": false,
43
- "algorithms": ["RS256"]
77
+ The module refuses to start without `secret` or both `signKey` and `verifyKey`. `ajs project modules add` writes `secret: "your-secret-key"`: replace it before deploying.
78
+
79
+ ## Quick start
80
+
81
+ In the module that serves the routes, add both interfaces:
82
+
83
+ ```bash
84
+ pnpm add @antelopejs/interface-api @antelopejs/interface-auth
85
+ ```
86
+
87
+ Issue a token as a cookie, then read it back on a protected route:
88
+
89
+ ```typescript [src/index.ts]
90
+ import {
91
+ Context,
92
+ Controller,
93
+ Get,
94
+ Post,
95
+ type RequestContext,
96
+ } from "@antelopejs/interface-api";
97
+ import { Authentication, SignServerResponse } from "@antelopejs/interface-auth";
98
+
99
+ interface Session {
100
+ userId: string;
101
+ }
102
+
103
+ export class SessionController extends Controller("/session") {
104
+ @Post("/login")
105
+ async login(@Context() context: RequestContext) {
106
+ await SignServerResponse(
107
+ context.rawResponse,
108
+ { userId: "42" },
109
+ { expiresIn: "1h" },
110
+ { httpOnly: true, path: "/" },
111
+ );
112
+ return { ok: true };
113
+ }
114
+
115
+ @Get("/me")
116
+ me(@Authentication() session: Session) {
117
+ return session;
44
118
  }
45
119
  }
46
120
  ```
47
121
 
48
- The configuration options include:
122
+ `GET /session/me` reads the token from the `x-antelopejs-auth` header or the `ANTELOPEJS_AUTH` cookie. It answers `401` when the token is missing and `403` when it is invalid or expired.
49
123
 
50
- - `secret`: A shared secret key used for both signing and verification (symmetric)
51
- - `signKey`: Path to a private key file (for asymmetric signing)
52
- - `verifyKey`: Path to a public key file (for asymmetric verification)
53
- - `signOptions`: Options for token signing (follows jsonwebtoken's SignOptions)
54
- - `verifyOptions`: Options for token verification (follows jsonwebtoken's VerifyOptions)
124
+ ## Documentation
55
125
 
56
- Note: Either `secret` or both `signKey` and `verifyKey` must be provided.
126
+ - [Auth](https://interfaces.antelopejs.com/docs/auth/introduction): the `@antelopejs/interface-auth` contract this module implements
127
+ - [Configuration](https://framework.antelopejs.com/docs/concepts/configuration): module sources, `config` blocks and config variables in `antelope.config.ts`
57
128
 
58
- ## Usage with API Controllers
129
+ ## Compatibility
59
130
 
60
- As this module interfaces auth decorator with the interface API provider system, it can be used with API controllers.
131
+ | Package | Supported range |
132
+ | ---------------------------- | ----------------- |
133
+ | `@antelopejs/interface-auth` | `>=0.0.6 <1.0.0` |
134
+ | `@antelopejs/interface-api` | `>=0.0.13 <1.0.0` |
135
+ | `@antelopejs/interface-core` | `>=0.1.1 <1.0.0` |
61
136
 
62
- Authentication decorators can be used with any parameter in API controller methods. They can be combined with other parameters and decorators:
137
+ The module is developed and tested against `@antelopejs/core` `^1.13.4` on Node.js 24.
63
138
 
64
- ```typescript
65
- import { Controller, Get } from '@ajs/api/beta';
66
- import { Authentication, AdminAuth } from '@ajs/auth/beta';
67
-
68
- class UsersController extends Controller('/users') {
69
- // Accessible to all authenticated users
70
- @Get()
71
- async listUsers(@Authentication() user: any) {
72
- // List users
73
- return { users: [] };
74
- }
75
- }
139
+ ## Contributing
140
+
141
+ ```bash
142
+ pnpm install
143
+ pnpm dev # run the playground/ project in watch mode
144
+ pnpm lint
145
+ pnpm format:check
146
+ pnpm knip
147
+ pnpm test # build, then ajs module test
76
148
  ```
77
149
 
150
+ Read the [contribution guidelines](CONTRIBUTING.md) before opening a pull request.
151
+
78
152
  ## License
79
153
 
80
- This project is licensed under the Apache License 2.0 - see the [LICENSE](LICENSE) file for details.
154
+ [Apache-2.0](LICENSE)
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/implementations/auth/index.ts"],"names":[],"mappings":";;;AAKA,uCAA4C;AAK5C,SAAS,oBAAoB,CAC3B,OAAqB;IAErB,IAAI,CAAC,OAAO,EAAE,CAAC;QACb,OAAO,SAAS,CAAC;IACnB,CAAC;IAED,MAAM,cAAc,GAAmB,EAAE,CAAC;IAE1C,IAAI,OAAO,CAAC,SAAS,KAAK,SAAS,EAAE,CAAC;QACpC,cAAc,CAAC,SAAS,GAAG,OAAO,CAAC,SAElC,CAAC;IACJ,CAAC;IAED,IAAI,OAAO,CAAC,SAAS,KAAK,SAAS,EAAE,CAAC;QACpC,cAAc,CAAC,SAAS,GAAG,OAAO,CAAC,SAElC,CAAC;IACJ,CAAC;IAED,OAAO,cAAc,CAAC;AACxB,CAAC;AAED,IAAiB,QAAQ,CAcxB;AAdD,WAAiB,QAAQ;IACvB,SAAgB,MAAM,CACpB,IAAa,EACb,OAA0B;QAE1B,OAAO,IAAA,qBAAa,GAAE,CAAC,MAAM,CAAI,IAAI,EAAE,OAAO,CAAC,CAAC;IAClD,CAAC;IALe,eAAM,SAKrB,CAAA;IAED,SAAgB,IAAI,CAClB,IAAoB,EACpB,OAAqB;QAErB,OAAO,IAAA,qBAAa,GAAE,CAAC,IAAI,CAAC,IAAI,EAAE,oBAAoB,CAAC,OAAO,CAAC,CAAC,CAAC;IACnE,CAAC;IALe,aAAI,OAKnB,CAAA;AACH,CAAC,EAdgB,QAAQ,wBAAR,QAAQ,QAcxB"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/implementations/auth/index.ts"],"names":[],"mappings":";;;AA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,KAAU,CAAC"}
package/package.json CHANGED
@@ -1,64 +1,77 @@
1
1
  {
2
2
  "name": "@antelopejs/auth-jwt",
3
- "version": "1.0.3",
4
- "description": "Authentication and authorization module that implements the Auth interface of antelopejs with JWT",
3
+ "version": "1.0.4",
4
+ "description": "JWT authentication module for AntelopeJS, implementing the Auth interface with jsonwebtoken",
5
5
  "keywords": [
6
- "antelope",
7
- "jwt",
6
+ "antelopejs",
8
7
  "auth",
9
8
  "authentication",
10
- "authorization"
9
+ "authorization",
10
+ "jsonwebtoken",
11
+ "jwt"
11
12
  ],
13
+ "homepage": "https://interfaces.antelopejs.com/docs/auth/introduction",
14
+ "bugs": {
15
+ "url": "https://github.com/AntelopeJS/auth-jwt/issues"
16
+ },
17
+ "license": "Apache-2.0",
12
18
  "repository": {
13
19
  "type": "git",
14
- "url": "git+https://github.com/AntelopeJS/auth.git"
20
+ "url": "git+https://github.com/AntelopeJS/auth-jwt.git"
15
21
  },
16
- "main": "dist/index.js",
17
22
  "files": [
18
23
  "dist"
19
24
  ],
25
+ "main": "dist/index.js",
20
26
  "publishConfig": {
21
- "access": "public"
27
+ "access": "public",
28
+ "provenance": true
22
29
  },
23
- "license": "Apache-2.0",
24
- "packageManager": "pnpm@10.6.5",
25
30
  "scripts": {
26
31
  "build": "rimraf dist && tsc",
27
- "dev": "ajs project run -w -p playground",
28
- "format": "biome format --write .",
29
- "lint:fix": "biome check --write .",
30
- "lint": "biome check .",
32
+ "dev": "ajs project dev -w -p playground",
33
+ "format": "oxfmt .",
34
+ "lint:fix": "oxlint --fix",
35
+ "lint": "oxlint",
31
36
  "prepack": "pnpm run build",
32
37
  "release": "pnpm run lint && pnpm run test && pnpm run prepack && release-it",
33
- "test": "pnpm run build && ajs module test"
34
- },
35
- "antelopeJs": {
36
- "implements": [
37
- "@antelopejs/interface-auth"
38
- ],
39
- "defaultConfig": {
40
- "secret": "your-secret-key"
41
- },
42
- "test": "src/test/antelope.test.ts"
38
+ "test": "pnpm run build && ajs module test",
39
+ "format:check": "oxfmt --check .",
40
+ "knip": "knip"
43
41
  },
44
42
  "dependencies": {
45
- "@antelopejs/interface-api": ">=0.0.8 <1.0.0",
46
- "@antelopejs/interface-auth": ">=0.0.5 <1.0.0",
47
- "@antelopejs/interface-core": ">=0.0.6 <1.0.0",
43
+ "@antelopejs/interface-api": ">=0.0.15 <1.0.0",
44
+ "@antelopejs/interface-auth": ">=0.0.7 <1.0.0",
45
+ "@antelopejs/interface-core": ">=0.2.4 <1.0.0",
48
46
  "chai": "^4.5.0",
49
- "jsonwebtoken": "^9.0.3",
50
- "mocha": "^11.7.5"
47
+ "jsonwebtoken": "^9.0.3"
51
48
  },
52
49
  "devDependencies": {
53
- "@biomejs/biome": "2.3.2",
50
+ "@antelopejs/core": "^1.16.0",
51
+ "@antelopejs/tooling-configs": "^0.0.9",
54
52
  "@types/chai": "^4.3.20",
55
53
  "@types/jsonwebtoken": "^9.0.10",
56
54
  "@types/mocha": "^10.0.10",
57
55
  "@types/node": "^22.19.15",
58
56
  "@types/semver": "^7.7.1",
57
+ "eslint-plugin-perfectionist": "^5.11.0",
58
+ "knip": "^6.34.0",
59
+ "oxfmt": "^0.66.0",
60
+ "oxlint": "1.81.0",
61
+ "oxlint-tsgolint": "^7.0.2001",
59
62
  "release-it": "^19.2.4",
60
63
  "release-it-changelogen": "^0.1.0",
61
64
  "rimraf": "^6.1.3",
62
65
  "typescript": "^5.9.3"
66
+ },
67
+ "packageManager": "pnpm@10.6.5",
68
+ "antelopeJs": {
69
+ "implements": [
70
+ "@antelopejs/interface-auth"
71
+ ],
72
+ "defaultConfig": {
73
+ "secret": "your-secret-key"
74
+ },
75
+ "test": "src/test/antelope.test.ts"
63
76
  }
64
77
  }