@sso-id/node 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.
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/management.d.ts +55 -0
- package/dist/management.js +68 -8
- package/dist/scim.d.ts +58 -0
- package/dist/scim.js +34 -0
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
package/dist/management.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { ScimGroupResource, ScimUserResource } from './scim.js';
|
|
1
2
|
export interface ManagementClientOptions {
|
|
2
3
|
/** Tenant domain (e.g. "acme.sso.id" or "https://acme.sso.id") */
|
|
3
4
|
domain: string;
|
|
@@ -23,8 +24,12 @@ export declare class ManagementClient {
|
|
|
23
24
|
}) => Promise<unknown>;
|
|
24
25
|
get: (userId: string) => Promise<unknown>;
|
|
25
26
|
create: (data: Record<string, unknown>) => Promise<unknown>;
|
|
27
|
+
invite: (data: Record<string, unknown>) => Promise<unknown>;
|
|
26
28
|
update: (userId: string, data: Record<string, unknown>) => Promise<unknown>;
|
|
27
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>;
|
|
28
33
|
};
|
|
29
34
|
readonly roles: {
|
|
30
35
|
list: () => Promise<unknown>;
|
|
@@ -37,6 +42,56 @@ export declare class ManagementClient {
|
|
|
37
42
|
readonly organizations: {
|
|
38
43
|
list: () => Promise<unknown>;
|
|
39
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
|
+
};
|
|
40
95
|
};
|
|
41
96
|
readonly auditLogs: {
|
|
42
97
|
list: (query?: {
|
package/dist/management.js
CHANGED
|
@@ -17,6 +17,7 @@ export class ManagementClient {
|
|
|
17
17
|
grant_type: 'client_credentials',
|
|
18
18
|
client_id: this.options.clientId,
|
|
19
19
|
client_secret: this.options.clientSecret,
|
|
20
|
+
redirect_uri: this.options.audience || this.authBaseUrl,
|
|
20
21
|
...(this.options.audience ? { audience: this.options.audience } : {}),
|
|
21
22
|
});
|
|
22
23
|
const res = await fetch(`${this.authBaseUrl}/auth/oauth/token`, {
|
|
@@ -64,21 +65,80 @@ export class ManagementClient {
|
|
|
64
65
|
if (query?.search)
|
|
65
66
|
params.set('search', query.search);
|
|
66
67
|
const qs = params.toString();
|
|
67
|
-
return this.request('GET', `/api/
|
|
68
|
+
return this.request('GET', `/api/users${qs ? `?${qs}` : ''}`);
|
|
68
69
|
},
|
|
69
|
-
get: (userId) => this.request('GET', `/api/
|
|
70
|
-
create: (data) => this.request('POST', '/api/
|
|
71
|
-
|
|
72
|
-
|
|
70
|
+
get: (userId) => this.request('GET', `/api/users/${encodeURIComponent(userId)}`),
|
|
71
|
+
create: (data) => this.request('POST', '/api/users', data),
|
|
72
|
+
invite: (data) => this.request('POST', '/api/users/invite', data),
|
|
73
|
+
update: (userId, data) => this.request('PUT', `/api/users/${encodeURIComponent(userId)}`, data),
|
|
74
|
+
delete: (userId) => this.request('DELETE', `/api/users/${encodeURIComponent(userId)}`),
|
|
75
|
+
listRoles: (userId) => this.request('GET', `/api/users/${encodeURIComponent(userId)}/roles`),
|
|
76
|
+
assignRole: (userId, roleId) => this.request('POST', `/api/users/${encodeURIComponent(userId)}/roles`, { roleId }),
|
|
77
|
+
removeRole: (userId, roleId) => this.request('DELETE', `/api/users/${encodeURIComponent(userId)}/roles/${encodeURIComponent(roleId)}`),
|
|
73
78
|
};
|
|
74
79
|
roles = {
|
|
75
80
|
list: () => this.request('GET', '/api/v1/roles'),
|
|
76
81
|
create: (data) => this.request('POST', '/api/v1/roles', data),
|
|
77
|
-
assignToUser: (userId, roleId) => this.request('POST', `/api/
|
|
82
|
+
assignToUser: (userId, roleId) => this.request('POST', `/api/users/${encodeURIComponent(userId)}/roles`, { roleId }),
|
|
78
83
|
};
|
|
79
84
|
organizations = {
|
|
80
|
-
list: () => this.request('GET', '/api/
|
|
81
|
-
get: (orgId) => this.request('GET', `/api/
|
|
85
|
+
list: () => this.request('GET', '/api/organizations'),
|
|
86
|
+
get: (orgId) => this.request('GET', `/api/organizations/${encodeURIComponent(orgId)}`),
|
|
87
|
+
create: (data) => this.request('POST', '/api/organizations', data),
|
|
88
|
+
update: (orgId, data) => this.request('PUT', `/api/organizations/${encodeURIComponent(orgId)}`, data),
|
|
89
|
+
delete: (orgId) => this.request('DELETE', `/api/organizations/${encodeURIComponent(orgId)}`),
|
|
90
|
+
listUsers: (orgId) => this.request('GET', `/api/organizations/${encodeURIComponent(orgId)}/users`),
|
|
91
|
+
addUser: (orgId, data) => this.request('POST', `/api/organizations/${encodeURIComponent(orgId)}/users`, data),
|
|
92
|
+
removeUser: (orgId, userId) => this.request('DELETE', `/api/organizations/${encodeURIComponent(orgId)}/users/${encodeURIComponent(userId)}`),
|
|
93
|
+
listGroups: (orgId) => this.request('GET', `/api/organizations/${encodeURIComponent(orgId)}/groups`),
|
|
94
|
+
addGroup: (orgId, data) => this.request('POST', `/api/organizations/${encodeURIComponent(orgId)}/groups`, data),
|
|
95
|
+
removeGroup: (orgId, groupId) => this.request('DELETE', `/api/organizations/${encodeURIComponent(orgId)}/groups/${encodeURIComponent(groupId)}`),
|
|
96
|
+
};
|
|
97
|
+
organizationUnits = {
|
|
98
|
+
list: () => this.request('GET', '/api/organization-units'),
|
|
99
|
+
listByOrganization: (orgId) => this.request('GET', `/api/organization-units/organizationunit/organization/${encodeURIComponent(orgId)}`),
|
|
100
|
+
get: (orgId, unitId) => this.request('GET', `/api/organization-units/organization/${encodeURIComponent(orgId)}/organizationunit/${encodeURIComponent(unitId)}`),
|
|
101
|
+
create: (data) => this.request('POST', '/api/organization-units', data),
|
|
102
|
+
update: (unitId, data) => this.request('PUT', `/api/organization-units/${encodeURIComponent(unitId)}`, data),
|
|
103
|
+
delete: (unitId) => this.request('DELETE', `/api/organization-units/${encodeURIComponent(unitId)}`),
|
|
104
|
+
listUsers: (unitId) => this.request('GET', `/api/organization-units/organizationunit/${encodeURIComponent(unitId)}/users`),
|
|
105
|
+
addUser: (data) => this.request('POST', '/api/organization-units/organizationunit/user', data),
|
|
106
|
+
removeUser: (orgId, unitId, userId) => this.request('DELETE', `/api/organization-units/organization/${encodeURIComponent(orgId)}/organizationunit/${encodeURIComponent(unitId)}/user/${encodeURIComponent(userId)}`),
|
|
107
|
+
listGroups: (unitId) => this.request('GET', `/api/organization-units/organizationunit/groups/${encodeURIComponent(unitId)}`),
|
|
108
|
+
addGroup: (data) => this.request('POST', '/api/organization-units/organizationunit/group', data),
|
|
109
|
+
removeGroup: (unitId, groupId) => this.request('DELETE', `/api/organization-units/organizationUnit/${encodeURIComponent(unitId)}/group/${encodeURIComponent(groupId)}`),
|
|
110
|
+
};
|
|
111
|
+
groups = {
|
|
112
|
+
list: () => this.request('GET', '/api/groups'),
|
|
113
|
+
get: (groupId) => this.request('GET', `/api/groups/${encodeURIComponent(groupId)}`),
|
|
114
|
+
create: (data) => this.request('POST', '/api/groups', data),
|
|
115
|
+
update: (groupId, data) => this.request('PUT', `/api/groups/${encodeURIComponent(groupId)}`, data),
|
|
116
|
+
delete: (groupId) => this.request('DELETE', `/api/groups/${encodeURIComponent(groupId)}`),
|
|
117
|
+
listUsers: (groupId) => this.request('GET', `/api/groups/${encodeURIComponent(groupId)}/users`),
|
|
118
|
+
addUser: (groupId, userId) => this.request('POST', `/api/groups/${encodeURIComponent(groupId)}/users/${encodeURIComponent(userId)}`),
|
|
119
|
+
removeUser: (groupId, userId) => this.request('DELETE', `/api/groups/${encodeURIComponent(groupId)}/users/${encodeURIComponent(userId)}`),
|
|
120
|
+
};
|
|
121
|
+
scim = {
|
|
122
|
+
forConnection: (connectionId) => {
|
|
123
|
+
const prefix = connectionId
|
|
124
|
+
? `/api/scim/v2/connections/${encodeURIComponent(connectionId)}`
|
|
125
|
+
: '/api/scim/v2';
|
|
126
|
+
return {
|
|
127
|
+
serviceProviderConfig: () => this.request('GET', `${prefix}/ServiceProviderConfig`),
|
|
128
|
+
schemas: () => this.request('GET', `${prefix}/Schemas`),
|
|
129
|
+
listUsers: (filter) => this.request('GET', `${prefix}/Users${filter ? `?filter=${encodeURIComponent(filter)}` : ''}`),
|
|
130
|
+
getUser: (id) => this.request('GET', `${prefix}/Users/${encodeURIComponent(id)}`),
|
|
131
|
+
createUser: (user) => this.request('POST', `${prefix}/Users`, user),
|
|
132
|
+
replaceUser: (id, user) => this.request('PUT', `${prefix}/Users/${encodeURIComponent(id)}`, user),
|
|
133
|
+
patchUser: (id, patchPayload) => this.request('PATCH', `${prefix}/Users/${encodeURIComponent(id)}`, patchPayload),
|
|
134
|
+
deleteUser: (id) => this.request('DELETE', `${prefix}/Users/${encodeURIComponent(id)}`),
|
|
135
|
+
listGroups: (filter) => this.request('GET', `${prefix}/Groups${filter ? `?filter=${encodeURIComponent(filter)}` : ''}`),
|
|
136
|
+
getGroup: (id) => this.request('GET', `${prefix}/Groups/${encodeURIComponent(id)}`),
|
|
137
|
+
createGroup: (group) => this.request('POST', `${prefix}/Groups`, group),
|
|
138
|
+
replaceGroup: (id, group) => this.request('PUT', `${prefix}/Groups/${encodeURIComponent(id)}`, group),
|
|
139
|
+
deleteGroup: (id) => this.request('DELETE', `${prefix}/Groups/${encodeURIComponent(id)}`),
|
|
140
|
+
};
|
|
141
|
+
},
|
|
82
142
|
};
|
|
83
143
|
auditLogs = {
|
|
84
144
|
list: (query) => {
|
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