0

Update a authentication provider

by
Published Apr 8, 2025

Updates settings of an existing authentication provider.

Script telnyx Verified

The script

Submitted by hugo697 Bun
Verified 428 days ago
1
//native
2
type Telnyx = {
3
	apiKey: string
4
}
5
/**
6
 * Update a authentication provider
7
 * Updates settings of an existing authentication provider.
8
 */
9
export async function main(
10
	auth: Telnyx,
11
	id: string,
12
	body: {
13
		name?: string
14
		short_name?: string
15
		active?: false | true
16
		settings?: {
17
			idp_entity_id: string
18
			idp_sso_target_url: string
19
			idp_cert_fingerprint: string
20
			idp_cert_fingerprint_algorithm?: 'sha1' | 'sha256' | 'sha384' | 'sha512'
21
		}
22
		settings_url?: string
23
	}
24
) {
25
	const url = new URL(`https://api.telnyx.com/v2/authentication_providers/${id}`)
26

27
	const response = await fetch(url, {
28
		method: 'PATCH',
29
		headers: {
30
			'Content-Type': 'application/json',
31
			Authorization: 'Bearer ' + auth.apiKey
32
		},
33
		body: JSON.stringify(body)
34
	})
35
	if (!response.ok) {
36
		const text = await response.text()
37
		throw new Error(`${response.status} ${text}`)
38
	}
39
	return await response.json()
40
}
41