@drmhse/sso-sdk 0.3.10 → 0.3.12
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/README.md +74 -5
- package/dist/index.d.mts +21 -0
- package/dist/index.d.ts +21 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -52,6 +52,71 @@ const orgs = await sso.organizations.list();
|
|
|
52
52
|
console.log(orgs);
|
|
53
53
|
```
|
|
54
54
|
|
|
55
|
+
## Understanding Context Modes
|
|
56
|
+
|
|
57
|
+
AuthOS supports **two initialization modes** that determine how authentication is handled:
|
|
58
|
+
|
|
59
|
+
### Platform-Level Mode
|
|
60
|
+
|
|
61
|
+
For platform owners and administrators managing AuthOS itself:
|
|
62
|
+
|
|
63
|
+
```typescript
|
|
64
|
+
const sso = new SsoClient({
|
|
65
|
+
baseURL: 'https://sso.example.com'
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
// Platform-level login (email/password only)
|
|
69
|
+
await sso.auth.login({
|
|
70
|
+
email: 'admin@platform.com',
|
|
71
|
+
password: 'SecurePass123!'
|
|
72
|
+
});
|
|
73
|
+
// JWT contains: { is_platform_owner: true, ... }
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
**When to use:** Admin dashboards, platform management tools, internal tooling.
|
|
77
|
+
|
|
78
|
+
### Multi-Tenant Mode
|
|
79
|
+
|
|
80
|
+
For end-user applications that integrate with AuthOS:
|
|
81
|
+
|
|
82
|
+
```typescript
|
|
83
|
+
// Initialize with org and service context
|
|
84
|
+
const sso = new SsoClient({
|
|
85
|
+
baseURL: 'https://sso.example.com'
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
// OAuth redirects require org + service to determine:
|
|
89
|
+
// 1. Which tenant's OAuth credentials (BYOO) to use
|
|
90
|
+
// 2. Which service the identity is attributed to
|
|
91
|
+
const loginUrl = sso.auth.getLoginUrl('github', {
|
|
92
|
+
org: 'acme-corp', // Organization slug
|
|
93
|
+
service: 'main-app', // Service within that org
|
|
94
|
+
redirect_uri: 'https://app.acme.com/callback'
|
|
95
|
+
});
|
|
96
|
+
|
|
97
|
+
// Password login can also include org context
|
|
98
|
+
await sso.auth.login({
|
|
99
|
+
email: 'user@example.com',
|
|
100
|
+
password: 'SecurePass123!',
|
|
101
|
+
org_slug: 'acme-corp' // Optional: scopes JWT to this org
|
|
102
|
+
});
|
|
103
|
+
// JWT contains: { org: 'acme-corp', ... }
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
**When to use:** Customer-facing apps, SaaS products, multi-tenant applications.
|
|
107
|
+
|
|
108
|
+
### Why Context Matters
|
|
109
|
+
|
|
110
|
+
| Context | JWT Claims | OAuth Credentials Used |
|
|
111
|
+
|---------|-----------|----------------------|
|
|
112
|
+
| Platform-level | `is_platform_owner: true` | Platform's `PLATFORM_*` credentials |
|
|
113
|
+
| Multi-tenant | `org: 'slug'`, `service: 'slug'` | Tenant's BYOO credentials (or platform fallback) |
|
|
114
|
+
|
|
115
|
+
The `org` and `service` parameters ensure:
|
|
116
|
+
- **Identity isolation**: User identities are scoped to specific services
|
|
117
|
+
- **Credential isolation**: Each tenant can use their own OAuth app credentials
|
|
118
|
+
- **Proper attribution**: Login events are tracked per organization/service
|
|
119
|
+
|
|
55
120
|
**New to the SDK?** Start with the **[Getting Started Guide →](https://drmhse.com/docs/sso/sdk/getting-started)** for a step-by-step tutorial showing how to authenticate users from scratch, handle token refresh, and implement logout.
|
|
56
121
|
|
|
57
122
|
**Essential Guides:**
|
|
@@ -91,19 +156,23 @@ if (accessToken) {
|
|
|
91
156
|
### Password Authentication
|
|
92
157
|
|
|
93
158
|
```typescript
|
|
94
|
-
// Register new user
|
|
159
|
+
// Register new user (tenant-first: always include org + service for proper attribution)
|
|
95
160
|
await sso.auth.register({
|
|
96
161
|
email: 'user@example.com',
|
|
97
162
|
password: 'SecurePass123!',
|
|
98
|
-
org_slug: 'acme-corp'
|
|
163
|
+
org_slug: 'acme-corp', // Your organization
|
|
164
|
+
service_slug: 'main-app' // Your application
|
|
99
165
|
});
|
|
166
|
+
// User identity is now scoped to your org and service
|
|
100
167
|
|
|
101
|
-
// Login with password -
|
|
168
|
+
// Login with password (service-scoped: include org + service)
|
|
102
169
|
await sso.auth.login({
|
|
103
170
|
email: 'user@example.com',
|
|
104
|
-
password: 'SecurePass123!'
|
|
171
|
+
password: 'SecurePass123!',
|
|
172
|
+
org_slug: 'acme-corp', // Your organization
|
|
173
|
+
service_slug: 'main-app' // Your application
|
|
105
174
|
});
|
|
106
|
-
//
|
|
175
|
+
// JWT is now scoped to org + service
|
|
107
176
|
|
|
108
177
|
// Enable MFA
|
|
109
178
|
const mfaSetup = await sso.user.mfa.setup();
|
package/dist/index.d.mts
CHANGED
|
@@ -309,7 +309,17 @@ interface RefreshTokenResponse {
|
|
|
309
309
|
interface RegisterRequest {
|
|
310
310
|
email: string;
|
|
311
311
|
password: string;
|
|
312
|
+
/**
|
|
313
|
+
* Organization slug for tenant context.
|
|
314
|
+
* When provided, the user is attributed to this organization.
|
|
315
|
+
*/
|
|
312
316
|
org_slug?: string;
|
|
317
|
+
/**
|
|
318
|
+
* Service slug for service attribution.
|
|
319
|
+
* When provided with org_slug, creates a scoped identity.
|
|
320
|
+
* This ensures password users are tracked the same as OAuth users.
|
|
321
|
+
*/
|
|
322
|
+
service_slug?: string;
|
|
313
323
|
}
|
|
314
324
|
/**
|
|
315
325
|
* Registration response
|
|
@@ -323,6 +333,17 @@ interface RegisterResponse {
|
|
|
323
333
|
interface LoginRequest {
|
|
324
334
|
email: string;
|
|
325
335
|
password: string;
|
|
336
|
+
/**
|
|
337
|
+
* Organization slug for context.
|
|
338
|
+
* When provided, scopes the session to this organization.
|
|
339
|
+
*/
|
|
340
|
+
org_slug?: string;
|
|
341
|
+
/**
|
|
342
|
+
* Service slug for service-scoped access.
|
|
343
|
+
* When provided with org_slug, limits access to this specific service.
|
|
344
|
+
* Only required for regular members; org owners/admins can omit.
|
|
345
|
+
*/
|
|
346
|
+
service_slug?: string;
|
|
326
347
|
}
|
|
327
348
|
/**
|
|
328
349
|
* Forgot password request payload
|
package/dist/index.d.ts
CHANGED
|
@@ -309,7 +309,17 @@ interface RefreshTokenResponse {
|
|
|
309
309
|
interface RegisterRequest {
|
|
310
310
|
email: string;
|
|
311
311
|
password: string;
|
|
312
|
+
/**
|
|
313
|
+
* Organization slug for tenant context.
|
|
314
|
+
* When provided, the user is attributed to this organization.
|
|
315
|
+
*/
|
|
312
316
|
org_slug?: string;
|
|
317
|
+
/**
|
|
318
|
+
* Service slug for service attribution.
|
|
319
|
+
* When provided with org_slug, creates a scoped identity.
|
|
320
|
+
* This ensures password users are tracked the same as OAuth users.
|
|
321
|
+
*/
|
|
322
|
+
service_slug?: string;
|
|
313
323
|
}
|
|
314
324
|
/**
|
|
315
325
|
* Registration response
|
|
@@ -323,6 +333,17 @@ interface RegisterResponse {
|
|
|
323
333
|
interface LoginRequest {
|
|
324
334
|
email: string;
|
|
325
335
|
password: string;
|
|
336
|
+
/**
|
|
337
|
+
* Organization slug for context.
|
|
338
|
+
* When provided, scopes the session to this organization.
|
|
339
|
+
*/
|
|
340
|
+
org_slug?: string;
|
|
341
|
+
/**
|
|
342
|
+
* Service slug for service-scoped access.
|
|
343
|
+
* When provided with org_slug, limits access to this specific service.
|
|
344
|
+
* Only required for regular members; org owners/admins can omit.
|
|
345
|
+
*/
|
|
346
|
+
service_slug?: string;
|
|
326
347
|
}
|
|
327
348
|
/**
|
|
328
349
|
* Forgot password request payload
|