@monocloud/auth-web-js 0.0.0-canary-20260526103559
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 +21 -0
- package/README.md +144 -0
- package/dist/index.cjs +1070 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.mts +871 -0
- package/dist/index.mjs +1006 -0
- package/dist/index.mjs.map +1 -0
- package/dist/utils/index.cjs +9 -0
- package/dist/utils/index.d.mts +1 -0
- package/dist/utils/index.mjs +2 -0
- package/dist/utils/internal.cjs +9 -0
- package/dist/utils/internal.d.mts +1 -0
- package/dist/utils/internal.mjs +2 -0
- package/package.json +70 -0
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,144 @@
|
|
|
1
|
+
<div align="center">
|
|
2
|
+
<a href="https://www.monocloud.com?utm_source=github&utm_medium=auth_js" target="_blank" rel="noopener noreferrer">
|
|
3
|
+
<picture>
|
|
4
|
+
<img src="https://raw.githubusercontent.com/monocloud/auth-js/refs/heads/main/packages/web-js/banner.svg" alt="MonoCloud Banner">
|
|
5
|
+
</picture>
|
|
6
|
+
</a>
|
|
7
|
+
<div align="right">
|
|
8
|
+
<a href="https://www.npmjs.com/package/@monocloud/auth-web-js" target="_blank">
|
|
9
|
+
<img src="https://img.shields.io/npm/v/@monocloud/auth-web-js" alt="NPM" />
|
|
10
|
+
</a>
|
|
11
|
+
<a href="https://opensource.org/licenses/MIT">
|
|
12
|
+
<img src="https://img.shields.io/:license-MIT-blue.svg?style=flat" alt="License: MIT" />
|
|
13
|
+
</a>
|
|
14
|
+
<a href="https://github.com/monocloud/auth-js/actions/workflows/build.yml">
|
|
15
|
+
<img src="https://github.com/monocloud/auth-js/actions/workflows/build.yml/badge.svg" alt="Build Status" />
|
|
16
|
+
</a>
|
|
17
|
+
</div>
|
|
18
|
+
</div>
|
|
19
|
+
|
|
20
|
+
## Introduction
|
|
21
|
+
|
|
22
|
+
**MonoCloud Web Authentication SDK – secure authentication for single-page applications and other browser-based JavaScript environments.**
|
|
23
|
+
|
|
24
|
+
[MonoCloud](https://www.monocloud.com?utm_source=github&utm_medium=auth_js) is a modern, developer-friendly Identity & Access Management platform.
|
|
25
|
+
|
|
26
|
+
This SDK provides a **browser-side authentication client** for single-page apps (SPAs) and any JavaScript environment running in the browser. It implements **OAuth 2.0 / OpenID Connect** with **PKCE**, handles redirect and popup flows, manages sessions and tokens, and serves as the foundation for higher-level framework SDKs (React, Vue, Angular, Svelte, Astro, etc.).
|
|
27
|
+
|
|
28
|
+
## 📘 Documentation
|
|
29
|
+
|
|
30
|
+
- **Documentation:** [https://www.monocloud.com/docs](https://www.monocloud.com/docs?utm_source=github&utm_medium=auth_js)
|
|
31
|
+
- **API Reference:** [https://monocloud.github.io/auth-js](https://monocloud.github.io/auth-js?utm_source=github&utm_medium=auth_js)
|
|
32
|
+
|
|
33
|
+
## Supported Platforms
|
|
34
|
+
|
|
35
|
+
- **Modern Browsers** (Chrome, Edge, Firefox, Safari)
|
|
36
|
+
|
|
37
|
+
## 🚀 Getting Started
|
|
38
|
+
|
|
39
|
+
### Requirements
|
|
40
|
+
|
|
41
|
+
- A **MonoCloud Tenant**
|
|
42
|
+
- A **Client** configured as a Single Page Application (SPA)
|
|
43
|
+
- The application's URL registered in **Callback URLs**, **Sign-out URLs** and **Cross Origin URLs**
|
|
44
|
+
|
|
45
|
+
## 📦 Installation
|
|
46
|
+
|
|
47
|
+
```bash
|
|
48
|
+
npm install @monocloud/auth-web-js
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
### Initialization
|
|
52
|
+
|
|
53
|
+
Create a shared `MonoCloudWebJSClient` instance and reuse it throughout your application.
|
|
54
|
+
|
|
55
|
+
```typescript
|
|
56
|
+
import { MonoCloudWebJSClient } from '@monocloud/auth-web-js';
|
|
57
|
+
|
|
58
|
+
export const client = new MonoCloudWebJSClient({
|
|
59
|
+
tenantDomain: 'https://<your-tenant-domain>',
|
|
60
|
+
clientId: '<your-client-id>',
|
|
61
|
+
appUrl: 'http://localhost:3000',
|
|
62
|
+
callbackPath: '/callback',
|
|
63
|
+
signOutCallbackPath: '/logout',
|
|
64
|
+
});
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
### Wire Up the Callback Routes
|
|
68
|
+
|
|
69
|
+
Call the matching process method from each callback route. The SDK never infers which flow is in progress — wire each handler to the route that owns its redirect URI.
|
|
70
|
+
|
|
71
|
+
```typescript
|
|
72
|
+
await client.processSignInCallback();
|
|
73
|
+
|
|
74
|
+
await client.processSignOutCallback();
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
### Sign In and Sign Out
|
|
78
|
+
|
|
79
|
+
Start an authentication flow by redirecting the user to MonoCloud, or end the session and return the user to your sign-out callback.
|
|
80
|
+
|
|
81
|
+
```typescript
|
|
82
|
+
await client.signIn();
|
|
83
|
+
|
|
84
|
+
await client.signOut();
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
### Silent Sign In (SSO Restore)
|
|
88
|
+
|
|
89
|
+
Attempt to restore an authenticated session at app bootstrap without disrupting the user. Uses a hidden iframe with `prompt=none`; resolves to the new session on success, or rejects with a `MonoCloudOPError` (typically `login_required`) when the authorization server cannot satisfy the request without interaction.
|
|
90
|
+
|
|
91
|
+
```typescript
|
|
92
|
+
import { MonoCloudOPError } from '@monocloud/auth-web-js';
|
|
93
|
+
|
|
94
|
+
try {
|
|
95
|
+
const session = await client.signInSilent();
|
|
96
|
+
console.log('Restored session for:', session.user);
|
|
97
|
+
} catch (error) {
|
|
98
|
+
if (error instanceof MonoCloudOPError && error.error === 'login_required') {
|
|
99
|
+
console.log('Not signed in');
|
|
100
|
+
} else {
|
|
101
|
+
throw error;
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
### Get the Current Session
|
|
107
|
+
|
|
108
|
+
Retrieve the active session, including the authenticated user's profile and tokens. Returns `null` when no user is signed in.
|
|
109
|
+
|
|
110
|
+
```typescript
|
|
111
|
+
const session = await client.getSession();
|
|
112
|
+
|
|
113
|
+
if (session) {
|
|
114
|
+
console.log(session.user);
|
|
115
|
+
}
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
## When should I use `auth-web-js`?
|
|
119
|
+
|
|
120
|
+
Use **`@monocloud/auth-web-js`** if you are building a **browser-based JavaScript application** and want a secure, OIDC-compliant authentication client without tying yourself to a specific UI framework.
|
|
121
|
+
|
|
122
|
+
This package is a good fit if you:
|
|
123
|
+
|
|
124
|
+
- Are building a **single-page application (SPA)** in plain JavaScript / TypeScript
|
|
125
|
+
- Are writing a **custom framework integration** on top of MonoCloud
|
|
126
|
+
- Need full control over **PKCE, redirects, popups, silent refresh, and token storage**
|
|
127
|
+
- Want **cross-tab refresh coordination** and pluggable storage out of the box
|
|
128
|
+
|
|
129
|
+
Higher-level packages build on top of `auth-web-js` and provide framework-specific ergonomics while reusing the same underlying browser implementation.
|
|
130
|
+
|
|
131
|
+
## 🤝 Contributing & Support
|
|
132
|
+
|
|
133
|
+
### Issues & Feedback
|
|
134
|
+
|
|
135
|
+
- Use **GitHub Issues** for bug reports and feature requests.
|
|
136
|
+
- For tenant or account-specific help, contact MonoCloud Support through your dashboard.
|
|
137
|
+
|
|
138
|
+
### Security
|
|
139
|
+
|
|
140
|
+
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)
|
|
141
|
+
|
|
142
|
+
## 📄 License
|
|
143
|
+
|
|
144
|
+
Licensed under the **MIT License**. See the included [`LICENSE`](https://github.com/monocloud/auth-js/blob/main/LICENSE) file.
|