@ionite/adapters 0.0.0-stage → 0.1.0-beta.20261118.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/LICENSE +18 -0
- package/package.json +40 -4
- package/src/api.ts +333 -0
- package/src/contract/ciam.ts +65 -0
- package/src/contract/iam.ts +36 -0
- package/src/contract/index.ts +11 -0
- package/src/contract/operations.ts +206 -0
- package/src/contract/otel.ts +21 -0
- package/src/contract/scim.ts +51 -0
- package/src/contract/sso.ts +323 -0
- package/src/contract/workload.ts +144 -0
- package/src/credentials.ts +114 -0
- package/src/define.ts +235 -0
- package/src/index.ts +27 -0
- package/src/onboard-page.ts +135 -0
- package/src/serve.ts +290 -0
- package/src/stores.ts +79 -0
- package/src/testing.ts +95 -0
- package/README.md +0 -3
|
@@ -0,0 +1,206 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { registerCiamAppPayloadSchema, registerCiamAppResultSchema, updateCiamAppPayloadSchema } from './ciam';
|
|
3
|
+
import { consumeIamRegisterPayloadSchema, consumeIamRegisterResultSchema } from './iam';
|
|
4
|
+
import { registerOtelPayloadSchema, registerOtelResultSchema } from './otel';
|
|
5
|
+
import { registerScimTargetPayloadSchema, registerScimTargetResultSchema } from './scim';
|
|
6
|
+
import {
|
|
7
|
+
consumeSsoPrepareRequestSchema,
|
|
8
|
+
consumeSsoPrepareResultSchema,
|
|
9
|
+
consumeSsoRegisterRequestSchema,
|
|
10
|
+
consumeSsoRegisterResultSchema,
|
|
11
|
+
discoveredSSOAppSchema,
|
|
12
|
+
discoverOneRequestSchema,
|
|
13
|
+
registerSSOAppPayloadSchema,
|
|
14
|
+
registerSSOAppResultSchema,
|
|
15
|
+
retireDiscoveredRequestSchema,
|
|
16
|
+
retireDiscoveredResultSchema,
|
|
17
|
+
ssoDiscoveryResultSchema,
|
|
18
|
+
updateSSOAppPayloadSchema,
|
|
19
|
+
} from './sso';
|
|
20
|
+
import {
|
|
21
|
+
consumeWorkloadRegisterPayloadSchema,
|
|
22
|
+
federateWorkloadPayloadSchema,
|
|
23
|
+
federateWorkloadResultSchema,
|
|
24
|
+
registerOutgoingPayloadSchema,
|
|
25
|
+
registerOutgoingResultSchema,
|
|
26
|
+
registerWorkloadPayloadSchema,
|
|
27
|
+
registerWorkloadResultSchema,
|
|
28
|
+
} from './workload';
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Bumped on a change an older peer cannot read. ionite refuses an adapter whose manifest names a
|
|
32
|
+
* different version, so a mismatch fails at connect time with a clear message, not mid-registration.
|
|
33
|
+
*/
|
|
34
|
+
export const CONTRACT_VERSION = 1;
|
|
35
|
+
|
|
36
|
+
/** What a group of operations is filed under in the manifest and in an adapter definition. */
|
|
37
|
+
export type AdapterCapability =
|
|
38
|
+
| 'provides.sso'
|
|
39
|
+
| 'provides.ssoDiscovery'
|
|
40
|
+
| 'provides.workload'
|
|
41
|
+
| 'provides.federatedWorkload'
|
|
42
|
+
| 'provides.otel'
|
|
43
|
+
| 'provides.scim'
|
|
44
|
+
| 'provides.ciam'
|
|
45
|
+
| 'consumes.sso'
|
|
46
|
+
| 'consumes.iam'
|
|
47
|
+
| 'consumes.workload';
|
|
48
|
+
|
|
49
|
+
const ack = z.object({ ok: z.literal(true) });
|
|
50
|
+
const byDownstreamId = z.object({ downstreamId: z.string().min(1) });
|
|
51
|
+
const empty = z.object({});
|
|
52
|
+
|
|
53
|
+
function operation<I extends z.ZodTypeAny, O extends z.ZodTypeAny>(capability: AdapterCapability, input: I, output: O) {
|
|
54
|
+
return { capability, input, output };
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* Every call ionite makes to a connected adapter tenant: `POST /api/adapter/{tenant}/{operation}`.
|
|
59
|
+
* WRITER AND READER MUST AGREE, and this table is how: the adapter runtime routes and validates
|
|
60
|
+
* requests from it, and ionite parses responses with the same `output` schemas. Objects drop unknown
|
|
61
|
+
* keys, so nothing the contract does not name crosses in either direction.
|
|
62
|
+
*/
|
|
63
|
+
export const operations = {
|
|
64
|
+
'sso/register': operation('provides.sso', registerSSOAppPayloadSchema, registerSSOAppResultSchema),
|
|
65
|
+
'sso/update': operation('provides.sso', byDownstreamId.extend({ payload: updateSSOAppPayloadSchema }), ack),
|
|
66
|
+
'sso/deregister': operation('provides.sso', byDownstreamId, ack),
|
|
67
|
+
'sso/discover': operation('provides.ssoDiscovery', empty, ssoDiscoveryResultSchema),
|
|
68
|
+
'sso/discover-one': operation(
|
|
69
|
+
'provides.ssoDiscovery',
|
|
70
|
+
discoverOneRequestSchema,
|
|
71
|
+
// `null` is the only way to say "the vendor does not hold it"; a missing key is a malformed answer.
|
|
72
|
+
z.object({ app: discoveredSSOAppSchema.nullable() }),
|
|
73
|
+
),
|
|
74
|
+
'sso/retire-discovered': operation(
|
|
75
|
+
'provides.ssoDiscovery',
|
|
76
|
+
retireDiscoveredRequestSchema,
|
|
77
|
+
z.object({ result: retireDiscoveredResultSchema }),
|
|
78
|
+
),
|
|
79
|
+
'workload/register': operation('provides.workload', registerWorkloadPayloadSchema, registerWorkloadResultSchema),
|
|
80
|
+
'workload/register-outgoing': operation(
|
|
81
|
+
'provides.workload',
|
|
82
|
+
registerOutgoingPayloadSchema,
|
|
83
|
+
registerOutgoingResultSchema,
|
|
84
|
+
),
|
|
85
|
+
'workload/deregister': operation('provides.workload', byDownstreamId, ack),
|
|
86
|
+
'workload/federate': operation(
|
|
87
|
+
'provides.federatedWorkload',
|
|
88
|
+
federateWorkloadPayloadSchema,
|
|
89
|
+
federateWorkloadResultSchema,
|
|
90
|
+
),
|
|
91
|
+
'workload/unfederate': operation('provides.federatedWorkload', byDownstreamId, ack),
|
|
92
|
+
'otel/register': operation('provides.otel', registerOtelPayloadSchema, registerOtelResultSchema),
|
|
93
|
+
'otel/deregister': operation('provides.otel', byDownstreamId, ack),
|
|
94
|
+
'scim/register': operation('provides.scim', registerScimTargetPayloadSchema, registerScimTargetResultSchema),
|
|
95
|
+
'scim/activate': operation('provides.scim', byDownstreamId, ack),
|
|
96
|
+
'scim/deregister': operation('provides.scim', byDownstreamId, ack),
|
|
97
|
+
'ciam/register': operation('provides.ciam', registerCiamAppPayloadSchema, registerCiamAppResultSchema),
|
|
98
|
+
'ciam/update': operation(
|
|
99
|
+
'provides.ciam',
|
|
100
|
+
z.object({ downstreamId: z.string().min(1), payload: updateCiamAppPayloadSchema }),
|
|
101
|
+
ack,
|
|
102
|
+
),
|
|
103
|
+
'ciam/deregister': operation('provides.ciam', byDownstreamId, ack),
|
|
104
|
+
'consumes/sso/prepare': operation('consumes.sso', consumeSsoPrepareRequestSchema, consumeSsoPrepareResultSchema),
|
|
105
|
+
'consumes/sso/register': operation('consumes.sso', consumeSsoRegisterRequestSchema, consumeSsoRegisterResultSchema),
|
|
106
|
+
'consumes/sso/deregister': operation('consumes.sso', empty, ack.extend({ removed: z.number().optional() })),
|
|
107
|
+
'consumes/iam/register': operation('consumes.iam', consumeIamRegisterPayloadSchema, consumeIamRegisterResultSchema),
|
|
108
|
+
'consumes/iam/deregister': operation('consumes.iam', byDownstreamId, ack),
|
|
109
|
+
'consumes/workload/register': operation('consumes.workload', consumeWorkloadRegisterPayloadSchema, ack),
|
|
110
|
+
'consumes/workload/deregister': operation('consumes.workload', empty, ack.extend({ removed: z.number().optional() })),
|
|
111
|
+
} as const;
|
|
112
|
+
|
|
113
|
+
export type OperationName = keyof typeof operations;
|
|
114
|
+
export type OperationInput<Op extends OperationName> = z.infer<(typeof operations)[Op]['input']>;
|
|
115
|
+
export type OperationOutput<Op extends OperationName> = z.infer<(typeof operations)[Op]['output']>;
|
|
116
|
+
|
|
117
|
+
export const operationNames = Object.keys(operations) as OperationName[];
|
|
118
|
+
|
|
119
|
+
export function isOperationName(value: string): value is OperationName {
|
|
120
|
+
return Object.hasOwn(operations, value);
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
/** Where each field failed, without the values: adapter bodies carry secrets and errors get logged. */
|
|
124
|
+
export function describeIssues(error: z.ZodError): string {
|
|
125
|
+
return error.issues
|
|
126
|
+
.slice(0, 5)
|
|
127
|
+
.map((issue) => (issue.path.length > 0 ? `'${issue.path.join('.')}' ${issue.message}` : issue.message))
|
|
128
|
+
.join('; ');
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
/*
|
|
132
|
+
* The calls that are not vendor operations. All live beside the operations:
|
|
133
|
+
* GET /api/adapter/manifest no tenant, no credentials: what this adapter serves
|
|
134
|
+
* POST /api/adapter/{tenant}/sign-in before a connection exists
|
|
135
|
+
* GET /api/adapter/{tenant}/connection whether one exists, and its public facts
|
|
136
|
+
*/
|
|
137
|
+
|
|
138
|
+
export const adapterManifestSchema = z.object({
|
|
139
|
+
contractVersion: z.number().int(),
|
|
140
|
+
/** The catalog slug of the product this adapter serves. */
|
|
141
|
+
product: z.string().min(1),
|
|
142
|
+
/** Catalog standard slugs: "sso", "workload", "otel", "iam" (SCIM provisioning), "ciam". */
|
|
143
|
+
provides: z.array(z.string()),
|
|
144
|
+
/** Standard slugs the vendor can take from another provider: "sso", "iam". */
|
|
145
|
+
consumes: z.array(z.string()),
|
|
146
|
+
operations: z.array(z.string()),
|
|
147
|
+
/**
|
|
148
|
+
* The adapter's workload provider is a federated target. Its connection's `wellKnownUrl` is the
|
|
149
|
+
* document of the IdP whose tokens it trusts; ionite mints the caller's client on that IdP's
|
|
150
|
+
* workload provider and calls `workload/federate`.
|
|
151
|
+
*/
|
|
152
|
+
federatedWorkload: z.boolean().optional(),
|
|
153
|
+
/** Present when the adapter provides CIAM. */
|
|
154
|
+
ciam: z.object({ defaultScope: z.string() }).optional(),
|
|
155
|
+
/** Present when the adapter provides SSO. */
|
|
156
|
+
sso: z
|
|
157
|
+
.object({
|
|
158
|
+
capabilities: z.array(z.enum(['oidc', 'saml'])).min(1),
|
|
159
|
+
defaultScope: z.string(),
|
|
160
|
+
})
|
|
161
|
+
.optional(),
|
|
162
|
+
});
|
|
163
|
+
export type AdapterManifest = z.infer<typeof adapterManifestSchema>;
|
|
164
|
+
|
|
165
|
+
export const signInRequestSchema = z.object({
|
|
166
|
+
email: z.string().refine((value) => value.includes('@'), 'is required'),
|
|
167
|
+
name: z.string().optional(),
|
|
168
|
+
/** A path on the adapter's own onboarding page; the link must not become an open redirect. */
|
|
169
|
+
redirect: z.string(),
|
|
170
|
+
});
|
|
171
|
+
export type SignInRequest = z.infer<typeof signInRequestSchema>;
|
|
172
|
+
|
|
173
|
+
export const signInResponseSchema = z.object({ url: z.string().min(1), expiresAt: z.string() });
|
|
174
|
+
export type SignInResponse = z.infer<typeof signInResponseSchema>;
|
|
175
|
+
|
|
176
|
+
/** Public facts about a completed connection. Never a credential. */
|
|
177
|
+
export const connectionFactsSchema = z.object({
|
|
178
|
+
/** The ids ionite sent on the tenant create, echoed so it can check the tenant is the one it made. */
|
|
179
|
+
ioniteId: z.string().optional(),
|
|
180
|
+
companyId: z.string().optional(),
|
|
181
|
+
/** The vendor instance, for display and as the app's URL. */
|
|
182
|
+
url: z.string().optional(),
|
|
183
|
+
/**
|
|
184
|
+
* The vendor's OIDC discovery document, for an adapter that provides SSO or Workload. ionite
|
|
185
|
+
* records it at connect time and checks every later registration result against it.
|
|
186
|
+
*/
|
|
187
|
+
wellKnownUrl: z.string().optional(),
|
|
188
|
+
/**
|
|
189
|
+
* The document of the server that issues workload tokens, when it is not `wellKnownUrl`'s (Okta
|
|
190
|
+
* mints client_credentials tokens on an authorization server, not on the org's SSO issuer). ionite
|
|
191
|
+
* checks workload results against it instead. Must be on `wellKnownUrl`'s origin.
|
|
192
|
+
*/
|
|
193
|
+
workloadWellKnownUrl: z.string().optional(),
|
|
194
|
+
/**
|
|
195
|
+
* Origins besides `url` where the vendor's SSO endpoints live, when the vendor hosts them elsewhere
|
|
196
|
+
* (Vercel's SAML ACS is on WorkOS). ionite records them at connect time and refuses a later
|
|
197
|
+
* redirect URI or ACS URL on any other origin.
|
|
198
|
+
*/
|
|
199
|
+
ssoOrigins: z.array(z.string()).max(5).optional(),
|
|
200
|
+
/**
|
|
201
|
+
* The cloud account the connection acts in, for a vendor whose resource names carry it (an AWS
|
|
202
|
+
* account id, from which ionite builds the OIDC provider ARN it hands AI-OPS).
|
|
203
|
+
*/
|
|
204
|
+
account: z.object({ id: z.string().max(64), region: z.string().max(64).optional() }).optional(),
|
|
205
|
+
});
|
|
206
|
+
export type ConnectionFacts = z.infer<typeof connectionFactsSchema>;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
|
|
3
|
+
export const otelProviderTypeSchema = z.enum(['datadog', 'grafana', 'splunk', 'elastic', 'otlp', 'google-cloud']);
|
|
4
|
+
export type OtelProviderType = z.infer<typeof otelProviderTypeSchema>;
|
|
5
|
+
|
|
6
|
+
/** The name the vendor files the minted credential under; ionite sends the app's display name. */
|
|
7
|
+
export const registerOtelPayloadSchema = z.object({ name: z.string().min(1) });
|
|
8
|
+
export type RegisterOtelPayload = z.infer<typeof registerOtelPayloadSchema>;
|
|
9
|
+
|
|
10
|
+
export const registerOtelResultSchema = z.object({
|
|
11
|
+
registered: z.literal(true),
|
|
12
|
+
keyId: z.string().min(1),
|
|
13
|
+
/** Empty for an endpoint that takes no credential (a plain OTLP collector). */
|
|
14
|
+
apiKey: z.string(),
|
|
15
|
+
/** Handed back on deregister, so the vendor code must be able to find the credential by it. */
|
|
16
|
+
downstreamId: z.string().min(1),
|
|
17
|
+
type: otelProviderTypeSchema,
|
|
18
|
+
/** Where the app exports to. May carry the credential (Grafana Cloud puts it in the userinfo). */
|
|
19
|
+
endpoint: z.string().min(1),
|
|
20
|
+
});
|
|
21
|
+
export type RegisterOtelResult = z.infer<typeof registerOtelResultSchema>;
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
|
|
3
|
+
const text = z.string().min(1);
|
|
4
|
+
|
|
5
|
+
/** A role the App lets the IAM tool assign. `value` is the App's catalog role id. */
|
|
6
|
+
export const scimAppRoleSchema = z.object({ value: text, displayName: text, description: z.string() });
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Registers the App at an IAM tool (Entra provisioning) so the tool pushes users and groups to the
|
|
10
|
+
* App's own SCIM API. Carries the App's SCIM credential: the tool calls the App with it.
|
|
11
|
+
*/
|
|
12
|
+
export const registerScimTargetPayloadSchema = z.object({
|
|
13
|
+
/** The App's SCIM API. The tool calls it from the vendor's cloud. */
|
|
14
|
+
scimBaseUrl: text,
|
|
15
|
+
/** The client the tool authenticates to the App with (client credentials). */
|
|
16
|
+
workload: z.object({ clientId: text, clientSecret: text, idpTokenUrl: text, scope: z.string().optional() }),
|
|
17
|
+
applicationId: z.string().optional(),
|
|
18
|
+
productId: z.string().optional(),
|
|
19
|
+
displayName: z.string().optional(),
|
|
20
|
+
companyId: z.string().optional(),
|
|
21
|
+
appRoles: z.array(scimAppRoleSchema).max(200).optional(),
|
|
22
|
+
/** Realm for the ECID the tool sends in the ion SCIM extension (`ecid:<realm>:<tool user id>`). */
|
|
23
|
+
ecidRealm: z.string().optional(),
|
|
24
|
+
});
|
|
25
|
+
export type RegisterScimTargetPayload = z.infer<typeof registerScimTargetPayloadSchema>;
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* The App's `iam.providers` entry for this tool. ionite checks `clientIds` is exactly the workload
|
|
29
|
+
* client it sent: a wider list would let other clients push identities into the App.
|
|
30
|
+
*/
|
|
31
|
+
export const scimProviderConfigSchema = z.object({
|
|
32
|
+
type: z.enum(['scim', 'entra', 'okta', 'sailpoint']),
|
|
33
|
+
clientIds: z.array(text).min(1).max(5),
|
|
34
|
+
branding: z.object({ displayName: text }).optional(),
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
export const registerScimTargetResultSchema = z.object({
|
|
38
|
+
registered: z.literal(true),
|
|
39
|
+
type: z.enum(['liam', 'sailpoint', 'okta', 'entra']),
|
|
40
|
+
/** Handle for activate and deregister. */
|
|
41
|
+
downstreamId: text,
|
|
42
|
+
applicationId: text,
|
|
43
|
+
/** Where the registration lives in the tool's console. */
|
|
44
|
+
toolBaseUrl: z.string().optional(),
|
|
45
|
+
providerKey: z
|
|
46
|
+
.string()
|
|
47
|
+
.regex(/^[A-Za-z0-9_.-]{1,100}$/)
|
|
48
|
+
.optional(),
|
|
49
|
+
providerConfig: scimProviderConfigSchema.optional(),
|
|
50
|
+
});
|
|
51
|
+
export type RegisterScimTargetResult = z.infer<typeof registerScimTargetResultSchema>;
|
|
@@ -0,0 +1,323 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
|
|
3
|
+
const text = z.string().min(1);
|
|
4
|
+
|
|
5
|
+
/** An absolute http(s) URL. Anything an adapter will fetch or hand to a vendor is held to this. */
|
|
6
|
+
export const httpUrlSchema = z.string().refine((value) => {
|
|
7
|
+
if (!URL.canParse(value)) return false;
|
|
8
|
+
const { protocol } = new URL(value);
|
|
9
|
+
return protocol === 'https:' || protocol === 'http:';
|
|
10
|
+
}, 'must be an http(s) URL');
|
|
11
|
+
|
|
12
|
+
export const ssoProtocolSchema = z.enum(['oidc', 'saml']);
|
|
13
|
+
export type SSOProtocol = z.infer<typeof ssoProtocolSchema>;
|
|
14
|
+
|
|
15
|
+
export const registerSSOAppPayloadSchema = z.object({
|
|
16
|
+
redirectUris: z.array(z.string()),
|
|
17
|
+
backchannelLogoutUri: z.string().optional(),
|
|
18
|
+
displayName: z.string().optional(),
|
|
19
|
+
defaultScope: z.string().optional(),
|
|
20
|
+
tenantId: z.string().optional(),
|
|
21
|
+
protocol: ssoProtocolSchema.optional(),
|
|
22
|
+
acsUrl: z.string().optional(),
|
|
23
|
+
spEntityId: z.string().optional(),
|
|
24
|
+
/**
|
|
25
|
+
* Realm for the `ecid` id_token claim (`ecid:<realm>:<IdP user id>`), from `ecidRealmForProvider`. Must
|
|
26
|
+
* match the value the IAM tool provisions over SCIM. Omitted: the IdP emits no `ecid` claim.
|
|
27
|
+
*/
|
|
28
|
+
ecidRealm: z.string().optional(),
|
|
29
|
+
});
|
|
30
|
+
export type RegisterSSOAppPayload = z.infer<typeof registerSSOAppPayloadSchema>;
|
|
31
|
+
|
|
32
|
+
export const oidcResultSchema = z.object({
|
|
33
|
+
protocol: z.literal('oidc'),
|
|
34
|
+
registered: z.literal(true),
|
|
35
|
+
clientId: text,
|
|
36
|
+
clientSecret: z.string().optional(),
|
|
37
|
+
appId: z.string().optional(),
|
|
38
|
+
downstreamId: z.string().optional(),
|
|
39
|
+
downstreamUrl: z.string().optional(),
|
|
40
|
+
authority: text,
|
|
41
|
+
tokenUrl: text,
|
|
42
|
+
authorizationUrl: text,
|
|
43
|
+
jwksUri: text,
|
|
44
|
+
userinfoUrl: z.string().optional(),
|
|
45
|
+
/**
|
|
46
|
+
* ISO-8601 timestamp at which the minted `clientSecret` expires, when the provider mints a
|
|
47
|
+
* finite-lifetime secret. Persisted to `standard_config.secretExpiresAt` so the integration can be
|
|
48
|
+
* proactively renewed. Omit for non-expiring secrets.
|
|
49
|
+
*/
|
|
50
|
+
secretExpiresAt: z.string().optional(),
|
|
51
|
+
});
|
|
52
|
+
export type OIDCResult = z.infer<typeof oidcResultSchema>;
|
|
53
|
+
|
|
54
|
+
export const samlResultSchema = z.object({
|
|
55
|
+
protocol: z.literal('saml'),
|
|
56
|
+
registered: z.literal(true),
|
|
57
|
+
appId: z.string().optional(),
|
|
58
|
+
downstreamId: z.string().optional(),
|
|
59
|
+
downstreamUrl: z.string().optional(),
|
|
60
|
+
entityId: text,
|
|
61
|
+
ssoUrl: text,
|
|
62
|
+
metadataUrl: z.string().optional(),
|
|
63
|
+
metadataXml: z.string().optional(),
|
|
64
|
+
signingCertPem: text,
|
|
65
|
+
nameIdFormat: z.string().optional(),
|
|
66
|
+
/**
|
|
67
|
+
* ISO-8601 timestamp at which `signingCertPem` expires, when the provider mints a finite-lifetime
|
|
68
|
+
* signing certificate. Persisted to `standard_config.secretExpiresAt`. Omit when unknown.
|
|
69
|
+
*/
|
|
70
|
+
secretExpiresAt: z.string().optional(),
|
|
71
|
+
});
|
|
72
|
+
export type SAMLResult = z.infer<typeof samlResultSchema>;
|
|
73
|
+
|
|
74
|
+
export const registerSSOAppResultSchema = z.discriminatedUnion('protocol', [oidcResultSchema, samlResultSchema]);
|
|
75
|
+
export type RegisterSSOAppResult = z.infer<typeof registerSSOAppResultSchema>;
|
|
76
|
+
|
|
77
|
+
export const updateSSOAppPayloadSchema = z.object({
|
|
78
|
+
redirectUris: z.array(z.string()).optional(),
|
|
79
|
+
displayName: z.string().optional(),
|
|
80
|
+
backchannelLogoutUri: z.string().optional(),
|
|
81
|
+
cookiesSecure: z.boolean().optional(),
|
|
82
|
+
cookiesSameSite: z.string().optional(),
|
|
83
|
+
});
|
|
84
|
+
export type UpdateSSOAppPayload = z.infer<typeof updateSSOAppPayloadSchema>;
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* How a DISCOVERED app signs in. Wider than `SSOProtocol` on purpose, and deliberately a separate
|
|
88
|
+
* type: `SSOProtocol` is what ionite can REGISTER, so widening it would oblige every provides
|
|
89
|
+
* adapter to handle modes it cannot create. Discovery only has to describe what it found.
|
|
90
|
+
*
|
|
91
|
+
* A real Okta org is mostly `password` — SWA, bookmark and plugin apps where Okta replays a stored
|
|
92
|
+
* credential instead of federating. Calling those "saml" would be the single most misleading thing an
|
|
93
|
+
* M&A inventory could say, because a password-replay app means shared secrets, not federation.
|
|
94
|
+
*/
|
|
95
|
+
export const discoveredSSOProtocolSchema = z.enum(['oidc', 'saml', 'ws-fed', 'password', 'other']);
|
|
96
|
+
export type DiscoveredSSOProtocol = z.infer<typeof discoveredSSOProtocolSchema>;
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* Security-relevant configuration flattened out of the provider payload by the ADAPTER, for the same
|
|
100
|
+
* reason `extraUris` is: ionite's hygiene rules read this and never `raw`, so they never learn one
|
|
101
|
+
* provider's shape.
|
|
102
|
+
*
|
|
103
|
+
* Every field is TRI-STATE. `undefined` means THIS PROVIDER CANNOT SAY — Okta has no per-app token
|
|
104
|
+
* lifespan, a SAML app has no OAuth bag at all — which is not the claim `false` makes. No rule may
|
|
105
|
+
* fire on `undefined`, and `undefined` is never a clean bill of health.
|
|
106
|
+
*/
|
|
107
|
+
export const discoveredSSOPostureSchema = z.object({
|
|
108
|
+
implicitFlow: z.boolean().optional(),
|
|
109
|
+
/** Resource-owner password credentials grant — Keycloak calls it "direct access grants". */
|
|
110
|
+
resourceOwnerPassword: z.boolean().optional(),
|
|
111
|
+
/** PKCE is REQUIRED. `false` = an OIDC client that does not require it; `undefined` = not OIDC. */
|
|
112
|
+
pkceEnforced: z.boolean().optional(),
|
|
113
|
+
/**
|
|
114
|
+
* A registered callback that matches more than one concrete URL. Decided on the provider's RAW
|
|
115
|
+
* strings, because ionite's `normalizeRedirectUri` drops a bare "*" and a relative "/*" with no
|
|
116
|
+
* rootUrl to resolve against, and its `isWildcard` only catches a "/*" path suffix.
|
|
117
|
+
*/
|
|
118
|
+
wildcardRedirect: z.boolean().optional(),
|
|
119
|
+
/**
|
|
120
|
+
* A CORS origin of "*". Keycloak-only, and only knowable in the adapter: `extraUris` omits the "*"
|
|
121
|
+
* sentinel, so downstream a wide-open client is indistinguishable from one with no origins.
|
|
122
|
+
*/
|
|
123
|
+
wildcardOrigin: z.boolean().optional(),
|
|
124
|
+
/** Keycloak-only: the client inherits every role in the realm. */
|
|
125
|
+
fullScopeAllowed: z.boolean().optional(),
|
|
126
|
+
/** Keycloak-only: per-client access token lifetime. Okta's lives on the authorization server. */
|
|
127
|
+
accessTokenLifespanSeconds: z.number().optional(),
|
|
128
|
+
});
|
|
129
|
+
export type DiscoveredSSOPosture = z.infer<typeof discoveredSSOPostureSchema>;
|
|
130
|
+
|
|
131
|
+
/**
|
|
132
|
+
* One application read back off a provider during an M&A discovery scan. Read-only: this describes
|
|
133
|
+
* something that ALREADY exists downstream, so it carries the provider's own identifiers rather than
|
|
134
|
+
* anything ionite minted. Distinct from RegisterSSOAppResult, which describes an app ionite created.
|
|
135
|
+
*/
|
|
136
|
+
export const discoveredSSOAppSchema = z.object({
|
|
137
|
+
/** Provider-side stable id. Keycloak: the client's UUID, NOT its clientId. */
|
|
138
|
+
externalId: z.string(),
|
|
139
|
+
/** Sub-scope within the provider that owns this app (Keycloak realm). "" when the provider has none. */
|
|
140
|
+
namespace: z.string(),
|
|
141
|
+
clientId: z.string(),
|
|
142
|
+
name: z.string().optional(),
|
|
143
|
+
description: z.string().optional(),
|
|
144
|
+
protocol: discoveredSSOProtocolSchema,
|
|
145
|
+
/**
|
|
146
|
+
* The provider's OWN word for the sign-on mode, verbatim, when it is richer than `protocol` —
|
|
147
|
+
* Okta's `SECURE_PASSWORD_STORE`, Keycloak's `openid-connect`. Kept so the inventory can show what
|
|
148
|
+
* an admin would see in their own console rather than ionite's coarser classification.
|
|
149
|
+
*/
|
|
150
|
+
protocolLabel: z.string().optional(),
|
|
151
|
+
enabled: z.boolean(),
|
|
152
|
+
publicClient: z.boolean().optional(),
|
|
153
|
+
serviceAccountEnabled: z.boolean().optional(),
|
|
154
|
+
/**
|
|
155
|
+
* Provider-managed plumbing rather than a real application (Keycloak ships six such clients in
|
|
156
|
+
* every realm). Flagged, never dropped: the scan is an inventory, so the operator decides what
|
|
157
|
+
* counts — but a UI that shows them by default is mostly noise.
|
|
158
|
+
*/
|
|
159
|
+
builtIn: z.boolean(),
|
|
160
|
+
redirectUris: z.array(z.string()).optional(),
|
|
161
|
+
/**
|
|
162
|
+
* Every OTHER URL the provider associates with this app — CORS origins, an admin/back-channel URL,
|
|
163
|
+
* post-logout returns, a SAML ACS endpoint. Separate from `redirectUris` because these are not
|
|
164
|
+
* login callbacks and must not be scored as one, but they are strong evidence of WHERE the app
|
|
165
|
+
* lives. Adapters flatten them here so matching never has to reach into `raw` and learn one
|
|
166
|
+
* provider's payload shape.
|
|
167
|
+
*/
|
|
168
|
+
extraUris: z.array(z.string()).optional(),
|
|
169
|
+
rootUrl: z.string().optional(),
|
|
170
|
+
baseUrl: z.string().optional(),
|
|
171
|
+
adminConsoleUrl: z.string().optional(),
|
|
172
|
+
/**
|
|
173
|
+
* Normalized security posture. Absent when the provider reports none of it — a SAML or bookmark
|
|
174
|
+
* app has no OAuth settings to describe.
|
|
175
|
+
*/
|
|
176
|
+
posture: discoveredSSOPostureSchema.optional(),
|
|
177
|
+
/**
|
|
178
|
+
* Full provider payload, retained so later phases can mine fields without a re-scan. Adapters MUST
|
|
179
|
+
* strip credential material before returning it: ionite syncs this column to the browser.
|
|
180
|
+
*/
|
|
181
|
+
raw: z.record(z.string(), z.unknown()),
|
|
182
|
+
});
|
|
183
|
+
export type DiscoveredSSOApp = z.infer<typeof discoveredSSOAppSchema>;
|
|
184
|
+
|
|
185
|
+
/** One namespace's slice of a scan. `error` set (and `apps` empty) when that namespace was unreadable. */
|
|
186
|
+
export const discoveredNamespaceSchema = z.object({
|
|
187
|
+
namespace: z.string(),
|
|
188
|
+
apps: z.array(discoveredSSOAppSchema),
|
|
189
|
+
error: z.string().optional(),
|
|
190
|
+
});
|
|
191
|
+
export type DiscoveredNamespace = z.infer<typeof discoveredNamespaceSchema>;
|
|
192
|
+
|
|
193
|
+
export const ssoDiscoveryResultSchema = z.object({ namespaces: z.array(discoveredNamespaceSchema) });
|
|
194
|
+
export type SSODiscoveryResult = z.infer<typeof ssoDiscoveryResultSchema>;
|
|
195
|
+
|
|
196
|
+
export const discoverOneRequestSchema = z.object({
|
|
197
|
+
externalId: text,
|
|
198
|
+
/** Namespace to look in. Omitted: the namespace of the connection. */
|
|
199
|
+
namespace: z.string().optional(),
|
|
200
|
+
});
|
|
201
|
+
export type DiscoverOneRequest = z.infer<typeof discoverOneRequestSchema>;
|
|
202
|
+
|
|
203
|
+
/**
|
|
204
|
+
* `namespace` is part of the target because one connection may enumerate several namespaces, while
|
|
205
|
+
* `sso/deregister` addresses only the connection's own. Empty is valid, as it is in a discovery
|
|
206
|
+
* result: a vendor with one flat space of apps (Okta) reports every app under `""`.
|
|
207
|
+
*/
|
|
208
|
+
export const retireDiscoveredRequestSchema = z.object({
|
|
209
|
+
externalId: text,
|
|
210
|
+
namespace: z.string(),
|
|
211
|
+
action: z.enum(['disable', 'enable']),
|
|
212
|
+
});
|
|
213
|
+
export type RetireDiscoveredRequest = z.infer<typeof retireDiscoveredRequestSchema>;
|
|
214
|
+
|
|
215
|
+
export const retireDiscoveredResultSchema = z.enum(['applied', 'already_absent']);
|
|
216
|
+
export type RetireDiscoveredResult = z.infer<typeof retireDiscoveredResultSchema>;
|
|
217
|
+
|
|
218
|
+
/*
|
|
219
|
+
* Consumes side: the adapter's vendor takes SSO from another IdP. ionite sends only what the vendor
|
|
220
|
+
* needs to broker, never the other vendor's admin credentials or any vault contents.
|
|
221
|
+
*/
|
|
222
|
+
|
|
223
|
+
/**
|
|
224
|
+
* The name the vendor files the upstream IdP under. ionite derives ONE value per upstream and sends
|
|
225
|
+
* it to both `consumes/sso/prepare` and `consumes/sso/register`: the redirect URI the upstream
|
|
226
|
+
* registers and the identity provider the vendor creates must agree on it.
|
|
227
|
+
*/
|
|
228
|
+
const aliasSchema = z.string().min(1).max(100);
|
|
229
|
+
|
|
230
|
+
export const consumeSsoPrepareRequestSchema = z.object({
|
|
231
|
+
alias: aliasSchema,
|
|
232
|
+
/**
|
|
233
|
+
* The upstream IdP's OIDC discovery document, when ionite has one recorded. Public. For a vendor
|
|
234
|
+
* whose callback depends on which IdP it is (ERPNext uses its own Office 365 login for Microsoft).
|
|
235
|
+
*/
|
|
236
|
+
upstreamWellKnownUrl: httpUrlSchema.optional(),
|
|
237
|
+
});
|
|
238
|
+
export type ConsumeSsoPrepareRequest = z.infer<typeof consumeSsoPrepareRequestSchema>;
|
|
239
|
+
|
|
240
|
+
/** What the upstream IdP must be asked to register for this vendor. ionite merges it into the register call. */
|
|
241
|
+
export const consumeSsoPrepareResultSchema = z.object({
|
|
242
|
+
/** Omitted: ionite's default, "oidc". "saml" for a vendor whose admin API only ingests SAML metadata. */
|
|
243
|
+
protocol: ssoProtocolSchema.optional(),
|
|
244
|
+
redirectUris: z.array(httpUrlSchema).optional(),
|
|
245
|
+
backchannelLogoutUri: httpUrlSchema.optional(),
|
|
246
|
+
acsUrl: httpUrlSchema.optional(),
|
|
247
|
+
spEntityId: z.string().optional(),
|
|
248
|
+
});
|
|
249
|
+
export type ConsumeSsoPrepareResult = z.infer<typeof consumeSsoPrepareResultSchema>;
|
|
250
|
+
|
|
251
|
+
/** The upstream IdP's registration result for the vendor's client there. It is what the vendor brokers to. */
|
|
252
|
+
export const brokerUpstreamSchema = z.object({
|
|
253
|
+
clientId: text,
|
|
254
|
+
clientSecret: z.string().optional(),
|
|
255
|
+
authority: httpUrlSchema,
|
|
256
|
+
tokenUrl: httpUrlSchema,
|
|
257
|
+
authorizationUrl: httpUrlSchema,
|
|
258
|
+
jwksUri: httpUrlSchema,
|
|
259
|
+
userinfoUrl: httpUrlSchema.optional(),
|
|
260
|
+
});
|
|
261
|
+
export type BrokerUpstream = z.infer<typeof brokerUpstreamSchema>;
|
|
262
|
+
|
|
263
|
+
/** A SAML upstream: what a vendor that ingests IdP metadata (Supabase, Vercel) is configured with. */
|
|
264
|
+
export const samlUpstreamSchema = z.object({
|
|
265
|
+
entityId: text,
|
|
266
|
+
ssoUrl: httpUrlSchema,
|
|
267
|
+
metadataUrl: httpUrlSchema.optional(),
|
|
268
|
+
metadataXml: z.string().optional(),
|
|
269
|
+
signingCertPem: text,
|
|
270
|
+
nameIdFormat: z.string().optional(),
|
|
271
|
+
});
|
|
272
|
+
export type SamlUpstream = z.infer<typeof samlUpstreamSchema>;
|
|
273
|
+
|
|
274
|
+
const consumeSsoRegisterBase = {
|
|
275
|
+
alias: aliasSchema,
|
|
276
|
+
displayName: z.string().optional(),
|
|
277
|
+
defaultScope: z.string().optional(),
|
|
278
|
+
};
|
|
279
|
+
export const consumeSsoRegisterPayloadSchema = z.object({ ...consumeSsoRegisterBase, upstream: brokerUpstreamSchema });
|
|
280
|
+
export type ConsumeSsoRegisterPayload = z.infer<typeof consumeSsoRegisterPayloadSchema>;
|
|
281
|
+
|
|
282
|
+
/** Sent instead of `upstream` when `prepare` asked for SAML. */
|
|
283
|
+
export const consumeSsoRegisterSamlPayloadSchema = z.object({
|
|
284
|
+
...consumeSsoRegisterBase,
|
|
285
|
+
samlUpstream: samlUpstreamSchema,
|
|
286
|
+
});
|
|
287
|
+
export type ConsumeSsoRegisterSamlPayload = z.infer<typeof consumeSsoRegisterSamlPayloadSchema>;
|
|
288
|
+
|
|
289
|
+
/**
|
|
290
|
+
* The wire form of `consumes/sso/register`: one of the two upstreams. Each branch requires its own, and
|
|
291
|
+
* unknown keys are dropped as everywhere else, so a body carrying both is read as OIDC.
|
|
292
|
+
*/
|
|
293
|
+
export const consumeSsoRegisterRequestSchema = z.union([
|
|
294
|
+
consumeSsoRegisterPayloadSchema,
|
|
295
|
+
consumeSsoRegisterSamlPayloadSchema,
|
|
296
|
+
]);
|
|
297
|
+
export type ConsumeSsoRegisterRequest = z.infer<typeof consumeSsoRegisterRequestSchema>;
|
|
298
|
+
|
|
299
|
+
/**
|
|
300
|
+
* Steps a person must finish in the vendor's console, for a vendor whose admin API cannot take the
|
|
301
|
+
* upstream (Vercel's SAML settings are UI-only). ionite files them as a task for whoever connected
|
|
302
|
+
* the standard. Every value is public IdP metadata, never a secret.
|
|
303
|
+
*/
|
|
304
|
+
export const manualSetupSchema = z.object({
|
|
305
|
+
targetUrl: httpUrlSchema,
|
|
306
|
+
message: z.string().max(2000).optional(),
|
|
307
|
+
fields: z
|
|
308
|
+
.array(
|
|
309
|
+
z.object({
|
|
310
|
+
label: z.string().min(1).max(200),
|
|
311
|
+
value: z.string().max(20_000),
|
|
312
|
+
hint: z.string().max(500).optional(),
|
|
313
|
+
}),
|
|
314
|
+
)
|
|
315
|
+
.max(20),
|
|
316
|
+
});
|
|
317
|
+
export type ManualSetup = z.infer<typeof manualSetupSchema>;
|
|
318
|
+
|
|
319
|
+
export const consumeSsoRegisterResultSchema = z.object({
|
|
320
|
+
ok: z.literal(true),
|
|
321
|
+
manualSetup: manualSetupSchema.optional(),
|
|
322
|
+
});
|
|
323
|
+
export type ConsumeSsoRegisterResult = z.infer<typeof consumeSsoRegisterResultSchema>;
|