//native
export type DynSelect_app_id = string
// Dropdown of the org's applications so users pick an app instead of typing its opaque ID.
export async function app_id(auth: RT.Okta) {
const url = new URL(`${auth.org_url}/api/v1/apps`)
url.searchParams.append("limit", "200")
const response = await fetch(url, {
headers: {
Authorization: `SSWS ${auth.token}`,
Accept: "application/json",
},
})
if (!response.ok) {
throw new Error(`${response.status} ${await response.text()}`)
}
const apps = (await response.json()) as {
id: string
label: string
name: string
}[]
return apps.map((a) => ({
value: a.id,
label: a.label ? `${a.label} (${a.id})` : a.id,
}))
}
/**
* List Application Users
* List the users assigned to an application. Page with `limit` and the `after` cursor from the previous response's Link header.
*/
export async function main(
auth: RT.Okta,
app_id: DynSelect_app_id,
q: string | undefined,
limit: number | undefined,
after: string | undefined
) {
const url = new URL(`${auth.org_url}/api/v1/apps/${app_id}/users`)
if (q !== undefined && q !== "") url.searchParams.append("q", q)
if (limit !== undefined) url.searchParams.append("limit", String(limit))
if (after !== undefined && after !== "")
url.searchParams.append("after", after)
const response = await fetch(url, {
method: "GET",
headers: {
Authorization: `SSWS ${auth.token}`,
Accept: "application/json",
},
})
if (!response.ok) {
throw new Error(`${response.status} ${await response.text()}`)
}
return await response.json()
}
Submitted by hugo989 6 days ago