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.
- package/COPYING +674 -0
- package/README.md +81 -124
- package/dist/IProvider-BH8TjziQ.d.mts +461 -0
- package/dist/IProvider-BH8TjziQ.d.mts.map +1 -0
- package/dist/client.d.ts +470 -0
- package/dist/client.d.ts.map +1 -0
- package/dist/client.js +19 -0
- package/dist/client.js.map +1 -0
- package/dist/index-D-dMFhOD.d.mts +55 -0
- package/dist/index-D-dMFhOD.d.mts.map +1 -0
- package/dist/index-DjPz5vTX.d.mts +37 -0
- package/dist/index-DjPz5vTX.d.mts.map +1 -0
- package/dist/index.d.mts +70 -0
- package/dist/index.d.mts.map +1 -0
- package/dist/index.mjs +19 -0
- package/dist/index.mjs.map +1 -0
- package/dist/providers.d.mts +20 -0
- package/dist/providers.mjs +19 -0
- package/dist/providers.mjs.map +1 -0
- package/dist/strategies.d.mts +20 -0
- package/dist/strategies.mjs +19 -0
- package/dist/strategies.mjs.map +1 -0
- package/package.json +52 -31
- package/LICENSE +0 -21
- package/dist/@types/globals.d.ts +0 -97
- package/dist/@types/globals.d.ts.map +0 -1
- package/dist/@types/globals.js +0 -1
- package/dist/@types/internals.d.ts +0 -13
- package/dist/@types/internals.d.ts.map +0 -1
- package/dist/@types/internals.js +0 -1
- package/dist/functions/index.d.ts +0 -3
- package/dist/functions/index.d.ts.map +0 -1
- package/dist/functions/index.js +0 -2
- package/dist/functions/jwt.d.ts +0 -11
- package/dist/functions/jwt.d.ts.map +0 -1
- package/dist/functions/jwt.js +0 -20
- package/dist/functions/urlencodedToJson.d.ts +0 -2
- package/dist/functions/urlencodedToJson.d.ts.map +0 -1
- package/dist/functions/urlencodedToJson.js +0 -8
- package/dist/index.d.ts +0 -5
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js +0 -4
- package/dist/lib.d.ts +0 -46
- package/dist/lib.d.ts.map +0 -1
- package/dist/lib.js +0 -161
- package/dist/providers/Credentials.d.ts +0 -33
- package/dist/providers/Credentials.d.ts.map +0 -1
- package/dist/providers/Credentials.js +0 -39
- package/dist/providers/IProvider.d.ts +0 -29
- package/dist/providers/IProvider.d.ts.map +0 -1
- package/dist/providers/IProvider.js +0 -20
- package/dist/providers/index.d.ts +0 -3
- package/dist/providers/index.d.ts.map +0 -1
- package/dist/providers/index.js +0 -2
- package/dist/strategies/IStrategy.d.ts +0 -29
- package/dist/strategies/IStrategy.d.ts.map +0 -1
- package/dist/strategies/IStrategy.js +0 -7
- package/dist/strategies/index.d.ts +0 -3
- package/dist/strategies/index.d.ts.map +0 -1
- package/dist/strategies/index.js +0 -2
- package/dist/strategies/jwt.d.ts +0 -19
- package/dist/strategies/jwt.d.ts.map +0 -1
- package/dist/strategies/jwt.js +0 -41
package/README.md
CHANGED
|
@@ -1,25 +1,33 @@
|
|
|
1
1
|
# ๐ Orange Auth
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
[](https://www.npmjs.com/package/orange-auth)
|
|
4
|
+
[](./COPYING)
|
|
5
|
+

|
|
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
|
-
|
|
8
|
+
> **โ ๏ธ Early WIP:** This project is experimental and not ready for production use.
|
|
9
|
+
> Use at your own risk.
|
|
8
10
|
|
|
9
|
-
|
|
10
|
-
-
|
|
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
|
-
|
|
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
|
|
43
|
+
basePath: "/api/auth",
|
|
36
44
|
});
|
|
37
45
|
```
|
|
38
46
|
|
|
39
|
-
|
|
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
|
-
|
|
55
|
+
|
|
56
|
+
// Attach auth handler on `/api/auth/*`
|
|
57
|
+
app.all("/api/auth/*", createHandler(handler)());
|
|
52
58
|
```
|
|
53
59
|
|
|
54
|
-
##
|
|
60
|
+
## ๐ก Available Endpoints
|
|
55
61
|
|
|
56
|
-
|
|
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
|
-
##
|
|
81
|
+
## โ๏ธ Configuration
|
|
67
82
|
|
|
68
|
-
|
|
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
|
-
|
|
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
|
-
|
|
94
|
+
โ ๏ธ Providers and strategies are designed to be modular โ you can write your own by implementing the relevant interfaces.
|
|
118
95
|
|
|
119
|
-
|
|
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
|
-
|
|
98
|
+
OrangeAuth fits well when you want:
|
|
137
99
|
|
|
138
|
-
|
|
139
|
-
|
|
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
|
-
|
|
128
|
+
This project is licensed under the **GNU General Public License v3.0 or later (GPL-3.0+)**.
|
|
168
129
|
|
|
169
|
-
|
|
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
|
-
|
|
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
|
-
|
|
134
|
+
ยฉ Unimat45
|