@sso-id/cli 0.1.0 → 0.2.1

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 +171 -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
package/bin/sso-id.mjs CHANGED
@@ -1,4 +1,23 @@
1
1
  #!/usr/bin/env node
2
+ import { randomBytes } from 'node:crypto';
3
+ import { cpSync, existsSync, mkdirSync, readFileSync, writeFileSync } from 'node:fs';
4
+ import { dirname, join, resolve } from 'node:path';
5
+ import { fileURLToPath } from 'node:url';
6
+
7
+ const __dirname = dirname(fileURLToPath(import.meta.url));
8
+
9
+ export const AVAILABLE_TEMPLATES = [
10
+ 'nextjs',
11
+ 'react-spa',
12
+ 'angular-spa',
13
+ 'vue-spa',
14
+ 'express-api',
15
+ 'dotnet-api',
16
+ 'python-fastapi',
17
+ 'go-gin',
18
+ 'php-laravel',
19
+ 'mobile-react-native',
20
+ ];
2
21
 
3
22
  export function decodeJwt(token) {
4
23
  const parts = token.split('.');
@@ -10,24 +29,170 @@ export function decodeJwt(token) {
10
29
  return { header, payload };
11
30
  }
12
31
 
13
- export function generateEnvTemplate({ domain, clientId, redirectUri }) {
14
- return [
32
+ export function generateEnvTemplate({ domain, clientId, clientSecret, redirectUri, scimToken }) {
33
+ const lines = [
15
34
  `SSO_ID_DOMAIN=${domain}`,
16
35
  `SSO_ID_CLIENT_ID=${clientId}`,
17
36
  `SSO_ID_REDIRECT_URI=${redirectUri || 'http://localhost:3000/callback'}`,
18
- ].join('\n');
37
+ ];
38
+ if (clientSecret) lines.push(`SSO_ID_CLIENT_SECRET=${clientSecret}`);
39
+ if (scimToken) lines.push(`SSO_ID_SCIM_BEARER_TOKEN=${scimToken}`);
40
+ return lines.join('\n');
41
+ }
42
+
43
+ export function parseFlags(argv) {
44
+ const flags = {};
45
+ const positional = [];
46
+ for (let i = 0; i < argv.length; i += 1) {
47
+ const arg = argv[i];
48
+ if (arg.startsWith('--')) {
49
+ const key = arg.slice(2);
50
+ const next = argv[i + 1];
51
+ if (next && !next.startsWith('--')) {
52
+ flags[key] = next;
53
+ i += 1;
54
+ } else {
55
+ flags[key] = 'true';
56
+ }
57
+ } else {
58
+ positional.push(arg);
59
+ }
60
+ }
61
+ return { flags, positional };
62
+ }
63
+
64
+ export function applyEnvOverrides(templateEnv, overrides) {
65
+ let content = templateEnv;
66
+ const sessionSecret = overrides.sessionSecret || randomBytes(32).toString('hex');
67
+ const replacements = {
68
+ SSO_ID_DOMAIN: overrides.domain,
69
+ NEXT_PUBLIC_SSO_ID_DOMAIN: overrides.domain,
70
+ VITE_SSO_ID_DOMAIN: overrides.domain,
71
+ SSO_ID_CLIENT_ID: overrides.clientId,
72
+ NEXT_PUBLIC_SSO_ID_CLIENT_ID: overrides.clientId,
73
+ VITE_SSO_ID_CLIENT_ID: overrides.clientId,
74
+ SSO_ID_CLIENT_SECRET: overrides.clientSecret,
75
+ SSO_ID_REDIRECT_URI: overrides.redirectUri,
76
+ NEXT_PUBLIC_SSO_ID_REDIRECT_URI: overrides.redirectUri,
77
+ VITE_SSO_ID_REDIRECT_URI: overrides.redirectUri,
78
+ SSO_ID_M2M_CLIENT_ID: overrides.m2mClientId || overrides.clientId,
79
+ SSO_ID_M2M_CLIENT_SECRET: overrides.m2mClientSecret || overrides.clientSecret,
80
+ SSO_ID_API_BASE_URL: overrides.apiBaseUrl,
81
+ SSO_ID_AUDIENCE: overrides.audience,
82
+ SSO_ID_SESSION_SECRET: sessionSecret,
83
+ SSO_ID_SCIM_BEARER_TOKEN: overrides.scimToken,
84
+ SSO_ID_SCIM_CONNECTION_ID: overrides.scimConnectionId,
85
+ };
86
+ for (const [key, val] of Object.entries(replacements)) {
87
+ if (!val) continue;
88
+ const regex = new RegExp(`^${key}=.*$`, 'gm');
89
+ if (regex.test(content)) {
90
+ content = content.replace(regex, `${key}=${val}`);
91
+ } else {
92
+ content += `\n${key}=${val}`;
93
+ }
94
+ }
95
+ return `${content.trimEnd()}\n`;
96
+ }
97
+
98
+ function patchStructuredConfigs(destDir, overrides) {
99
+ const angularEnvPath = join(destDir, 'src', 'environments', 'environment.ts');
100
+ if (existsSync(angularEnvPath)) {
101
+ let ngEnv = readFileSync(angularEnvPath, 'utf8');
102
+ if (overrides.domain) ngEnv = ngEnv.replace(/ssoIdDomain:\s*'[^']*'/, `ssoIdDomain: '${overrides.domain}'`);
103
+ if (overrides.clientId) ngEnv = ngEnv.replace(/ssoIdClientId:\s*'[^']*'/, `ssoIdClientId: '${overrides.clientId}'`);
104
+ if (overrides.redirectUri) ngEnv = ngEnv.replace(/ssoIdRedirectUri:\s*'[^']*'/, `ssoIdRedirectUri: '${overrides.redirectUri}'`);
105
+ writeFileSync(angularEnvPath, ngEnv, 'utf8');
106
+ }
107
+
108
+ const appsettingsPath = join(destDir, 'appsettings.json');
109
+ if (existsSync(appsettingsPath)) {
110
+ const cfg = JSON.parse(readFileSync(appsettingsPath, 'utf8'));
111
+ cfg.SsoId = cfg.SsoId || {};
112
+ cfg.Scim = cfg.Scim || {};
113
+ if (overrides.domain) cfg.SsoId.Domain = overrides.domain;
114
+ if (overrides.m2mClientId || overrides.clientId) cfg.SsoId.ClientId = overrides.m2mClientId || overrides.clientId;
115
+ if (overrides.m2mClientSecret || overrides.clientSecret) cfg.SsoId.ClientSecret = overrides.m2mClientSecret || overrides.clientSecret;
116
+ if (overrides.apiBaseUrl) cfg.SsoId.ApiBaseUrl = overrides.apiBaseUrl;
117
+ if (overrides.audience) cfg.SsoId.Audience = overrides.audience;
118
+ if (overrides.scimToken) cfg.Scim.BearerToken = overrides.scimToken;
119
+ if (overrides.scimConnectionId) cfg.Scim.ConnectionId = overrides.scimConnectionId;
120
+ writeFileSync(appsettingsPath, `${JSON.stringify(cfg, null, 2)}\n`, 'utf8');
121
+ }
122
+ }
123
+
124
+ export function scaffoldTemplate(templateName, targetDir, overrides = {}) {
125
+ if (!AVAILABLE_TEMPLATES.includes(templateName)) {
126
+ throw new Error(`Unknown template "${templateName}". Available: ${AVAILABLE_TEMPLATES.join(', ')}`);
127
+ }
128
+ const bundledTemplates = resolve(__dirname, '..', 'templates');
129
+ const workspaceTemplates = resolve(__dirname, '..', '..', '..', 'templates');
130
+ const templatesRoot = existsSync(bundledTemplates) ? bundledTemplates : workspaceTemplates;
131
+ const sourceDir = join(templatesRoot, templateName);
132
+ const destDir = resolve(targetDir || `sso-id-${templateName}`);
133
+ mkdirSync(destDir, { recursive: true });
134
+
135
+ if (existsSync(sourceDir)) {
136
+ cpSync(sourceDir, destDir, { recursive: true });
137
+ const envExamplePath = join(destDir, '.env.example');
138
+ const baseEnv = existsSync(envExamplePath)
139
+ ? readFileSync(envExamplePath, 'utf8')
140
+ : generateEnvTemplate({ domain: 'acme.sso.id', clientId: 'YOUR_CLIENT_ID', ...overrides });
141
+ writeFileSync(join(destDir, '.env'), applyEnvOverrides(baseEnv, overrides), 'utf8');
142
+ patchStructuredConfigs(destDir, overrides);
143
+ } else {
144
+ writeFileSync(
145
+ join(destDir, '.env'),
146
+ generateEnvTemplate({ domain: overrides.domain || 'acme.sso.id', clientId: overrides.clientId || 'YOUR_CLIENT_ID', ...overrides }),
147
+ 'utf8',
148
+ );
149
+ }
150
+ return destDir;
19
151
  }
20
152
 
21
153
  async function main() {
22
- const [, , cmd, arg1] = process.argv;
154
+ const { flags, positional } = parseFlags(process.argv.slice(2));
155
+ const [cmd, arg1, arg2] = positional;
156
+
23
157
  if (!cmd || cmd === '--help' || cmd === '-h') {
24
- console.log('Usage: sso-id <command>\n\nCommands:\n init <domain> <clientId> Print .env starter config\n decode-token <jwt> Decode JWT header & payload\n test-discovery <domain> Fetch OIDC discovery metadata');
158
+ console.log(
159
+ 'Usage: sso-id <command>\n\nCommands:\n' +
160
+ ' list-templates List pre-built SSO.ID starter templates\n' +
161
+ ' create <template> [dir] [--domain ...] Scaffold a pre-configured template with SCIM & Management API\n' +
162
+ ' init <domain> <clientId> Print .env starter config\n' +
163
+ ' decode-token <jwt> Decode JWT header & payload\n' +
164
+ ' test-discovery <domain> Fetch OIDC discovery metadata',
165
+ );
166
+ return;
167
+ }
168
+
169
+ if (cmd === 'list-templates') {
170
+ console.log(AVAILABLE_TEMPLATES.join('\n'));
171
+ return;
172
+ }
173
+
174
+ if (cmd === 'create') {
175
+ if (!arg1) throw new Error(`Specify a template name. Available: ${AVAILABLE_TEMPLATES.join(', ')}`);
176
+ const dest = scaffoldTemplate(arg1, arg2, {
177
+ domain: flags.domain,
178
+ clientId: flags['client-id'],
179
+ clientSecret: flags['client-secret'],
180
+ m2mClientId: flags['m2m-client-id'],
181
+ m2mClientSecret: flags['m2m-client-secret'],
182
+ redirectUri: flags['redirect-uri'],
183
+ apiBaseUrl: flags['api-base-url'],
184
+ sessionSecret: flags['session-secret'],
185
+ audience: flags.audience,
186
+ scimToken: flags['scim-token'],
187
+ scimConnectionId: flags['scim-connection-id'],
188
+ });
189
+ console.log(`Created SSO.ID "${arg1}" starter at: ${dest}`);
25
190
  return;
26
191
  }
27
192
 
28
193
  if (cmd === 'init') {
29
194
  const domain = arg1 || 'acme.sso.id';
30
- const clientId = process.argv[4] || 'YOUR_CLIENT_ID';
195
+ const clientId = arg2 || 'YOUR_CLIENT_ID';
31
196
  console.log(generateEnvTemplate({ domain, clientId }));
32
197
  return;
33
198
  }
@@ -57,4 +222,3 @@ if (isDirectRun) {
57
222
  process.exit(1);
58
223
  });
59
224
  }
60
-
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sso-id/cli",
3
- "version": "0.1.0",
3
+ "version": "0.2.1",
4
4
  "type": "module",
5
5
  "description": "Official SSO.ID Developer CLI (init, decode-token, test-discovery)",
6
6
  "bin": {
@@ -24,6 +24,7 @@
24
24
  "access": "public"
25
25
  },
26
26
  "files": [
27
- "bin"
27
+ "bin",
28
+ "templates"
28
29
  ]
29
30
  }
@@ -0,0 +1,19 @@
1
+ {
2
+ "name": "sso-id-angular-template",
3
+ "version": "0.1.0",
4
+ "private": true,
5
+ "scripts": {
6
+ "start": "ng serve",
7
+ "build": "ng build"
8
+ },
9
+ "dependencies": {
10
+ "@angular/common": "^18.2.0",
11
+ "@angular/core": "^18.2.0",
12
+ "@angular/forms": "^18.2.0",
13
+ "@angular/platform-browser": "^18.2.0",
14
+ "@angular/router": "^18.2.0",
15
+ "@sso-id/angular": "^0.1.0",
16
+ "rxjs": "^7.8.1"
17
+ }
18
+ }
19
+
@@ -0,0 +1,63 @@
1
+ import { Component, OnInit, inject } from '@angular/core';
2
+ import { CommonModule } from '@angular/common';
3
+ import { FormsModule } from '@angular/forms';
4
+ import { HttpClient } from '@angular/common/http';
5
+ import { SsoIdService } from '@sso-id/angular';
6
+ import { environment } from '../environments/environment';
7
+
8
+ @Component({
9
+ selector: 'app-root',
10
+ standalone: true,
11
+ imports: [CommonModule, FormsModule],
12
+ template: `
13
+ <main style="max-width:960px;margin:32px auto;font-family:system-ui,sans-serif;padding:16px">
14
+ <header style="display:flex;justify-content:space-between;align-items:center;margin-bottom:24px">
15
+ <h1>SSO.ID Angular Starter</h1>
16
+ <button *ngIf="!(sso.isAuthenticated$ | async)" (click)="sso.loginWithRedirect()">Sign In with SSO.ID</button>
17
+ <button *ngIf="sso.isAuthenticated$ | async" (click)="sso.logout()">Sign Out</button>
18
+ </header>
19
+ <section *ngIf="sso.isAuthenticated$ | async">
20
+ <div style="display:flex;gap:8px;margin-bottom:16px">
21
+ <button *ngFor="let t of tabs" (click)="selectTab(t)">{{ t }}</button>
22
+ </div>
23
+ <form (ngSubmit)="create()" style="display:flex;gap:8px;margin-bottom:16px">
24
+ <input [(ngModel)]="name" name="name" placeholder="Name or email" required />
25
+ <button type="submit">Create</button>
26
+ </form>
27
+ <pre style="background:#0f172a;color:#e2e8f0;padding:16px;border-radius:8px">{{ data | json }}</pre>
28
+ </section>
29
+ </main>
30
+ `,
31
+ })
32
+ export class AppComponent implements OnInit {
33
+ sso = inject(SsoIdService);
34
+ private http = inject(HttpClient);
35
+ tabs = ['organizations', 'organization-units', 'users', 'groups', 'scim'] as const;
36
+ tab: (typeof this.tabs)[number] = 'organizations';
37
+ name = '';
38
+ data: unknown = null;
39
+
40
+ ngOnInit(): void {
41
+ this.load();
42
+ }
43
+
44
+ selectTab(tab: (typeof this.tabs)[number]): void {
45
+ this.tab = tab;
46
+ this.load();
47
+ }
48
+
49
+ load(): void {
50
+ const path = this.tab === 'scim' ? '/api/scim/events' : `/api/${this.tab}`;
51
+ this.http.get(`${environment.apiBaseUrl}${path}`).subscribe((res) => (this.data = res));
52
+ }
53
+
54
+ create(): void {
55
+ const path = this.tab === 'scim' ? '/api/scim/push-user' : `/api/${this.tab}`;
56
+ const body = this.tab === 'users' || this.tab === 'scim' ? { email: this.name, userName: this.name, displayName: this.name } : { name: this.name };
57
+ this.http.post(`${environment.apiBaseUrl}${path}`, body).subscribe(() => {
58
+ this.name = '';
59
+ this.load();
60
+ });
61
+ }
62
+ }
63
+
@@ -0,0 +1,16 @@
1
+ import { ApplicationConfig } from '@angular/core';
2
+ import { provideHttpClient, withInterceptors } from '@angular/common/http';
3
+ import { provideSsoId, ssoIdHttpInterceptor } from '@sso-id/angular';
4
+ import { environment } from '../environments/environment';
5
+
6
+ export const appConfig: ApplicationConfig = {
7
+ providers: [
8
+ provideHttpClient(withInterceptors([ssoIdHttpInterceptor])),
9
+ provideSsoId({
10
+ domain: environment.ssoIdDomain,
11
+ clientId: environment.ssoIdClientId,
12
+ redirectUri: environment.ssoIdRedirectUri,
13
+ }),
14
+ ],
15
+ };
16
+
@@ -0,0 +1,7 @@
1
+ export const environment = {
2
+ ssoIdDomain: 'acme.sso.id',
3
+ ssoIdClientId: 'YOUR_SPA_CLIENT_ID',
4
+ ssoIdRedirectUri: 'http://localhost:4200/callback',
5
+ apiBaseUrl: 'http://localhost:5000',
6
+ };
7
+
@@ -0,0 +1,121 @@
1
+ using System.Collections.Concurrent;
2
+ using System.Security.Cryptography;
3
+ using System.Text;
4
+ using System.Text.Json;
5
+ using Microsoft.AspNetCore.Authorization;
6
+ using SsoId.AspNetCore;
7
+ using SsoId.ManagementApi;
8
+
9
+ var builder = WebApplication.CreateBuilder(args);
10
+
11
+ var domain = builder.Configuration["SsoId:Domain"] ?? "acme.sso.id";
12
+ var audience = builder.Configuration["SsoId:Audience"] ?? "https://api.acme.com";
13
+ var scimToken = builder.Configuration["Scim:BearerToken"] ?? "";
14
+
15
+ builder.Services.AddSsoIdApi(opts =>
16
+ {
17
+ opts.Domain = domain;
18
+ opts.Audience = audience;
19
+ });
20
+
21
+ builder.Services.AddSingleton(new SsoManagementOptions
22
+ {
23
+ Domain = domain,
24
+ ClientId = builder.Configuration["SsoId:ClientId"] ?? "",
25
+ ClientSecret = builder.Configuration["SsoId:ClientSecret"] ?? "",
26
+ ApiBaseUrl = builder.Configuration["SsoId:ApiBaseUrl"] ?? "https://api.sso.id",
27
+ });
28
+ builder.Services.AddHttpClient<ISsoManagementClient, SsoManagementClient>();
29
+ builder.Services.AddCors(o => o.AddDefaultPolicy(p => p.AllowAnyOrigin().AllowAnyHeader().AllowAnyMethod()));
30
+
31
+ var app = builder.Build();
32
+ app.UseCors();
33
+ app.UseAuthentication();
34
+ app.UseAuthorization();
35
+
36
+ var scimUsers = new ConcurrentDictionary<string, JsonElement>();
37
+ var scimGroups = new ConcurrentDictionary<string, JsonElement>();
38
+ var scimEvents = new ConcurrentQueue<object>();
39
+
40
+ bool ValidScimToken(HttpRequest req)
41
+ {
42
+ var header = req.Headers.Authorization.ToString();
43
+ if (!header.StartsWith("Bearer ", StringComparison.OrdinalIgnoreCase) || string.IsNullOrEmpty(scimToken))
44
+ return false;
45
+ var a = Encoding.UTF8.GetBytes(header["Bearer ".Length..].Trim());
46
+ var b = Encoding.UTF8.GetBytes(scimToken);
47
+ return a.Length == b.Length && CryptographicOperations.FixedTimeEquals(a, b);
48
+ }
49
+
50
+ // Management API routes (Organizations, OUs, Users, Groups)
51
+ app.MapGet("/api/organizations", [Authorize] (ISsoManagementClient mgmt, CancellationToken ct) => mgmt.ListOrganizationsAsync(ct));
52
+ app.MapPost("/api/organizations", [Authorize] (JsonElement body, ISsoManagementClient mgmt, CancellationToken ct) => mgmt.CreateOrganizationAsync(body, ct));
53
+
54
+ app.MapGet("/api/organization-units", [Authorize] (string? organizationId, ISsoManagementClient mgmt, CancellationToken ct) => mgmt.ListOrganizationUnitsAsync(organizationId, ct));
55
+ app.MapPost("/api/organization-units", [Authorize] (JsonElement body, ISsoManagementClient mgmt, CancellationToken ct) => mgmt.CreateOrganizationUnitAsync(body, ct));
56
+
57
+ app.MapGet("/api/users", [Authorize] (ISsoManagementClient mgmt, CancellationToken ct) => mgmt.ListUsersAsync(1, 50, ct));
58
+ app.MapPost("/api/users", [Authorize] (JsonElement body, ISsoManagementClient mgmt, CancellationToken ct) => mgmt.CreateUserAsync(body, ct));
59
+
60
+ app.MapGet("/api/groups", [Authorize] (ISsoManagementClient mgmt, CancellationToken ct) => mgmt.ListGroupsAsync(ct));
61
+ app.MapPost("/api/groups", [Authorize] (JsonElement body, ISsoManagementClient mgmt, CancellationToken ct) => mgmt.CreateGroupAsync(body, ct));
62
+
63
+ // Real-Time SCIM 2.0 Receiver
64
+ app.MapGet("/scim/v2/Users", (HttpRequest req) =>
65
+ {
66
+ if (!ValidScimToken(req)) return Results.Unauthorized();
67
+ var list = scimUsers.Values.ToList();
68
+ return Results.Ok(new
69
+ {
70
+ schemas = new[] { "urn:ietf:params:scim:api:messages:2.0:ListResponse" },
71
+ totalResults = list.Count,
72
+ startIndex = 1,
73
+ itemsPerPage = list.Count,
74
+ Resources = list,
75
+ });
76
+ });
77
+
78
+ app.MapPost("/scim/v2/Users", (HttpRequest req, JsonElement body) =>
79
+ {
80
+ if (!ValidScimToken(req)) return Results.Unauthorized();
81
+ var id = body.TryGetProperty("id", out var idProp) ? idProp.GetString() ?? Guid.NewGuid().ToString() : Guid.NewGuid().ToString();
82
+ scimUsers[id] = body;
83
+ scimEvents.Enqueue(new { type = "User", op = "CREATE", id, at = DateTimeOffset.UtcNow });
84
+ return Results.Created($"/scim/v2/Users/{id}", body);
85
+ });
86
+
87
+ app.MapDelete("/scim/v2/Users/{id}", (HttpRequest req, string id) =>
88
+ {
89
+ if (!ValidScimToken(req)) return Results.Unauthorized();
90
+ scimUsers.TryRemove(id, out _);
91
+ scimEvents.Enqueue(new { type = "User", op = "DELETE", id, at = DateTimeOffset.UtcNow });
92
+ return Results.NoContent();
93
+ });
94
+
95
+ app.MapGet("/scim/v2/Groups", (HttpRequest req) =>
96
+ {
97
+ if (!ValidScimToken(req)) return Results.Unauthorized();
98
+ var list = scimGroups.Values.ToList();
99
+ return Results.Ok(new
100
+ {
101
+ schemas = new[] { "urn:ietf:params:scim:api:messages:2.0:ListResponse" },
102
+ totalResults = list.Count,
103
+ startIndex = 1,
104
+ itemsPerPage = list.Count,
105
+ Resources = list,
106
+ });
107
+ });
108
+
109
+ app.MapPost("/scim/v2/Groups", (HttpRequest req, JsonElement body) =>
110
+ {
111
+ if (!ValidScimToken(req)) return Results.Unauthorized();
112
+ var id = body.TryGetProperty("id", out var idProp) ? idProp.GetString() ?? Guid.NewGuid().ToString() : Guid.NewGuid().ToString();
113
+ scimGroups[id] = body;
114
+ scimEvents.Enqueue(new { type = "Group", op = "CREATE", id, at = DateTimeOffset.UtcNow });
115
+ return Results.Created($"/scim/v2/Groups/{id}", body);
116
+ });
117
+
118
+ app.MapGet("/api/scim/events", [Authorize] () => Results.Ok(new { users = scimUsers.Values, groups = scimGroups.Values, events = scimEvents }));
119
+
120
+ app.Run();
121
+
@@ -0,0 +1,12 @@
1
+ <Project Sdk="Microsoft.NET.Sdk.Web">
2
+ <PropertyGroup>
3
+ <TargetFramework>net8.0</TargetFramework>
4
+ <Nullable>enable</Nullable>
5
+ <ImplicitUsings>enable</ImplicitUsings>
6
+ </PropertyGroup>
7
+ <ItemGroup>
8
+ <PackageReference Include="SsoId.AspNetCore" Version="0.1.0" />
9
+ <PackageReference Include="SsoId.ManagementApi" Version="0.1.0" />
10
+ </ItemGroup>
11
+ </Project>
12
+
@@ -0,0 +1,14 @@
1
+ {
2
+ "SsoId": {
3
+ "Domain": "acme.sso.id",
4
+ "Audience": "https://api.acme.com",
5
+ "ClientId": "YOUR_M2M_CLIENT_ID",
6
+ "ClientSecret": "YOUR_M2M_CLIENT_SECRET",
7
+ "ApiBaseUrl": "https://api.sso.id"
8
+ },
9
+ "Scim": {
10
+ "BearerToken": "REPLACE_WITH_STRONG_SCIM_TOKEN",
11
+ "ConnectionId": ""
12
+ }
13
+ }
14
+
@@ -0,0 +1,12 @@
1
+ PORT=4000
2
+ SSO_ID_DOMAIN=acme.sso.id
3
+ SSO_ID_CLIENT_ID=YOUR_CLIENT_ID
4
+ SSO_ID_CLIENT_SECRET=YOUR_CLIENT_SECRET
5
+ SSO_ID_BASE_URL=http://localhost:4000
6
+ SSO_ID_SESSION_SECRET=REPLACE_WITH_LONG_RANDOM_SECRET
7
+ SSO_ID_API_BASE_URL=https://api.sso.id
8
+ SSO_ID_AUDIENCE=
9
+ SSO_ID_SCIM_BEARER_TOKEN=REPLACE_WITH_STRONG_SCIM_TOKEN
10
+ SSO_ID_SCIM_CONNECTION_ID=
11
+ CORS_ORIGIN=http://localhost:5173
12
+
@@ -0,0 +1,8 @@
1
+ # SSO.ID Express + SCIM 2.0 + Management API Template
2
+
3
+ Pre-configured Express backend using `@sso-id/express` and `@sso-id/node`:
4
+ - OIDC login/callback/logout (`/login`, `/callback`, `/logout`)
5
+ - Bearer JWT + session verification for SPAs & Mobile apps
6
+ - Organizations, Organization Units, Users, and Groups Management API routes
7
+ - Real-Time SCIM 2.0 receiver (`/scim/v2/Users`, `/scim/v2/Groups`) and outbound SCIM push (`/api/scim/push-user`)
8
+
@@ -0,0 +1,18 @@
1
+ {
2
+ "name": "sso-id-express-template",
3
+ "version": "0.1.0",
4
+ "private": true,
5
+ "type": "module",
6
+ "scripts": {
7
+ "dev": "node --watch src/server.mjs",
8
+ "start": "node src/server.mjs"
9
+ },
10
+ "dependencies": {
11
+ "@sso-id/express": "^0.1.0",
12
+ "@sso-id/node": "^0.2.0",
13
+ "cors": "^2.8.5",
14
+ "dotenv": "^16.4.5",
15
+ "express": "^4.21.0"
16
+ }
17
+ }
18
+