@sso-id/node 0.0.0-stage → 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.
@@ -0,0 +1,3 @@
1
+ export * from './jwt.js';
2
+ export * from './management.js';
3
+ export * from './scim.js';
package/dist/index.js ADDED
@@ -0,0 +1,3 @@
1
+ export * from './jwt.js';
2
+ export * from './management.js';
3
+ export * from './scim.js';
package/dist/jwt.d.ts ADDED
@@ -0,0 +1,42 @@
1
+ import { type JsonWebKey } from 'node:crypto';
2
+ export interface VerifyTokenOptions {
3
+ /** Tenant domain (e.g. "acme.sso.id" or "https://acme.sso.id") */
4
+ domain: string;
5
+ /** Expected audience (`aud`) claim, optional */
6
+ audience?: string;
7
+ /** Expected issuer (`iss`) claim, defaults to normalized domain */
8
+ issuer?: string;
9
+ /** Clock tolerance in seconds (default: 60) */
10
+ clockToleranceSec?: number;
11
+ /** Optional static JWKS keys for offline/unit-test verification */
12
+ jwksKeys?: JwkKey[];
13
+ }
14
+ export interface JwkKey extends JsonWebKey {
15
+ kid?: string;
16
+ kty: string;
17
+ alg?: string;
18
+ use?: string;
19
+ }
20
+ export interface SsoIdJwtClaims {
21
+ sub: string;
22
+ iss?: string;
23
+ aud?: string | string[];
24
+ exp?: number;
25
+ iat?: number;
26
+ nbf?: number;
27
+ email?: string;
28
+ name?: string;
29
+ org_id?: string;
30
+ roles?: string[];
31
+ permissions?: string[];
32
+ [key: string]: unknown;
33
+ }
34
+ export declare function verifyAccessToken(token: string, options: VerifyTokenOptions): Promise<SsoIdJwtClaims>;
35
+ export declare function requireSsoIdAuth(options: VerifyTokenOptions): (req: {
36
+ headers: Record<string, string | string[] | undefined>;
37
+ ssoIdUser?: SsoIdJwtClaims;
38
+ }, res: {
39
+ status: (code: number) => {
40
+ json: (body: unknown) => void;
41
+ };
42
+ }, next: () => void) => Promise<void>;
package/dist/jwt.js ADDED
@@ -0,0 +1,86 @@
1
+ import { createPublicKey, verify } from 'node:crypto';
2
+ const jwksCache = new Map();
3
+ function normalizeDomain(domain) {
4
+ const clean = domain.replace(/\/+$/, '');
5
+ return clean.startsWith('http') ? clean : `https://${clean}`;
6
+ }
7
+ function decodeBase64UrlJson(segment) {
8
+ const json = Buffer.from(segment, 'base64url').toString('utf8');
9
+ return JSON.parse(json);
10
+ }
11
+ async function fetchJwks(baseUrl) {
12
+ const cached = jwksCache.get(baseUrl);
13
+ if (cached && Date.now() < cached.expiresAt) {
14
+ return cached.keys;
15
+ }
16
+ const res = await fetch(`${baseUrl}/auth/.well-known/jwks.json`);
17
+ if (!res.ok) {
18
+ throw new Error(`Failed to fetch SSO.ID JWKS (${res.status})`);
19
+ }
20
+ const body = (await res.json());
21
+ const keys = body.keys ?? [];
22
+ jwksCache.set(baseUrl, { keys, expiresAt: Date.now() + 5 * 60 * 1000 });
23
+ return keys;
24
+ }
25
+ export async function verifyAccessToken(token, options) {
26
+ const parts = token.split('.');
27
+ if (parts.length !== 3) {
28
+ throw new Error('Invalid JWT format');
29
+ }
30
+ const [headerB64, payloadB64, signatureB64] = parts;
31
+ const header = decodeBase64UrlJson(headerB64);
32
+ if (header.alg !== 'RS256') {
33
+ throw new Error(`Unsupported JWT algorithm: ${header.alg ?? 'unknown'}`);
34
+ }
35
+ const claims = decodeBase64UrlJson(payloadB64);
36
+ const baseUrl = normalizeDomain(options.domain);
37
+ const keys = options.jwksKeys ?? (await fetchJwks(baseUrl));
38
+ const matchingKey = (header.kid ? keys.find((k) => k.kid === header.kid) : undefined) ?? keys[0];
39
+ if (!matchingKey) {
40
+ throw new Error('No matching JWK found for token');
41
+ }
42
+ const publicKey = createPublicKey({ key: matchingKey, format: 'jwk' });
43
+ const signingInput = Buffer.from(`${headerB64}.${payloadB64}`, 'utf8');
44
+ const signature = Buffer.from(signatureB64, 'base64url');
45
+ const valid = verify('RSA-SHA256', signingInput, publicKey, signature);
46
+ if (!valid) {
47
+ throw new Error('Invalid JWT signature');
48
+ }
49
+ const nowSec = Math.floor(Date.now() / 1000);
50
+ const tolerance = options.clockToleranceSec ?? 60;
51
+ if (typeof claims.exp === 'number' && nowSec - tolerance >= claims.exp) {
52
+ throw new Error('JWT has expired');
53
+ }
54
+ if (typeof claims.nbf === 'number' && nowSec + tolerance < claims.nbf) {
55
+ throw new Error('JWT is not yet valid');
56
+ }
57
+ const expectedIssuer = options.issuer ?? baseUrl;
58
+ if (expectedIssuer && claims.iss && claims.iss.replace(/\/+$/, '') !== expectedIssuer.replace(/\/+$/, '')) {
59
+ throw new Error(`Invalid issuer: expected ${expectedIssuer}, got ${claims.iss}`);
60
+ }
61
+ if (options.audience) {
62
+ const audList = Array.isArray(claims.aud) ? claims.aud : claims.aud ? [claims.aud] : [];
63
+ if (!audList.includes(options.audience)) {
64
+ throw new Error(`Invalid audience: expected ${options.audience}`);
65
+ }
66
+ }
67
+ return claims;
68
+ }
69
+ export function requireSsoIdAuth(options) {
70
+ return async (req, res, next) => {
71
+ try {
72
+ const raw = req.headers.authorization;
73
+ const header = Array.isArray(raw) ? raw[0] : raw;
74
+ if (!header || !header.startsWith('Bearer ')) {
75
+ res.status(401).json({ error: 'Missing Bearer token' });
76
+ return;
77
+ }
78
+ const token = header.slice('Bearer '.length).trim();
79
+ req.ssoIdUser = await verifyAccessToken(token, options);
80
+ next();
81
+ }
82
+ catch (err) {
83
+ res.status(401).json({ error: err instanceof Error ? err.message : 'Unauthorized' });
84
+ }
85
+ };
86
+ }
@@ -0,0 +1,102 @@
1
+ import type { ScimGroupResource, ScimUserResource } from './scim.js';
2
+ export interface ManagementClientOptions {
3
+ /** Tenant domain (e.g. "acme.sso.id" or "https://acme.sso.id") */
4
+ domain: string;
5
+ clientId: string;
6
+ clientSecret: string;
7
+ /** Management API base URL (defaults to "https://api.sso.id") */
8
+ apiBaseUrl?: string;
9
+ audience?: string;
10
+ }
11
+ export declare class ManagementClient {
12
+ private readonly authBaseUrl;
13
+ private readonly apiBaseUrl;
14
+ private readonly options;
15
+ private cachedToken;
16
+ constructor(options: ManagementClientOptions);
17
+ private getAccessToken;
18
+ private request;
19
+ readonly users: {
20
+ list: (query?: {
21
+ page?: number;
22
+ pageSize?: number;
23
+ search?: string;
24
+ }) => Promise<unknown>;
25
+ get: (userId: string) => Promise<unknown>;
26
+ create: (data: Record<string, unknown>) => Promise<unknown>;
27
+ invite: (data: Record<string, unknown>) => Promise<unknown>;
28
+ update: (userId: string, data: Record<string, unknown>) => Promise<unknown>;
29
+ delete: (userId: string) => Promise<void>;
30
+ listRoles: (userId: string) => Promise<unknown>;
31
+ assignRole: (userId: string, roleId: string) => Promise<void>;
32
+ removeRole: (userId: string, roleId: string) => Promise<void>;
33
+ };
34
+ readonly roles: {
35
+ list: () => Promise<unknown>;
36
+ create: (data: {
37
+ name: string;
38
+ description?: string;
39
+ }) => Promise<unknown>;
40
+ assignToUser: (userId: string, roleId: string) => Promise<void>;
41
+ };
42
+ readonly organizations: {
43
+ list: () => Promise<unknown>;
44
+ get: (orgId: string) => Promise<unknown>;
45
+ create: (data: Record<string, unknown>) => Promise<unknown>;
46
+ update: (orgId: string, data: Record<string, unknown>) => Promise<unknown>;
47
+ delete: (orgId: string) => Promise<void>;
48
+ listUsers: (orgId: string) => Promise<unknown>;
49
+ addUser: (orgId: string, data: Record<string, unknown>) => Promise<unknown>;
50
+ removeUser: (orgId: string, userId: string) => Promise<void>;
51
+ listGroups: (orgId: string) => Promise<unknown>;
52
+ addGroup: (orgId: string, data: Record<string, unknown>) => Promise<unknown>;
53
+ removeGroup: (orgId: string, groupId: string) => Promise<void>;
54
+ };
55
+ readonly organizationUnits: {
56
+ list: () => Promise<unknown>;
57
+ listByOrganization: (orgId: string) => Promise<unknown>;
58
+ get: (orgId: string, unitId: string) => Promise<unknown>;
59
+ create: (data: Record<string, unknown>) => Promise<unknown>;
60
+ update: (unitId: string, data: Record<string, unknown>) => Promise<unknown>;
61
+ delete: (unitId: string) => Promise<void>;
62
+ listUsers: (unitId: string) => Promise<unknown>;
63
+ addUser: (data: Record<string, unknown>) => Promise<unknown>;
64
+ removeUser: (orgId: string, unitId: string, userId: string) => Promise<void>;
65
+ listGroups: (unitId: string) => Promise<unknown>;
66
+ addGroup: (data: Record<string, unknown>) => Promise<unknown>;
67
+ removeGroup: (unitId: string, groupId: string) => Promise<void>;
68
+ };
69
+ readonly groups: {
70
+ list: () => Promise<unknown>;
71
+ get: (groupId: string) => Promise<unknown>;
72
+ create: (data: Record<string, unknown>) => Promise<unknown>;
73
+ update: (groupId: string, data: Record<string, unknown>) => Promise<unknown>;
74
+ delete: (groupId: string) => Promise<void>;
75
+ listUsers: (groupId: string) => Promise<unknown>;
76
+ addUser: (groupId: string, userId: string) => Promise<unknown>;
77
+ removeUser: (groupId: string, userId: string) => Promise<void>;
78
+ };
79
+ readonly scim: {
80
+ forConnection: (connectionId?: string) => {
81
+ serviceProviderConfig: () => Promise<unknown>;
82
+ schemas: () => Promise<unknown>;
83
+ listUsers: (filter?: string) => Promise<unknown>;
84
+ getUser: (id: string) => Promise<ScimUserResource>;
85
+ createUser: (user: ScimUserResource) => Promise<ScimUserResource>;
86
+ replaceUser: (id: string, user: ScimUserResource) => Promise<ScimUserResource>;
87
+ patchUser: (id: string, patchPayload: Record<string, unknown>) => Promise<ScimUserResource>;
88
+ deleteUser: (id: string) => Promise<void>;
89
+ listGroups: (filter?: string) => Promise<unknown>;
90
+ getGroup: (id: string) => Promise<ScimGroupResource>;
91
+ createGroup: (group: ScimGroupResource) => Promise<ScimGroupResource>;
92
+ replaceGroup: (id: string, group: ScimGroupResource) => Promise<ScimGroupResource>;
93
+ deleteGroup: (id: string) => Promise<void>;
94
+ };
95
+ };
96
+ readonly auditLogs: {
97
+ list: (query?: {
98
+ page?: number;
99
+ pageSize?: number;
100
+ }) => Promise<unknown>;
101
+ };
102
+ }
@@ -0,0 +1,153 @@
1
+ export class ManagementClient {
2
+ authBaseUrl;
3
+ apiBaseUrl;
4
+ options;
5
+ cachedToken = null;
6
+ constructor(options) {
7
+ const clean = options.domain.replace(/\/+$/, '');
8
+ this.authBaseUrl = clean.startsWith('http') ? clean : `https://${clean}`;
9
+ this.apiBaseUrl = (options.apiBaseUrl ?? 'https://api.sso.id').replace(/\/+$/, '');
10
+ this.options = options;
11
+ }
12
+ async getAccessToken() {
13
+ if (this.cachedToken && Date.now() < this.cachedToken.expiresAt - 30_000) {
14
+ return this.cachedToken.token;
15
+ }
16
+ const body = new URLSearchParams({
17
+ grant_type: 'client_credentials',
18
+ client_id: this.options.clientId,
19
+ client_secret: this.options.clientSecret,
20
+ ...(this.options.audience ? { audience: this.options.audience } : {}),
21
+ });
22
+ const res = await fetch(`${this.authBaseUrl}/auth/oauth/token`, {
23
+ method: 'POST',
24
+ headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
25
+ body: body.toString(),
26
+ });
27
+ if (!res.ok) {
28
+ const text = await res.text();
29
+ throw new Error(`SSO.ID M2M token request failed (${res.status}): ${text}`);
30
+ }
31
+ const data = (await res.json());
32
+ this.cachedToken = {
33
+ token: data.access_token,
34
+ expiresAt: Date.now() + (data.expires_in ?? 3600) * 1000,
35
+ };
36
+ return this.cachedToken.token;
37
+ }
38
+ async request(method, path, payload) {
39
+ const token = await this.getAccessToken();
40
+ const res = await fetch(`${this.apiBaseUrl}${path}`, {
41
+ method,
42
+ headers: {
43
+ Authorization: `Bearer ${token}`,
44
+ ...(payload !== undefined ? { 'Content-Type': 'application/json' } : {}),
45
+ },
46
+ body: payload !== undefined ? JSON.stringify(payload) : undefined,
47
+ });
48
+ if (!res.ok) {
49
+ const text = await res.text();
50
+ throw new Error(`SSO.ID Management API ${method} ${path} failed (${res.status}): ${text}`);
51
+ }
52
+ if (res.status === 204) {
53
+ return undefined;
54
+ }
55
+ return (await res.json());
56
+ }
57
+ users = {
58
+ list: (query) => {
59
+ const params = new URLSearchParams();
60
+ if (query?.page)
61
+ params.set('page', String(query.page));
62
+ if (query?.pageSize)
63
+ params.set('pageSize', String(query.pageSize));
64
+ if (query?.search)
65
+ params.set('search', query.search);
66
+ const qs = params.toString();
67
+ return this.request('GET', `/api/users${qs ? `?${qs}` : ''}`);
68
+ },
69
+ get: (userId) => this.request('GET', `/api/users/${encodeURIComponent(userId)}`),
70
+ create: (data) => this.request('POST', '/api/users', data),
71
+ invite: (data) => this.request('POST', '/api/users/invite', data),
72
+ update: (userId, data) => this.request('PUT', `/api/users/${encodeURIComponent(userId)}`, data),
73
+ delete: (userId) => this.request('DELETE', `/api/users/${encodeURIComponent(userId)}`),
74
+ listRoles: (userId) => this.request('GET', `/api/users/${encodeURIComponent(userId)}/roles`),
75
+ assignRole: (userId, roleId) => this.request('POST', `/api/users/${encodeURIComponent(userId)}/roles`, { roleId }),
76
+ removeRole: (userId, roleId) => this.request('DELETE', `/api/users/${encodeURIComponent(userId)}/roles/${encodeURIComponent(roleId)}`),
77
+ };
78
+ roles = {
79
+ list: () => this.request('GET', '/api/v1/roles'),
80
+ create: (data) => this.request('POST', '/api/v1/roles', data),
81
+ assignToUser: (userId, roleId) => this.request('POST', `/api/users/${encodeURIComponent(userId)}/roles`, { roleId }),
82
+ };
83
+ organizations = {
84
+ list: () => this.request('GET', '/api/organizations'),
85
+ get: (orgId) => this.request('GET', `/api/organizations/${encodeURIComponent(orgId)}`),
86
+ create: (data) => this.request('POST', '/api/organizations', data),
87
+ update: (orgId, data) => this.request('PUT', `/api/organizations/${encodeURIComponent(orgId)}`, data),
88
+ delete: (orgId) => this.request('DELETE', `/api/organizations/${encodeURIComponent(orgId)}`),
89
+ listUsers: (orgId) => this.request('GET', `/api/organizations/${encodeURIComponent(orgId)}/users`),
90
+ addUser: (orgId, data) => this.request('POST', `/api/organizations/${encodeURIComponent(orgId)}/users`, data),
91
+ removeUser: (orgId, userId) => this.request('DELETE', `/api/organizations/${encodeURIComponent(orgId)}/users/${encodeURIComponent(userId)}`),
92
+ listGroups: (orgId) => this.request('GET', `/api/organizations/${encodeURIComponent(orgId)}/groups`),
93
+ addGroup: (orgId, data) => this.request('POST', `/api/organizations/${encodeURIComponent(orgId)}/groups`, data),
94
+ removeGroup: (orgId, groupId) => this.request('DELETE', `/api/organizations/${encodeURIComponent(orgId)}/groups/${encodeURIComponent(groupId)}`),
95
+ };
96
+ organizationUnits = {
97
+ list: () => this.request('GET', '/api/organization-units'),
98
+ listByOrganization: (orgId) => this.request('GET', `/api/organization-units/organizationunit/organization/${encodeURIComponent(orgId)}`),
99
+ get: (orgId, unitId) => this.request('GET', `/api/organization-units/organization/${encodeURIComponent(orgId)}/organizationunit/${encodeURIComponent(unitId)}`),
100
+ create: (data) => this.request('POST', '/api/organization-units', data),
101
+ update: (unitId, data) => this.request('PUT', `/api/organization-units/${encodeURIComponent(unitId)}`, data),
102
+ delete: (unitId) => this.request('DELETE', `/api/organization-units/${encodeURIComponent(unitId)}`),
103
+ listUsers: (unitId) => this.request('GET', `/api/organization-units/organizationunit/${encodeURIComponent(unitId)}/users`),
104
+ addUser: (data) => this.request('POST', '/api/organization-units/organizationunit/user', data),
105
+ removeUser: (orgId, unitId, userId) => this.request('DELETE', `/api/organization-units/organization/${encodeURIComponent(orgId)}/organizationunit/${encodeURIComponent(unitId)}/user/${encodeURIComponent(userId)}`),
106
+ listGroups: (unitId) => this.request('GET', `/api/organization-units/organizationunit/groups/${encodeURIComponent(unitId)}`),
107
+ addGroup: (data) => this.request('POST', '/api/organization-units/organizationunit/group', data),
108
+ removeGroup: (unitId, groupId) => this.request('DELETE', `/api/organization-units/organizationUnit/${encodeURIComponent(unitId)}/group/${encodeURIComponent(groupId)}`),
109
+ };
110
+ groups = {
111
+ list: () => this.request('GET', '/api/groups'),
112
+ get: (groupId) => this.request('GET', `/api/groups/${encodeURIComponent(groupId)}`),
113
+ create: (data) => this.request('POST', '/api/groups', data),
114
+ update: (groupId, data) => this.request('PUT', `/api/groups/${encodeURIComponent(groupId)}`, data),
115
+ delete: (groupId) => this.request('DELETE', `/api/groups/${encodeURIComponent(groupId)}`),
116
+ listUsers: (groupId) => this.request('GET', `/api/groups/${encodeURIComponent(groupId)}/users`),
117
+ addUser: (groupId, userId) => this.request('POST', `/api/groups/${encodeURIComponent(groupId)}/users/${encodeURIComponent(userId)}`),
118
+ removeUser: (groupId, userId) => this.request('DELETE', `/api/groups/${encodeURIComponent(groupId)}/users/${encodeURIComponent(userId)}`),
119
+ };
120
+ scim = {
121
+ forConnection: (connectionId) => {
122
+ const prefix = connectionId
123
+ ? `/api/scim/v2/connections/${encodeURIComponent(connectionId)}`
124
+ : '/api/scim/v2';
125
+ return {
126
+ serviceProviderConfig: () => this.request('GET', `${prefix}/ServiceProviderConfig`),
127
+ schemas: () => this.request('GET', `${prefix}/Schemas`),
128
+ listUsers: (filter) => this.request('GET', `${prefix}/Users${filter ? `?filter=${encodeURIComponent(filter)}` : ''}`),
129
+ getUser: (id) => this.request('GET', `${prefix}/Users/${encodeURIComponent(id)}`),
130
+ createUser: (user) => this.request('POST', `${prefix}/Users`, user),
131
+ replaceUser: (id, user) => this.request('PUT', `${prefix}/Users/${encodeURIComponent(id)}`, user),
132
+ patchUser: (id, patchPayload) => this.request('PATCH', `${prefix}/Users/${encodeURIComponent(id)}`, patchPayload),
133
+ deleteUser: (id) => this.request('DELETE', `${prefix}/Users/${encodeURIComponent(id)}`),
134
+ listGroups: (filter) => this.request('GET', `${prefix}/Groups${filter ? `?filter=${encodeURIComponent(filter)}` : ''}`),
135
+ getGroup: (id) => this.request('GET', `${prefix}/Groups/${encodeURIComponent(id)}`),
136
+ createGroup: (group) => this.request('POST', `${prefix}/Groups`, group),
137
+ replaceGroup: (id, group) => this.request('PUT', `${prefix}/Groups/${encodeURIComponent(id)}`, group),
138
+ deleteGroup: (id) => this.request('DELETE', `${prefix}/Groups/${encodeURIComponent(id)}`),
139
+ };
140
+ },
141
+ };
142
+ auditLogs = {
143
+ list: (query) => {
144
+ const params = new URLSearchParams();
145
+ if (query?.page)
146
+ params.set('page', String(query.page));
147
+ if (query?.pageSize)
148
+ params.set('pageSize', String(query.pageSize));
149
+ const qs = params.toString();
150
+ return this.request('GET', `/api/v1/audit-logs${qs ? `?${qs}` : ''}`);
151
+ },
152
+ };
153
+ }
package/dist/scim.d.ts ADDED
@@ -0,0 +1,58 @@
1
+ export declare const SCIM_CORE_USER_SCHEMA = "urn:ietf:params:scim:schemas:core:2.0:User";
2
+ export declare const SCIM_CORE_GROUP_SCHEMA = "urn:ietf:params:scim:schemas:core:2.0:Group";
3
+ export declare const SCIM_LIST_RESPONSE_SCHEMA = "urn:ietf:params:scim:api:messages:2.0:ListResponse";
4
+ export declare const SCIM_ERROR_SCHEMA = "urn:ietf:params:scim:api:messages:2.0:Error";
5
+ export interface ScimUserResource {
6
+ schemas?: string[];
7
+ id?: string;
8
+ externalId?: string;
9
+ userName: string;
10
+ name?: {
11
+ formatted?: string;
12
+ givenName?: string;
13
+ familyName?: string;
14
+ };
15
+ displayName?: string;
16
+ emails?: Array<{
17
+ value: string;
18
+ type?: string;
19
+ primary?: boolean;
20
+ }>;
21
+ active?: boolean;
22
+ meta?: {
23
+ resourceType?: string;
24
+ created?: string;
25
+ lastModified?: string;
26
+ };
27
+ }
28
+ export interface ScimGroupResource {
29
+ schemas?: string[];
30
+ id?: string;
31
+ externalId?: string;
32
+ displayName: string;
33
+ members?: Array<{
34
+ value: string;
35
+ display?: string;
36
+ $ref?: string;
37
+ }>;
38
+ meta?: {
39
+ resourceType?: string;
40
+ created?: string;
41
+ lastModified?: string;
42
+ };
43
+ }
44
+ export interface ScimListResponse<T> {
45
+ schemas: [typeof SCIM_LIST_RESPONSE_SCHEMA];
46
+ totalResults: number;
47
+ startIndex: number;
48
+ itemsPerPage: number;
49
+ Resources: T[];
50
+ }
51
+ export declare function verifyScimBearerToken(authHeader: string | undefined, expectedToken: string): boolean;
52
+ export declare function formatScimListResponse<T>(resources: T[], startIndex?: number, itemsPerPage?: number, totalResults?: number): ScimListResponse<T>;
53
+ export declare function formatScimError(detail: string, status: number, scimType?: string): {
54
+ scimType?: string | undefined;
55
+ schemas: string[];
56
+ detail: string;
57
+ status: string;
58
+ };
package/dist/scim.js ADDED
@@ -0,0 +1,34 @@
1
+ import { timingSafeEqual } from 'node:crypto';
2
+ export const SCIM_CORE_USER_SCHEMA = 'urn:ietf:params:scim:schemas:core:2.0:User';
3
+ export const SCIM_CORE_GROUP_SCHEMA = 'urn:ietf:params:scim:schemas:core:2.0:Group';
4
+ export const SCIM_LIST_RESPONSE_SCHEMA = 'urn:ietf:params:scim:api:messages:2.0:ListResponse';
5
+ export const SCIM_ERROR_SCHEMA = 'urn:ietf:params:scim:api:messages:2.0:Error';
6
+ export function verifyScimBearerToken(authHeader, expectedToken) {
7
+ if (!authHeader || !expectedToken)
8
+ return false;
9
+ const match = /^Bearer\s+(.+)$/i.exec(authHeader.trim());
10
+ if (!match)
11
+ return false;
12
+ const provided = Buffer.from(match[1]);
13
+ const expected = Buffer.from(expectedToken);
14
+ if (provided.length !== expected.length)
15
+ return false;
16
+ return timingSafeEqual(provided, expected);
17
+ }
18
+ export function formatScimListResponse(resources, startIndex = 1, itemsPerPage = resources.length, totalResults = resources.length) {
19
+ return {
20
+ schemas: [SCIM_LIST_RESPONSE_SCHEMA],
21
+ totalResults,
22
+ startIndex,
23
+ itemsPerPage,
24
+ Resources: resources,
25
+ };
26
+ }
27
+ export function formatScimError(detail, status, scimType) {
28
+ return {
29
+ schemas: [SCIM_ERROR_SCHEMA],
30
+ detail,
31
+ status: String(status),
32
+ ...(scimType ? { scimType } : {}),
33
+ };
34
+ }
package/package.json CHANGED
@@ -1,6 +1,36 @@
1
1
  {
2
2
  "name": "@sso-id/node",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "0.2.0",
4
+ "type": "module",
5
+ "description": "Official SSO.ID Node.js SDK (RS256 JWKS JWT verification, Express/Fastify middleware, Management API client)",
6
+ "main": "dist/index.js",
7
+ "module": "dist/index.js",
8
+ "types": "dist/index.d.ts",
9
+ "scripts": {
10
+ "build": "tsc",
11
+ "test": "node --test tests/*.test.mjs"
12
+ },
13
+ "keywords": [
14
+ "sso.id",
15
+ "node",
16
+ "jwt",
17
+ "jwks",
18
+ "oauth2",
19
+ "oidc",
20
+ "management-api"
21
+ ],
22
+ "license": "MIT",
23
+ "engines": {
24
+ "node": ">=18.0.0"
25
+ },
26
+ "devDependencies": {
27
+ "@types/node": "^20.11.0",
28
+ "typescript": "^5.4.0"
29
+ },
30
+ "publishConfig": {
31
+ "access": "public"
32
+ },
33
+ "files": [
34
+ "dist"
35
+ ]
36
+ }
package/README.md DELETED
@@ -1,3 +0,0 @@
1
- # Temporary Holding Version
2
-
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.