@darco2903/auth-api 2.1.0 → 2.1.2
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 +674 -674
- package/README.md +4 -3
- package/dist/consts.d.ts +1 -0
- package/dist/consts.js +1 -0
- package/dist/server.js +2 -2
- package/package.json +3 -3
- package/tools/generate-openapi.ts +25 -25
package/README.md
CHANGED
|
@@ -18,7 +18,7 @@ npm install @darco2903/auth-api
|
|
|
18
18
|
import { createClient } from "@darco2903/auth-api/client";
|
|
19
19
|
|
|
20
20
|
const SERVER_ORIGIN = "https://auth.example.com";
|
|
21
|
-
const authApi =
|
|
21
|
+
const authApi = createClient(SERVER_ORIGIN);
|
|
22
22
|
```
|
|
23
23
|
|
|
24
24
|
### Signing a JWT token
|
|
@@ -31,7 +31,7 @@ import {
|
|
|
31
31
|
} from "@darco2903/auth-api/server";
|
|
32
32
|
import { Hour } from "@darco2903/secondthought";
|
|
33
33
|
|
|
34
|
-
const JWT_PRIVATE_KEY = "";
|
|
34
|
+
const JWT_PRIVATE_KEY = "..."; // Private key here
|
|
35
35
|
const tokenData: AccessTokenData = {
|
|
36
36
|
public_id: "user_public_id",
|
|
37
37
|
role: UserRole.User,
|
|
@@ -55,7 +55,8 @@ await JWTSign(tokenData, JWT_PRIVATE_KEY, expiresIn).match(
|
|
|
55
55
|
```ts
|
|
56
56
|
import { JWTVerify } from "@darco2903/auth-api/server";
|
|
57
57
|
|
|
58
|
-
const
|
|
58
|
+
const JWT_PUBLIC_KEY = "..."; // Public key here
|
|
59
|
+
const accessToken = "..."; // JWT token here
|
|
59
60
|
|
|
60
61
|
await JWTVerify(accessToken, JWT_PUBLIC_KEY).match(
|
|
61
62
|
(decodedToken) => {
|
package/dist/consts.d.ts
CHANGED
|
@@ -2,6 +2,7 @@ import type { Algorithm } from "jsonwebtoken";
|
|
|
2
2
|
export declare const API_VERSION = "v2";
|
|
3
3
|
export declare const API_PATH_PREFIX = "/api/v2";
|
|
4
4
|
export declare const JWT_ALGORITHM: Algorithm;
|
|
5
|
+
export declare const JWT_ALGORITHMS: Algorithm[];
|
|
5
6
|
export declare const NAME_MIN_LENGTH = 3;
|
|
6
7
|
export declare const NAME_MAX_LENGTH = 32;
|
|
7
8
|
export declare const EMAIL_MAX_LENGTH = 255;
|
package/dist/consts.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
export const API_VERSION = "v2";
|
|
2
2
|
export const API_PATH_PREFIX = `/api/${API_VERSION}`;
|
|
3
3
|
export const JWT_ALGORITHM = "ES256";
|
|
4
|
+
export const JWT_ALGORITHMS = [JWT_ALGORITHM, "RS256"];
|
|
4
5
|
export const NAME_MIN_LENGTH = 3;
|
|
5
6
|
export const NAME_MAX_LENGTH = 32;
|
|
6
7
|
export const EMAIL_MAX_LENGTH = 255;
|
package/dist/server.js
CHANGED
|
@@ -2,10 +2,10 @@ export * from "./common.js";
|
|
|
2
2
|
import jwt from "jsonwebtoken";
|
|
3
3
|
import { ResultAsync } from "neverthrow";
|
|
4
4
|
import { accessTokenDataDecodedSchema, } from "./types/index.js";
|
|
5
|
-
import { JWT_ALGORITHM } from "./consts.js";
|
|
5
|
+
import { JWT_ALGORITHM, JWT_ALGORITHMS } from "./consts.js";
|
|
6
6
|
export function JWTVerify(token, pubKey) {
|
|
7
7
|
return ResultAsync.fromPromise(new Promise((resolve, reject) => {
|
|
8
|
-
jwt.verify(token, pubKey, { algorithms:
|
|
8
|
+
jwt.verify(token, pubKey, { algorithms: JWT_ALGORITHMS }, (e, decoded) => {
|
|
9
9
|
if (e) {
|
|
10
10
|
reject({
|
|
11
11
|
name: e.name,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@darco2903/auth-api",
|
|
3
|
-
"version": "2.1.
|
|
3
|
+
"version": "2.1.2",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"type": "module",
|
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
"author": "",
|
|
9
9
|
"license": "ISC",
|
|
10
10
|
"repository": {
|
|
11
|
-
"url": "https://github.com/Darco2903/
|
|
11
|
+
"url": "https://github.com/Darco2903/auth-api.git"
|
|
12
12
|
},
|
|
13
13
|
"publishConfig": {
|
|
14
14
|
"access": "public"
|
|
@@ -19,7 +19,7 @@
|
|
|
19
19
|
"./server": "./dist/server.js"
|
|
20
20
|
},
|
|
21
21
|
"dependencies": {
|
|
22
|
-
"@darco2903/cdn-api": "^1.0
|
|
22
|
+
"@darco2903/cdn-api": "^1.1.0",
|
|
23
23
|
"@ts-rest/core": "^3.52.1",
|
|
24
24
|
"@ts-rest/open-api": "^3.52.1",
|
|
25
25
|
"jsonwebtoken": "^9.0.3",
|
|
@@ -1,25 +1,25 @@
|
|
|
1
|
-
import fs from "fs";
|
|
2
|
-
import { generateOpenApi } from "@ts-rest/open-api";
|
|
3
|
-
import { contract } from "../src/";
|
|
4
|
-
|
|
5
|
-
import { version } from "../package.json";
|
|
6
|
-
|
|
7
|
-
console.log("Generating OpenAPI documentation...");
|
|
8
|
-
console.log(`API version: ${version}`);
|
|
9
|
-
|
|
10
|
-
const openApiDocument = generateOpenApi(contract, {
|
|
11
|
-
info: {
|
|
12
|
-
title: "Auth API",
|
|
13
|
-
version,
|
|
14
|
-
},
|
|
15
|
-
servers: [
|
|
16
|
-
{
|
|
17
|
-
url: "https://auth.darco2903.fr",
|
|
18
|
-
},
|
|
19
|
-
{
|
|
20
|
-
url: "https://dev-auth.darco2903.fr",
|
|
21
|
-
},
|
|
22
|
-
],
|
|
23
|
-
});
|
|
24
|
-
|
|
25
|
-
fs.writeFileSync("openapi.json", JSON.stringify(openApiDocument, null, 2));
|
|
1
|
+
import fs from "fs";
|
|
2
|
+
import { generateOpenApi } from "@ts-rest/open-api";
|
|
3
|
+
import { contract } from "../src/";
|
|
4
|
+
|
|
5
|
+
import { version } from "../package.json";
|
|
6
|
+
|
|
7
|
+
console.log("Generating OpenAPI documentation...");
|
|
8
|
+
console.log(`API version: ${version}`);
|
|
9
|
+
|
|
10
|
+
const openApiDocument = generateOpenApi(contract, {
|
|
11
|
+
info: {
|
|
12
|
+
title: "Auth API",
|
|
13
|
+
version,
|
|
14
|
+
},
|
|
15
|
+
servers: [
|
|
16
|
+
{
|
|
17
|
+
url: "https://auth.darco2903.fr",
|
|
18
|
+
},
|
|
19
|
+
{
|
|
20
|
+
url: "https://dev-auth.darco2903.fr",
|
|
21
|
+
},
|
|
22
|
+
],
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
fs.writeFileSync("openapi.json", JSON.stringify(openApiDocument, null, 2));
|