orange-auth 1.1.0 โ†’ 1.3.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.
Files changed (63) hide show
  1. package/COPYING +674 -0
  2. package/README.md +81 -124
  3. package/dist/IProvider-BH8TjziQ.d.mts +461 -0
  4. package/dist/IProvider-BH8TjziQ.d.mts.map +1 -0
  5. package/dist/client.d.ts +470 -0
  6. package/dist/client.d.ts.map +1 -0
  7. package/dist/client.js +19 -0
  8. package/dist/client.js.map +1 -0
  9. package/dist/index-D-dMFhOD.d.mts +55 -0
  10. package/dist/index-D-dMFhOD.d.mts.map +1 -0
  11. package/dist/index-DjPz5vTX.d.mts +37 -0
  12. package/dist/index-DjPz5vTX.d.mts.map +1 -0
  13. package/dist/index.d.mts +70 -0
  14. package/dist/index.d.mts.map +1 -0
  15. package/dist/index.mjs +19 -0
  16. package/dist/index.mjs.map +1 -0
  17. package/dist/providers.d.mts +20 -0
  18. package/dist/providers.mjs +19 -0
  19. package/dist/providers.mjs.map +1 -0
  20. package/dist/strategies.d.mts +20 -0
  21. package/dist/strategies.mjs +19 -0
  22. package/dist/strategies.mjs.map +1 -0
  23. package/package.json +52 -31
  24. package/LICENSE +0 -21
  25. package/dist/@types/globals.d.ts +0 -97
  26. package/dist/@types/globals.d.ts.map +0 -1
  27. package/dist/@types/globals.js +0 -1
  28. package/dist/@types/internals.d.ts +0 -13
  29. package/dist/@types/internals.d.ts.map +0 -1
  30. package/dist/@types/internals.js +0 -1
  31. package/dist/functions/index.d.ts +0 -3
  32. package/dist/functions/index.d.ts.map +0 -1
  33. package/dist/functions/index.js +0 -2
  34. package/dist/functions/jwt.d.ts +0 -11
  35. package/dist/functions/jwt.d.ts.map +0 -1
  36. package/dist/functions/jwt.js +0 -20
  37. package/dist/functions/urlencodedToJson.d.ts +0 -2
  38. package/dist/functions/urlencodedToJson.d.ts.map +0 -1
  39. package/dist/functions/urlencodedToJson.js +0 -8
  40. package/dist/index.d.ts +0 -5
  41. package/dist/index.d.ts.map +0 -1
  42. package/dist/index.js +0 -4
  43. package/dist/lib.d.ts +0 -46
  44. package/dist/lib.d.ts.map +0 -1
  45. package/dist/lib.js +0 -161
  46. package/dist/providers/Credentials.d.ts +0 -33
  47. package/dist/providers/Credentials.d.ts.map +0 -1
  48. package/dist/providers/Credentials.js +0 -39
  49. package/dist/providers/IProvider.d.ts +0 -29
  50. package/dist/providers/IProvider.d.ts.map +0 -1
  51. package/dist/providers/IProvider.js +0 -20
  52. package/dist/providers/index.d.ts +0 -3
  53. package/dist/providers/index.d.ts.map +0 -1
  54. package/dist/providers/index.js +0 -2
  55. package/dist/strategies/IStrategy.d.ts +0 -29
  56. package/dist/strategies/IStrategy.d.ts.map +0 -1
  57. package/dist/strategies/IStrategy.js +0 -7
  58. package/dist/strategies/index.d.ts +0 -3
  59. package/dist/strategies/index.d.ts.map +0 -1
  60. package/dist/strategies/index.js +0 -2
  61. package/dist/strategies/jwt.d.ts +0 -19
  62. package/dist/strategies/jwt.d.ts.map +0 -1
  63. package/dist/strategies/jwt.js +0 -41
package/README.md CHANGED
@@ -1,25 +1,33 @@
1
1
  # ๐ŸŠ Orange Auth
2
2
 
3
- ### THIS IS A VERY EARLY WIP, AND SHOULD NOT BE USED IN PRODUCTION
3
+ [![npm version](https://img.shields.io/npm/v/orange-auth?color=orange&logo=npm)](https://www.npmjs.com/package/orange-auth)
4
+ [![License](https://img.shields.io/github/license/Unimat45/OrangeAuth?color=blue)](./COPYING)
5
+ ![GitHub Actions Workflow Status](https://img.shields.io/github/actions/workflow/status/Unimat45/OrangeAuth/.github/workflows/publish.yaml?branch=main&logo=github)
4
6
 
5
- Authentication middleware for [@universal-middleware/core](https://www.npmjs.com/package/@universal-middleware/core), supporting provider-based login/logout and strategy-driven session handling via secure cookies.
6
7
 
7
- ## ๐Ÿš€ Features
8
+ > **โš ๏ธ Early WIP:** This project is experimental and not ready for production use.
9
+ > Use at your own risk.
8
10
 
9
- - Provider-based login/logout flow
10
- - Pluggable strategies (e.g. JWT)
11
- - Secure cookie-based session storage
12
- - Simple, composable handler with session retrieval
13
- - Optional cookie settings
14
- - Framework-agnostic
11
+ **OrangeAuth** is a framework-agnostic, modular authentication middleware for Node.js & TypeScript.
12
+ It provides a clean workflow for session handling, provider-based login/logout, cookie storage, and customizable strategies.
15
13
 
16
- ## ๐Ÿ“ฆ Install
14
+ ---
15
+
16
+ ## ๐Ÿ” Features
17
+
18
+ - ๐Ÿงฉ **Provider-based Auth:** Plug in local credentials, OAuth providers, etc.
19
+ - ๐Ÿ”‘ **Strategies:** Swap how sessions are created, verified, and serialized (e.g., JWT).
20
+ - ๐Ÿช **Secure Cookies:** Built-in cookie handling with sensible defaults.
21
+ - ๐Ÿ› ๏ธ **Framework-agnostic:** Works with many routing layers via adapters (e.g., Express).
22
+ - ๐Ÿ“ฆ **Modular API:** Add or customize providers and strategies easily.
23
+
24
+ ## ๐Ÿš€ Installation
17
25
 
18
26
  ```bash
19
27
  npm install orange-auth
20
28
  ```
21
29
 
22
- ## ๐Ÿง  Usage
30
+ ## ๐Ÿง  Quick Usage
23
31
 
24
32
  ### Setup
25
33
 
@@ -29,18 +37,14 @@ import { JWT } from "orange-auth/strategies";
29
37
  import { Credentials } from "orange-auth/providers";
30
38
 
31
39
  const { handler, getSession } = CreateAuth({
32
- providers: [new Credentials({ ... })],
33
- strategy: new JWT({ ... }),
40
+ providers: [new Credentials({ /* options */ })],
41
+ strategy: new JWT({ /* jwt options */ }),
34
42
  secret: "your-secret",
35
- basePath: "/api/auth/:action/:provider",
43
+ basePath: "/api/auth",
36
44
  });
37
45
  ```
38
46
 
39
- You can now use:
40
- - `POST /api/auth/login/:provider`
41
- - `POST /api/auth/logout/:provider`
42
-
43
- ### Example (express middleware router)
47
+ ### Using with Express
44
48
 
45
49
  ```ts
46
50
  import express from "express";
@@ -48,14 +52,25 @@ import { handler } from "./auth";
48
52
  import { createHandler } from "@universal-middleware/express";
49
53
 
50
54
  const app = express();
51
- app.get("/api/auth/{*auth}", createHandler(handler)());
55
+
56
+ // Attach auth handler on `/api/auth/*`
57
+ app.all("/api/auth/*", createHandler(handler)());
52
58
  ```
53
59
 
54
- ## ๐Ÿงพ Session Access
60
+ ## ๐Ÿ“ก Available Endpoints
55
61
 
56
- ```ts
57
- import { getSession } from "./auth";
62
+ Once configured, your handlers expose:
58
63
 
64
+ | Method | Path | Action |
65
+ | ------ | ---------------------------- | --------------------- |
66
+ | POST | `/api/auth/login/:provider` | Login via provider |
67
+ | POST | `/api/auth/logout/:provider` | Log out from provider |
68
+
69
+ ## ๐Ÿงฉ Session Access
70
+
71
+ You can retrieve session data programmatically:
72
+
73
+ ```ts
59
74
  const session = await getSession(req);
60
75
 
61
76
  if (session) {
@@ -63,115 +78,57 @@ if (session) {
63
78
  }
64
79
  ```
65
80
 
66
- ## ๐Ÿงฉ Config Options
81
+ ## โš™๏ธ Configuration
67
82
 
68
- ```ts
69
- type ConfigOptionsProps = {
70
- /**
71
- * All the available providers.
72
- * If multiple instance of a single provider are used with the same name, the order does matter.
73
- */
74
- providers: IProvider[];
75
-
76
- /**
77
- * Your secret key.
78
- */
79
- secret: string;
80
-
81
- /**
82
- * A custom name for the cookie.
83
- * Otherwise, the default name will be `orange.auth`
84
- */
85
- cookieName?: string;
86
-
87
- /**
88
- * The strategy to be used.
89
- */
90
- strategy: IStrategy;
91
-
92
- /**
93
- * This should be the url path that your auth is set up on, including the action and provider variables.
94
- * @example
95
- * ```js
96
- * const app = express();
97
- *
98
- * const { handler } = CreateAuth({
99
- * basePath: "/api/auth/:action/:provider",
100
- * ...
101
- * });
102
- *
103
- * app.all("/api/auth/{*auth}", createHandler(handler)());
104
- * ```
105
- */
106
- basePath: string;
107
-
108
- /**
109
- * Cookie serialization options. see [MDN Cookie](https://developer.mozilla.org/en-US/docs/Web/HTTP/Guides/Cookies)
110
- */
111
- cookieSettings?: SerializeOptions;
112
- };
113
- ```
83
+ ### `CreateAuth` Options
114
84
 
115
- ## ๐Ÿงฑ Interfaces
85
+ | Option | Type | Description |
86
+ | ----------------- | ------------- | ------------------------------------------------- |
87
+ | `providers` | `IProvider[]` | List of auth providers (e.g., Credentials, OAuth) |
88
+ | `strategy` | `IStrategy` | Strategy for token/session (JWT, etc.) |
89
+ | `secret` | `string` | Secret key for signing/validation |
90
+ | `basePath` | `string` | API route prefix for auth |
91
+ | `cookieName?` | `string` | Custom cookie key (defaults to `orange.auth`) |
92
+ | `cookieSettings?` | `object` | Cookie serialization options |
116
93
 
117
- ### IProvider
94
+ โš ๏ธ Providers and strategies are designed to be modular โ€” you can write your own by implementing the relevant interfaces.
118
95
 
119
- ```ts
120
- abstract class IProvider {
121
- /**
122
- * Custom name for a provider
123
- */
124
- ID: string;
125
-
126
- /**
127
- * Login function. This is used to call all the login flows of each provider.
128
- * For now, the request's body **MUST** be JSON.
129
- * @param req The request object.
130
- * @param globalCfg The global auth config.
131
- */
132
- logIn(req: Request, globalCfg: ConfigOptions): Promise<string | null>;
133
- }
134
- ```
96
+ ## ๐Ÿ“Œ When to Use
135
97
 
136
- ### IStrategy
98
+ OrangeAuth fits well when you want:
137
99
 
138
- ```ts
139
- abstract class IStrategy {
140
- /**
141
- * Handles how a session token is generated.
142
- * @param session The validated session object.
143
- * @param globalCfg The global auth config.
144
- * @returns A newly generated token that will be sent as a cookie.
145
- */
146
- serialize(session: Session, globalCfg: ConfigOptions): Promise<string>;
147
-
148
- /**
149
- * Handles how a token is validated and deserialized into a session object.
150
- * @param token A user's token.
151
- * @param globalCfg The global auth config.
152
- * @returns A user's session if validated and found, else `null`.
153
- */
154
- deserialize(token: string, globalCfg: ConfigOptions): Promise<Session | null>;
155
-
156
- /**
157
- * Handles how a session is destroyed when a user is logging out.
158
- * @param req The request object.
159
- * @param globalCfg The global auth config.
160
- */
161
- logOut(req: Request, globalCfg: ConfigOptions): Promise<void>;
162
- }
163
- ```
100
+ * A **flexible auth layer** for APIs (REST or serverless)
101
+ * A **strategy-agnostic session store** (e.g., JWT, encrypted tokens)
102
+ * A **provider pattern** instead of monolithic auth
164
103
 
165
- ---
104
+ ## ๐Ÿ“š Roadmap
105
+
106
+ Future improvements might include:
107
+
108
+ * ๐Ÿ‘ค Additional built-in provider support (OAuth2, OpenID)
109
+ * ๐Ÿงช Built-in test helpers and mocks
110
+ * ๐ŸŒ Better TypeScript typings for providers
111
+ * ๐Ÿ”Œ Framework adapters (Fastify, Next.js, etc.)
112
+
113
+ ## ๐Ÿค Contributing
114
+
115
+ 1. Fork the repository.
116
+ 2. Create a feature branch:
117
+
118
+ ```bash
119
+ git checkout -b feature/my-awesome-change
120
+ ```
121
+ 3. Make your changes, add tests, update docs.
122
+ 4. Submit a pull request.
123
+
124
+ We welcome enhancements, bug fixes, and docs improvements!
125
+
126
+ ## ๐Ÿ“„ License
166
127
 
167
- ## ๐Ÿ” Cookie Defaults
128
+ This project is licensed under the **GNU General Public License v3.0 or later (GPL-3.0+)**.
168
129
 
169
- By default, the cookie is:
130
+ You are free to use, modify, and redistribute this software under the terms of the GPL, provided that any derivative work is also distributed under the same license.
170
131
 
171
- - `httpOnly: true`
172
- - `secure: true`
173
- - `sameSite: "lax"`
174
- - `path: "/"`
175
- - `maxAge: 3600` (1 hour)
132
+ See the [COPYING](./COPYING) file for full details.
176
133
 
177
- This can be customized via `cookieSettings` in the initial config.
134
+ ยฉ Unimat45