0

List User Factors

by
Published 4 days ago

List the MFA factors enrolled for a user.

Script okta Verified

The script

Submitted by hugo989 Typescript (fetch-only)
Verified 5 days ago
1
//native
2

3
/**
4
 * List User Factors
5
 * List the MFA factors enrolled for a user (e.g. Okta Verify, SMS, email, WebAuthn).
6
 */
7
export async function main(auth: RT.Okta, user_id: string) {
8
  const url = new URL(
9
    `${auth.org_url}/api/v1/users/${encodeURIComponent(user_id)}/factors`
10
  )
11

12
  const response = await fetch(url, {
13
    method: "GET",
14
    headers: {
15
      Authorization: `SSWS ${auth.token}`,
16
      Accept: "application/json",
17
    },
18
  })
19

20
  if (!response.ok) {
21
    throw new Error(`${response.status} ${await response.text()}`)
22
  }
23

24
  return await response.json()
25
}
26