@sso-id/cli 0.1.0 → 0.2.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 (50) hide show
  1. package/bin/sso-id.mjs +128 -7
  2. package/package.json +3 -2
  3. package/templates/angular-spa/package.json +19 -0
  4. package/templates/angular-spa/src/app/app.component.ts +63 -0
  5. package/templates/angular-spa/src/app/app.config.ts +16 -0
  6. package/templates/angular-spa/src/environments/environment.ts +7 -0
  7. package/templates/dotnet-api/Program.cs +121 -0
  8. package/templates/dotnet-api/SsoIdStarter.csproj +12 -0
  9. package/templates/dotnet-api/appsettings.json +14 -0
  10. package/templates/express-api/.env.example +12 -0
  11. package/templates/express-api/README.md +8 -0
  12. package/templates/express-api/package.json +18 -0
  13. package/templates/express-api/src/server.mjs +182 -0
  14. package/templates/go-gin/.env.example +7 -0
  15. package/templates/go-gin/go.mod +6 -0
  16. package/templates/go-gin/main.go +112 -0
  17. package/templates/mobile-react-native/.env.example +5 -0
  18. package/templates/mobile-react-native/App.tsx +45 -0
  19. package/templates/mobile-react-native/package.json +11 -0
  20. package/templates/nextjs/.env.example +19 -0
  21. package/templates/nextjs/README.md +18 -0
  22. package/templates/nextjs/next.config.mjs +4 -0
  23. package/templates/nextjs/package.json +27 -0
  24. package/templates/nextjs/src/app/api/auth/[...ssoid]/route.ts +10 -0
  25. package/templates/nextjs/src/app/api/management/[resource]/route.ts +64 -0
  26. package/templates/nextjs/src/app/api/scim/sync/route.ts +60 -0
  27. package/templates/nextjs/src/app/api/scim/v2/Groups/[id]/route.ts +58 -0
  28. package/templates/nextjs/src/app/api/scim/v2/Groups/route.ts +44 -0
  29. package/templates/nextjs/src/app/api/scim/v2/Users/[id]/route.ts +89 -0
  30. package/templates/nextjs/src/app/api/scim/v2/Users/route.ts +44 -0
  31. package/templates/nextjs/src/app/layout.tsx +18 -0
  32. package/templates/nextjs/src/app/page.tsx +164 -0
  33. package/templates/nextjs/src/app/providers.tsx +16 -0
  34. package/templates/nextjs/src/lib/scim-auth.ts +12 -0
  35. package/templates/nextjs/src/lib/sso.ts +39 -0
  36. package/templates/nextjs/tsconfig.json +24 -0
  37. package/templates/php-laravel/.env.example +6 -0
  38. package/templates/php-laravel/composer.json +9 -0
  39. package/templates/php-laravel/public/index.php +34 -0
  40. package/templates/python-fastapi/.env.example +7 -0
  41. package/templates/python-fastapi/main.py +155 -0
  42. package/templates/python-fastapi/requirements.txt +6 -0
  43. package/templates/react-spa/.env.example +5 -0
  44. package/templates/react-spa/package.json +25 -0
  45. package/templates/react-spa/src/App.tsx +67 -0
  46. package/templates/react-spa/src/main.tsx +17 -0
  47. package/templates/vue-spa/.env.example +5 -0
  48. package/templates/vue-spa/package.json +20 -0
  49. package/templates/vue-spa/src/App.vue +57 -0
  50. package/templates/vue-spa/src/main.ts +14 -0
@@ -0,0 +1,164 @@
1
+ 'use client';
2
+
3
+ import { useEffect, useState } from 'react';
4
+ import { useSsoId } from '@sso-id/react';
5
+ import { SignInButton, UserMenu } from '@sso-id/ui';
6
+
7
+ type Tab = 'organizations' | 'organization-units' | 'users' | 'groups' | 'scim';
8
+
9
+ export default function HomePage() {
10
+ const { isAuthenticated, user, isLoading } = useSsoId();
11
+ const [tab, setTab] = useState<Tab>('organizations');
12
+ const [data, setData] = useState<unknown>(null);
13
+ const [scimState, setScimState] = useState<{ users: unknown[]; groups: unknown[]; events: Array<{ id: string; timestamp: string; direction: string; resourceType: string; operation: string; summary: string }> }>({
14
+ users: [],
15
+ groups: [],
16
+ events: [],
17
+ });
18
+ const [name, setName] = useState('');
19
+ const [email, setEmail] = useState('');
20
+ const [orgId, setOrgId] = useState('');
21
+ const [status, setStatus] = useState('');
22
+
23
+ async function loadTab(current: Tab) {
24
+ setStatus('');
25
+ if (current === 'scim') {
26
+ const res = await fetch('/api/scim/sync');
27
+ setScimState(await res.json());
28
+ return;
29
+ }
30
+ const res = await fetch(`/api/management/${current}`);
31
+ setData(await res.json());
32
+ }
33
+
34
+ useEffect(() => {
35
+ loadTab(tab).catch((err) => setStatus(String(err)));
36
+ }, [tab]);
37
+
38
+ async function handleCreate(e: React.FormEvent) {
39
+ e.preventDefault();
40
+ setStatus('Saving...');
41
+ const payload =
42
+ tab === 'users'
43
+ ? { email, userName: email, firstName: name, lastName: 'User' }
44
+ : tab === 'organization-units'
45
+ ? { name, organizationId: orgId }
46
+ : { name };
47
+
48
+ const endpoint = tab === 'scim' ? '/api/scim/sync' : `/api/management/${tab}`;
49
+ const body = tab === 'scim' ? { type: 'User', userName: email, displayName: name, email } : payload;
50
+
51
+ const res = await fetch(endpoint, {
52
+ method: 'POST',
53
+ headers: { 'Content-Type': 'application/json' },
54
+ body: JSON.stringify(body),
55
+ });
56
+ const json = await res.json();
57
+ setStatus(res.ok ? 'Created successfully!' : `Error: ${json.error || res.status}`);
58
+ setName('');
59
+ setEmail('');
60
+ await loadTab(tab);
61
+ }
62
+
63
+ return (
64
+ <main style={{ maxWidth: 1080, margin: '0 auto', padding: '32px 20px' }}>
65
+ <header style={{ display: 'flex', justifyContent: 'space-between', alignItems: 'center', marginBottom: 24, paddingBottom: 16, borderBottom: '1px solid #e2e8f0' }}>
66
+ <div>
67
+ <h1 style={{ margin: 0, fontSize: 22 }}>SSO.ID Starter Workspace (Next.js)</h1>
68
+ <p style={{ margin: '4px 0 0', color: '#475569', fontSize: 14 }}>
69
+ OIDC + PKCE Auth · Organizations & OUs · Users & Groups · Real-Time SCIM 2.0
70
+ </p>
71
+ </div>
72
+ <div>
73
+ {isLoading ? (
74
+ <span>Loading session...</span>
75
+ ) : isAuthenticated ? (
76
+ <UserMenu />
77
+ ) : (
78
+ <div style={{ display: 'flex', gap: 10 }}>
79
+ <SignInButton />
80
+ <a href="/api/auth/login" style={{ padding: '8px 14px', borderRadius: 8, background: '#0f172a', color: '#fff', textDecoration: 'none', fontSize: 14 }}>
81
+ Server Login
82
+ </a>
83
+ </div>
84
+ )}
85
+ </div>
86
+ </header>
87
+
88
+ {isAuthenticated && user && (
89
+ <div style={{ background: '#ecfdf5', border: '1px solid #a7f3d0', padding: 12, borderRadius: 8, marginBottom: 20, fontSize: 14 }}>
90
+ Signed in as <strong>{String(user.email || user.name || user.sub)}</strong>
91
+ </div>
92
+ )}
93
+
94
+ <nav style={{ display: 'flex', gap: 8, marginBottom: 20, flexWrap: 'wrap' }}>
95
+ {(['organizations', 'organization-units', 'users', 'groups', 'scim'] as Tab[]).map((t) => (
96
+ <button
97
+ key={t}
98
+ onClick={() => setTab(t)}
99
+ style={{
100
+ padding: '8px 16px',
101
+ borderRadius: 8,
102
+ border: '1px solid #cbd5e1',
103
+ background: tab === t ? '#2563eb' : '#fff',
104
+ color: tab === t ? '#fff' : '#0f172a',
105
+ cursor: 'pointer',
106
+ fontWeight: 600,
107
+ }}
108
+ >
109
+ {t === 'scim' ? 'Real-Time SCIM 2.0' : t.replace('-', ' ').toUpperCase()}
110
+ </button>
111
+ ))}
112
+ </nav>
113
+
114
+ <section style={{ background: '#fff', border: '1px solid #e2e8f0', borderRadius: 12, padding: 20, marginBottom: 20 }}>
115
+ <h2 style={{ marginTop: 0, fontSize: 18 }}>Create {tab}</h2>
116
+ <form onSubmit={handleCreate} style={{ display: 'flex', gap: 10, flexWrap: 'wrap', alignItems: 'center' }}>
117
+ <input
118
+ value={name}
119
+ onChange={(e) => setName(e.target.value)}
120
+ placeholder={tab === 'users' || tab === 'scim' ? 'Display Name' : 'Name'}
121
+ required
122
+ style={{ padding: '8px 12px', borderRadius: 6, border: '1px solid #cbd5e1', minWidth: 200 }}
123
+ />
124
+ {(tab === 'users' || tab === 'scim') && (
125
+ <input
126
+ type="email"
127
+ value={email}
128
+ onChange={(e) => setEmail(e.target.value)}
129
+ placeholder="Email address"
130
+ required
131
+ style={{ padding: '8px 12px', borderRadius: 6, border: '1px solid #cbd5e1', minWidth: 220 }}
132
+ />
133
+ )}
134
+ {tab === 'organization-units' && (
135
+ <input
136
+ value={orgId}
137
+ onChange={(e) => setOrgId(e.target.value)}
138
+ placeholder="Organization ID"
139
+ required
140
+ style={{ padding: '8px 12px', borderRadius: 6, border: '1px solid #cbd5e1', minWidth: 200 }}
141
+ />
142
+ )}
143
+ <button type="submit" style={{ padding: '8px 16px', borderRadius: 6, border: 'none', background: '#0f172a', color: '#fff', cursor: 'pointer', fontWeight: 600 }}>
144
+ {tab === 'scim' ? 'Push User via SCIM' : 'Create'}
145
+ </button>
146
+ {status && <span style={{ fontSize: 13, color: '#475569' }}>{status}</span>}
147
+ </form>
148
+ </section>
149
+
150
+ <section style={{ background: '#fff', border: '1px solid #e2e8f0', borderRadius: 12, padding: 20 }}>
151
+ <div style={{ display: 'flex', justifyContent: 'space-between', alignItems: 'center', marginBottom: 12 }}>
152
+ <h2 style={{ margin: 0, fontSize: 18 }}>{tab === 'scim' ? 'Live SCIM 2.0 Sync Log & Directory' : `${tab} Directory`}</h2>
153
+ <button onClick={() => loadTab(tab)} style={{ padding: '6px 12px', borderRadius: 6, border: '1px solid #cbd5e1', background: '#fff', cursor: 'pointer' }}>
154
+ Refresh
155
+ </button>
156
+ </div>
157
+ <pre style={{ background: '#0f172a', color: '#e2e8f0', padding: 16, borderRadius: 8, overflowX: 'auto', fontSize: 13 }}>
158
+ {JSON.stringify(tab === 'scim' ? scimState : data, null, 2)}
159
+ </pre>
160
+ </section>
161
+ </main>
162
+ );
163
+ }
164
+
@@ -0,0 +1,16 @@
1
+ 'use client';
2
+
3
+ import { SsoIdProvider } from '@sso-id/react';
4
+
5
+ export function Providers({ children }: { children: React.ReactNode }) {
6
+ return (
7
+ <SsoIdProvider
8
+ domain={process.env.NEXT_PUBLIC_SSO_ID_DOMAIN || 'acme.sso.id'}
9
+ clientId={process.env.NEXT_PUBLIC_SSO_ID_CLIENT_ID || 'YOUR_CLIENT_ID'}
10
+ redirectUri={process.env.NEXT_PUBLIC_SSO_ID_REDIRECT_URI || 'http://localhost:3000/api/auth/callback'}
11
+ >
12
+ {children}
13
+ </SsoIdProvider>
14
+ );
15
+ }
16
+
@@ -0,0 +1,12 @@
1
+ import { NextResponse } from 'next/server';
2
+ import { formatScimError, verifyScimBearerToken } from '@sso-id/node';
3
+
4
+ export function requireScimAuth(req: Request): NextResponse | null {
5
+ const expected = process.env.SSO_ID_SCIM_BEARER_TOKEN || '';
6
+ const auth = req.headers.get('authorization') ?? undefined;
7
+ if (!verifyScimBearerToken(auth, expected)) {
8
+ return NextResponse.json(formatScimError('Unauthorized SCIM request', 401), { status: 401 });
9
+ }
10
+ return null;
11
+ }
12
+
@@ -0,0 +1,39 @@
1
+ import { ManagementClient, type ScimGroupResource, type ScimUserResource } from '@sso-id/node';
2
+
3
+ export function getManagementClient() {
4
+ return new ManagementClient({
5
+ domain: process.env.SSO_ID_DOMAIN || 'acme.sso.id',
6
+ clientId: process.env.SSO_ID_M2M_CLIENT_ID || process.env.SSO_ID_CLIENT_ID || '',
7
+ clientSecret: process.env.SSO_ID_M2M_CLIENT_SECRET || process.env.SSO_ID_CLIENT_SECRET || '',
8
+ apiBaseUrl: process.env.SSO_ID_API_BASE_URL || 'https://api.sso.id',
9
+ });
10
+ }
11
+
12
+ export interface ScimEvent {
13
+ id: string;
14
+ timestamp: string;
15
+ direction: 'inbound' | 'outbound';
16
+ resourceType: 'User' | 'Group';
17
+ operation: 'CREATE' | 'UPDATE' | 'PATCH' | 'DELETE';
18
+ targetId: string;
19
+ summary: string;
20
+ }
21
+
22
+ class ScimRealtimeStore {
23
+ users = new Map<string, ScimUserResource>();
24
+ groups = new Map<string, ScimGroupResource>();
25
+ events: ScimEvent[] = [];
26
+
27
+ record(event: Omit<ScimEvent, 'id' | 'timestamp'>) {
28
+ this.events.unshift({
29
+ ...event,
30
+ id: `evt_${Date.now()}_${Math.random().toString(36).slice(2, 7)}`,
31
+ timestamp: new Date().toISOString(),
32
+ });
33
+ if (this.events.length > 100) this.events.length = 100;
34
+ }
35
+ }
36
+
37
+ const globalForScim = globalThis as unknown as { __scimStore?: ScimRealtimeStore };
38
+ export const scimStore = globalForScim.__scimStore ?? (globalForScim.__scimStore = new ScimRealtimeStore());
39
+
@@ -0,0 +1,24 @@
1
+ {
2
+ "compilerOptions": {
3
+ "target": "ES2022",
4
+ "lib": ["dom", "dom.iterable", "esnext"],
5
+ "allowJs": true,
6
+ "skipLibCheck": true,
7
+ "strict": true,
8
+ "noEmit": true,
9
+ "esModuleInterop": true,
10
+ "module": "esnext",
11
+ "moduleResolution": "bundler",
12
+ "resolveJsonModule": true,
13
+ "isolatedModules": true,
14
+ "jsx": "preserve",
15
+ "incremental": true,
16
+ "plugins": [{ "name": "next" }],
17
+ "paths": {
18
+ "@/*": ["./src/*"]
19
+ }
20
+ },
21
+ "include": ["next-env.d.ts", "**/*.ts", "**/*.tsx", ".next/types/**/*.ts"],
22
+ "exclude": ["node_modules"]
23
+ }
24
+
@@ -0,0 +1,6 @@
1
+ SSO_ID_DOMAIN=acme.sso.id
2
+ SSO_ID_CLIENT_ID=YOUR_M2M_CLIENT_ID
3
+ SSO_ID_CLIENT_SECRET=YOUR_M2M_CLIENT_SECRET
4
+ SSO_ID_API_BASE_URL=https://api.sso.id
5
+ SSO_ID_SCIM_BEARER_TOKEN=REPLACE_WITH_STRONG_SCIM_TOKEN
6
+
@@ -0,0 +1,9 @@
1
+ {
2
+ "name": "sso-id/php-starter",
3
+ "description": "Pre-configured PHP starter for SSO.ID OIDC, Management API, and SCIM 2.0",
4
+ "require": {
5
+ "php": "^8.2",
6
+ "sso-id/sso-id-php": "^0.1.0"
7
+ }
8
+ }
9
+
@@ -0,0 +1,34 @@
1
+ <?php
2
+ declare(strict_types=1);
3
+
4
+ header('Content-Type: application/scim+json');
5
+
6
+ $method = $_SERVER['REQUEST_METHOD'] ?? 'GET';
7
+ $path = parse_url($_SERVER['REQUEST_URI'] ?? '/', PHP_URL_PATH);
8
+ $scimToken = getenv('SSO_ID_SCIM_BEARER_TOKEN') ?: '';
9
+ $authHeader = $_SERVER['HTTP_AUTHORIZATION'] ?? '';
10
+
11
+ if (str_starts_with($path, '/scim/v2')) {
12
+ $provided = str_starts_with($authHeader, 'Bearer ') ? trim(substr($authHeader, 7)) : '';
13
+ if ($scimToken === '' || !hash_equals($scimToken, $provided)) {
14
+ http_response_code(401);
15
+ echo json_encode(['schemas' => ['urn:ietf:params:scim:api:messages:2.0:Error'], 'detail' => 'Unauthorized', 'status' => '401']);
16
+ exit;
17
+ }
18
+
19
+ if ($path === '/scim/v2/Users' && $method === 'GET') {
20
+ echo json_encode(['schemas' => ['urn:ietf:params:scim:api:messages:2.0:ListResponse'], 'totalResults' => 0, 'Resources' => []]);
21
+ exit;
22
+ }
23
+
24
+ if ($path === '/scim/v2/Users' && $method === 'POST') {
25
+ $payload = json_decode(file_get_contents('php://input') ?: '{}', true) ?? [];
26
+ $payload['id'] = $payload['id'] ?? bin2hex(random_bytes(8));
27
+ http_response_code(201);
28
+ echo json_encode($payload);
29
+ exit;
30
+ }
31
+ }
32
+
33
+ echo json_encode(['status' => 'SSO.ID PHP + SCIM 2.0 Starter Ready']);
34
+
@@ -0,0 +1,7 @@
1
+ SSO_ID_DOMAIN=acme.sso.id
2
+ SSO_ID_CLIENT_ID=YOUR_M2M_CLIENT_ID
3
+ SSO_ID_CLIENT_SECRET=YOUR_M2M_CLIENT_SECRET
4
+ SSO_ID_API_BASE_URL=https://api.sso.id
5
+ SSO_ID_AUDIENCE=
6
+ SSO_ID_SCIM_BEARER_TOKEN=REPLACE_WITH_STRONG_SCIM_TOKEN
7
+
@@ -0,0 +1,155 @@
1
+ import hmac
2
+ import os
3
+ import uuid
4
+ from datetime import datetime, timezone
5
+ from fastapi import Depends, FastAPI, Header, HTTPException, Request
6
+ import httpx
7
+ from dotenv import load_dotenv
8
+ from sso_id.jwt import verify_access_token
9
+
10
+ load_dotenv()
11
+
12
+ app = FastAPI(title="SSO.ID FastAPI + SCIM 2.0 + Management Starter")
13
+
14
+ DOMAIN = os.getenv("SSO_ID_DOMAIN", "acme.sso.id")
15
+ CLIENT_ID = os.getenv("SSO_ID_CLIENT_ID", "")
16
+ CLIENT_SECRET = os.getenv("SSO_ID_CLIENT_SECRET", "")
17
+ API_BASE = os.getenv("SSO_ID_API_BASE_URL", "https://api.sso.id").rstrip("/")
18
+ AUDIENCE = os.getenv("SSO_ID_AUDIENCE") or None
19
+ SCIM_TOKEN = os.getenv("SSO_ID_SCIM_BEARER_TOKEN", "")
20
+
21
+ scim_users: dict[str, dict] = {}
22
+ scim_groups: dict[str, dict] = {}
23
+ scim_events: list[dict] = []
24
+
25
+
26
+ def require_jwt(authorization: str = Header(default="")):
27
+ if not authorization.startswith("Bearer "):
28
+ raise HTTPException(status_code=401, detail="Missing Bearer token")
29
+ return verify_access_token(authorization[7:], domain=DOMAIN, audience=AUDIENCE)
30
+
31
+
32
+ def require_scim(authorization: str = Header(default="")):
33
+ if not authorization.startswith("Bearer ") or not SCIM_TOKEN:
34
+ raise HTTPException(status_code=401, detail="Unauthorized SCIM request")
35
+ provided = authorization[7:].strip()
36
+ if not hmac.compare_digest(provided, SCIM_TOKEN):
37
+ raise HTTPException(status_code=401, detail="Invalid SCIM bearer token")
38
+
39
+
40
+ async def get_m2m_token() -> str:
41
+ async with httpx.AsyncClient() as client:
42
+ res = await client.post(
43
+ f"https://{DOMAIN}/auth/oauth/token",
44
+ data={
45
+ "grant_type": "client_credentials",
46
+ "client_id": CLIENT_ID,
47
+ "client_secret": CLIENT_SECRET,
48
+ },
49
+ )
50
+ res.raise_for_status()
51
+ return res.json()["access_token"]
52
+
53
+
54
+ async def mgmt_request(method: str, path: str, payload: dict | None = None):
55
+ token = await get_m2m_token()
56
+ async with httpx.AsyncClient() as client:
57
+ res = await client.request(
58
+ method,
59
+ f"{API_BASE}{path}",
60
+ headers={"Authorization": f"Bearer {token}"},
61
+ json=payload,
62
+ )
63
+ res.raise_for_status()
64
+ return res.json() if res.content else {}
65
+
66
+
67
+ @app.get("/api/organizations", dependencies=[Depends(require_jwt)])
68
+ async def list_orgs():
69
+ return await mgmt_request("GET", "/api/organizations")
70
+
71
+
72
+ @app.post("/api/organizations", dependencies=[Depends(require_jwt)])
73
+ async def create_org(req: Request):
74
+ return await mgmt_request("POST", "/api/organizations", await req.json())
75
+
76
+
77
+ @app.get("/api/organization-units", dependencies=[Depends(require_jwt)])
78
+ async def list_ous(organizationId: str | None = None):
79
+ path = f"/api/organization-units/organizationunit/organization/{organizationId}" if organizationId else "/api/organization-units"
80
+ return await mgmt_request("GET", path)
81
+
82
+
83
+ @app.post("/api/organization-units", dependencies=[Depends(require_jwt)])
84
+ async def create_ou(req: Request):
85
+ return await mgmt_request("POST", "/api/organization-units", await req.json())
86
+
87
+
88
+ @app.get("/api/users", dependencies=[Depends(require_jwt)])
89
+ async def list_users():
90
+ return await mgmt_request("GET", "/api/users")
91
+
92
+
93
+ @app.post("/api/users", dependencies=[Depends(require_jwt)])
94
+ async def create_user(req: Request):
95
+ return await mgmt_request("POST", "/api/users", await req.json())
96
+
97
+
98
+ @app.get("/api/groups", dependencies=[Depends(require_jwt)])
99
+ async def list_groups():
100
+ return await mgmt_request("GET", "/api/groups")
101
+
102
+
103
+ @app.post("/api/groups", dependencies=[Depends(require_jwt)])
104
+ async def create_group(req: Request):
105
+ return await mgmt_request("POST", "/api/groups", await req.json())
106
+
107
+
108
+ @app.get("/scim/v2/Users", dependencies=[Depends(require_scim)])
109
+ def scim_list_users():
110
+ resources = list(scim_users.values())
111
+ return {
112
+ "schemas": ["urn:ietf:params:scim:api:messages:2.0:ListResponse"],
113
+ "totalResults": len(resources),
114
+ "startIndex": 1,
115
+ "itemsPerPage": len(resources),
116
+ "Resources": resources,
117
+ }
118
+
119
+
120
+ @app.post("/scim/v2/Users", status_code=201, dependencies=[Depends(require_scim)])
121
+ async def scim_create_user(req: Request):
122
+ body = await req.json()
123
+ uid = body.get("id") or str(uuid.uuid4())
124
+ body["id"] = uid
125
+ scim_users[uid] = body
126
+ scim_events.insert(0, {"type": "User", "op": "CREATE", "id": uid, "at": datetime.now(timezone.utc).isoformat()})
127
+ return body
128
+
129
+
130
+ @app.get("/scim/v2/Groups", dependencies=[Depends(require_scim)])
131
+ def scim_list_groups():
132
+ resources = list(scim_groups.values())
133
+ return {
134
+ "schemas": ["urn:ietf:params:scim:api:messages:2.0:ListResponse"],
135
+ "totalResults": len(resources),
136
+ "startIndex": 1,
137
+ "itemsPerPage": len(resources),
138
+ "Resources": resources,
139
+ }
140
+
141
+
142
+ @app.post("/scim/v2/Groups", status_code=201, dependencies=[Depends(require_scim)])
143
+ async def scim_create_group(req: Request):
144
+ body = await req.json()
145
+ gid = body.get("id") or str(uuid.uuid4())
146
+ body["id"] = gid
147
+ scim_groups[gid] = body
148
+ scim_events.insert(0, {"type": "Group", "op": "CREATE", "id": gid, "at": datetime.now(timezone.utc).isoformat()})
149
+ return body
150
+
151
+
152
+ @app.get("/api/scim/events", dependencies=[Depends(require_jwt)])
153
+ def get_scim_events():
154
+ return {"users": list(scim_users.values()), "groups": list(scim_groups.values()), "events": scim_events}
155
+
@@ -0,0 +1,6 @@
1
+ fastapi>=0.115.0
2
+ uvicorn[standard]>=0.30.0
3
+ httpx>=0.27.0
4
+ python-dotenv>=1.0.1
5
+ sso-id-python>=0.1.0
6
+
@@ -0,0 +1,5 @@
1
+ VITE_SSO_ID_DOMAIN=acme.sso.id
2
+ VITE_SSO_ID_CLIENT_ID=YOUR_SPA_CLIENT_ID
3
+ VITE_SSO_ID_REDIRECT_URI=http://localhost:5173/callback
4
+ VITE_API_BASE_URL=http://localhost:4000
5
+
@@ -0,0 +1,25 @@
1
+ {
2
+ "name": "sso-id-react-template",
3
+ "version": "0.1.0",
4
+ "private": true,
5
+ "type": "module",
6
+ "scripts": {
7
+ "dev": "vite",
8
+ "build": "tsc && vite build",
9
+ "preview": "vite preview"
10
+ },
11
+ "dependencies": {
12
+ "@sso-id/react": "^0.1.0",
13
+ "@sso-id/ui": "^0.1.0",
14
+ "react": "^18.3.1",
15
+ "react-dom": "^18.3.1"
16
+ },
17
+ "devDependencies": {
18
+ "@types/react": "^18.3.0",
19
+ "@types/react-dom": "^18.3.0",
20
+ "@vitejs/plugin-react": "^4.3.0",
21
+ "typescript": "^5.6.0",
22
+ "vite": "^5.4.0"
23
+ }
24
+ }
25
+
@@ -0,0 +1,67 @@
1
+ import { useEffect, useState } from 'react';
2
+ import { useSsoId } from '@sso-id/react';
3
+ import { SignInButton, UserMenu } from '@sso-id/ui';
4
+
5
+ const API = import.meta.env.VITE_API_BASE_URL || 'http://localhost:4000';
6
+
7
+ export default function App() {
8
+ const { isAuthenticated, user, getAccessTokenSilently } = useSsoId();
9
+ const [tab, setTab] = useState<'organizations' | 'organization-units' | 'users' | 'groups' | 'scim'>('organizations');
10
+ const [result, setResult] = useState<unknown>(null);
11
+ const [name, setName] = useState('');
12
+
13
+ async function apiFetch(path: string, init?: RequestInit) {
14
+ const token = await getAccessTokenSilently();
15
+ const res = await fetch(`${API}${path}`, {
16
+ ...init,
17
+ headers: {
18
+ 'Content-Type': 'application/json',
19
+ Authorization: `Bearer ${token}`,
20
+ ...(init?.headers || {}),
21
+ },
22
+ });
23
+ return res.json();
24
+ }
25
+
26
+ useEffect(() => {
27
+ if (!isAuthenticated) return;
28
+ const path = tab === 'scim' ? '/api/scim/events' : `/api/${tab}`;
29
+ apiFetch(path).then(setResult).catch(console.error);
30
+ }, [isAuthenticated, tab]);
31
+
32
+ async function handleCreate(e: React.FormEvent) {
33
+ e.preventDefault();
34
+ const path = tab === 'scim' ? '/api/scim/push-user' : `/api/${tab}`;
35
+ const body = tab === 'users' || tab === 'scim' ? { email: name, userName: name, displayName: name } : { name };
36
+ await apiFetch(path, { method: 'POST', body: JSON.stringify(body) });
37
+ setName('');
38
+ setResult(await apiFetch(tab === 'scim' ? '/api/scim/events' : `/api/${tab}`));
39
+ }
40
+
41
+ return (
42
+ <div style={{ maxWidth: 960, margin: '32px auto', fontFamily: 'system-ui, sans-serif', padding: 16 }}>
43
+ <header style={{ display: 'flex', justifyContent: 'space-between', alignItems: 'center', marginBottom: 24 }}>
44
+ <h1>SSO.ID React Starter (OIDC + Orgs/OUs/Users/Groups + SCIM)</h1>
45
+ {isAuthenticated ? <UserMenu /> : <SignInButton />}
46
+ </header>
47
+ {isAuthenticated && (
48
+ <>
49
+ <p>Signed in as <strong>{String(user?.email || user?.sub)}</strong></p>
50
+ <div style={{ display: 'flex', gap: 8, marginBottom: 16 }}>
51
+ {(['organizations', 'organization-units', 'users', 'groups', 'scim'] as const).map((t) => (
52
+ <button key={t} onClick={() => setTab(t)} style={{ padding: '6px 12px', fontWeight: tab === t ? 700 : 400 }}>
53
+ {t}
54
+ </button>
55
+ ))}
56
+ </div>
57
+ <form onSubmit={handleCreate} style={{ display: 'flex', gap: 8, marginBottom: 16 }}>
58
+ <input value={name} onChange={(e) => setName(e.target.value)} placeholder={tab === 'users' || tab === 'scim' ? 'email@acme.com' : 'Name'} required />
59
+ <button type="submit">Create</button>
60
+ </form>
61
+ <pre style={{ background: '#0f172a', color: '#e2e8f0', padding: 16, borderRadius: 8 }}>{JSON.stringify(result, null, 2)}</pre>
62
+ </>
63
+ )}
64
+ </div>
65
+ );
66
+ }
67
+
@@ -0,0 +1,17 @@
1
+ import React from 'react';
2
+ import ReactDOM from 'react-dom/client';
3
+ import { SsoIdProvider } from '@sso-id/react';
4
+ import App from './App';
5
+
6
+ ReactDOM.createRoot(document.getElementById('root')!).render(
7
+ <React.StrictMode>
8
+ <SsoIdProvider
9
+ domain={import.meta.env.VITE_SSO_ID_DOMAIN || 'acme.sso.id'}
10
+ clientId={import.meta.env.VITE_SSO_ID_CLIENT_ID || 'YOUR_CLIENT_ID'}
11
+ redirectUri={import.meta.env.VITE_SSO_ID_REDIRECT_URI || `${window.location.origin}/callback`}
12
+ >
13
+ <App />
14
+ </SsoIdProvider>
15
+ </React.StrictMode>,
16
+ );
17
+
@@ -0,0 +1,5 @@
1
+ VITE_SSO_ID_DOMAIN=acme.sso.id
2
+ VITE_SSO_ID_CLIENT_ID=YOUR_SPA_CLIENT_ID
3
+ VITE_SSO_ID_REDIRECT_URI=http://localhost:5173/callback
4
+ VITE_API_BASE_URL=http://localhost:4000
5
+
@@ -0,0 +1,20 @@
1
+ {
2
+ "name": "sso-id-vue-template",
3
+ "version": "0.1.0",
4
+ "private": true,
5
+ "type": "module",
6
+ "scripts": {
7
+ "dev": "vite",
8
+ "build": "vite build"
9
+ },
10
+ "dependencies": {
11
+ "@sso-id/vue": "^0.1.0",
12
+ "vue": "^3.5.0"
13
+ },
14
+ "devDependencies": {
15
+ "@vitejs/plugin-vue": "^5.1.0",
16
+ "typescript": "^5.6.0",
17
+ "vite": "^5.4.0"
18
+ }
19
+ }
20
+