0

Creates an authentication provider

by
Published Apr 8, 2025

Creates an 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
 * Creates an authentication provider
7
 * Creates an authentication provider.
8
 */
9
export async function main(
10
	auth: Telnyx,
11
	body: {
12
		name: string
13
		short_name: string
14
		active?: false | true
15
		settings: {
16
			idp_entity_id: string
17
			idp_sso_target_url: string
18
			idp_cert_fingerprint: string
19
			idp_cert_fingerprint_algorithm?: 'sha1' | 'sha256' | 'sha384' | 'sha512'
20
		}
21
		settings_url?: string
22
	}
23
) {
24
	const url = new URL(`https://api.telnyx.com/v2/authentication_providers`)
25

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