@monocloud/auth-node-core 0.0.0-canary-20251223204113

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 ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 MonoCloud
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,143 @@
1
+ ![MonoCloud Logo](https://raw.githubusercontent.com/monocloud/auth-js/refs/heads/main/MonoCloud.png)
2
+
3
+ ## Introduction
4
+
5
+ **MonoCloud Auth Node SDK – secure authentication and session management for Node.js backends.**
6
+
7
+ [MonoCloud](https://www.monocloud.com?utm_source=github&utm_medium=auth_js) is a modern, developer-friendly Identity & Access Management platform.
8
+
9
+ This package provides a **high-level authentication client for Node.js applications**, built on top of MonoCloud’s OpenID Connect (OIDC) implementation. It abstracts the complexity of OAuth/OIDC while remaining framework-agnostic.
10
+
11
+ The SDK handles:
12
+
13
+ - **Authorization Code Flow** with PKCE
14
+ - **Secure session management** using encrypted cookies
15
+ - **Automatic token rotation** via refresh tokens
16
+ - **State and CSRF validation** out of the box
17
+
18
+ > This package builds on **`@monocloud/auth-core`** and adds Node.js–specific session and cookie handling.
19
+
20
+ ## 📘 Documentation
21
+
22
+ - **Documentation:** [https://www.monocloud.com/docs](https://www.monocloud.com/docs?utm_source=github&utm_medium=auth_js)
23
+
24
+ ## Supported Platforms
25
+
26
+ - **Node.js >= 16.0.0**
27
+
28
+ ## Requirements
29
+
30
+ - A **MonoCloud Tenant**
31
+ - A **Client ID** and **Client Secret** (configured as a *Web Application*)
32
+ - A **Random secret** (32+ characters) for encrypting session cookies
33
+
34
+ ## 📦 Installation
35
+
36
+ ```bash
37
+ npm install @monocloud/auth-node-core
38
+ ```
39
+
40
+ ### Initialization
41
+
42
+ Initialize the client with your tenant and application configuration.
43
+
44
+ ```typescript
45
+ import { MonoCloudCoreClient } from '@monocloud/auth-node-core';
46
+
47
+ const nodeClient = new MonoCloudCoreClient({
48
+ tenantDomain: 'https://<your-tenant-domain>',
49
+ clientId: '<your-client-id>',
50
+ clientSecret: '<your-client-secret>',
51
+ appUrl: '<application-server-url>',
52
+ cookieSecret: '<cookie-secret>', // Used to encrypt the session cookie
53
+ });
54
+ ```
55
+
56
+ ⚠️ Security Note: Never commit secrets to source control. Always load them from environment variables.
57
+
58
+ ## Usage
59
+
60
+ The SDK is **framework-agnostic**. It operates on generic request/response adapters so it can be used with Express, Fastify, Hapi, or custom servers.
61
+
62
+ ### Sign In
63
+
64
+ Redirects the user to MonoCloud to start authentication.
65
+
66
+ ```typescript
67
+ import type { MonoCloudRequest, MonoCloudResponse } from '@monocloud/auth-node-core';
68
+
69
+ const request: MonoCloudRequest = /* framework adapter */;
70
+ const response: MonoCloudResponse = /* framework adapter */;
71
+
72
+ // Default route: /api/auth/signin
73
+ await nodeClient.signIn(request, response);
74
+ ```
75
+
76
+ ### Handle Callback
77
+
78
+ Handles the redirect from MonoCloud, validates state, exchanges the authorization code for tokens, and sets the encrypted session cookie.
79
+
80
+ ```typescript
81
+ import type { MonoCloudRequest, MonoCloudResponse } from '@monocloud/auth-node-core';
82
+
83
+ const request: MonoCloudRequest = /* framework adapter */;
84
+ const response: MonoCloudResponse = /* framework adapter */;
85
+
86
+ // Default route: /api/auth/callback
87
+ await nodeClient.callback(request, response);
88
+ ```
89
+
90
+ ### Get Session
91
+
92
+ Retrieve the current authenticated session from the request.
93
+
94
+ ```typescript
95
+ const session = await nodeClient.getSession(request, response);
96
+
97
+ console.log(session);
98
+ ```
99
+
100
+ ### Sign Out
101
+
102
+ Clears the local session and redirects the user to MonoCloud to terminate the SSO session.
103
+
104
+ ```typescript
105
+ import type { MonoCloudRequest, MonoCloudResponse } from '@monocloud/auth-node-core';
106
+
107
+ const request: MonoCloudRequest = /* framework adapter */;
108
+ const response: MonoCloudResponse = /* framework adapter */;
109
+
110
+ // Default route: /api/auth/signout
111
+ await nodeClient.signOut(request, response);
112
+ ```
113
+
114
+ ## When should I use `auth-node-core`?
115
+
116
+ Use **`@monocloud/auth-node-core`** if you are building a **Node.js backend** and want a secure authentication solution without tying yourself to a specific framework.
117
+
118
+ This package is a good fit if you:
119
+
120
+ - Are building an **API or server-rendered application** in Node.js
121
+ - Want **cookie-based sessions** with encryption handled for you
122
+ - Need built-in handling for **OIDC redirects, state validation, and token exchange**
123
+ - Want to manage authentication in a **custom servers**
124
+ - Prefer a **framework-agnostic** solution with sensible security defaults
125
+
126
+ `auth-node-core` builds on top of `@monocloud/auth-core` and adds Node-specific features such as encrypted session cookies and refresh token rotation.
127
+
128
+ Higher-level packages reuse the same underlying OIDC implementation but provide framework-specific ergonomics.
129
+
130
+ ## 🤝 Contributing & Support
131
+
132
+ ### Issues & Feedback
133
+
134
+ - Use **GitHub Issues** for bug reports and feature requests.
135
+ - For tenant or account-specific help, contact MonoCloud Support through your dashboard.
136
+
137
+ ### Security
138
+
139
+ Do **not** report security issues publicly. Please follow the contact instructions at: [https://www.monocloud.com/contact](https://www.monocloud.com/contact?utm_source=github&utm_medium=auth_js)
140
+
141
+ ## 📄 License
142
+
143
+ Licensed under the **MIT License**. See the included [`LICENSE`](https://github.com/monocloud/auth-js/blob/main/LICENSE) file.