0

Adds a JWKS URL to a project

by
Published Apr 8, 2025

Add a new JWKS URL to a project, such that it can be used for verifying JWTs used as the authentication mechanism for the specified project.

Script neondb Verified

The script

Submitted by hugo697 Bun
Verified 428 days ago
1
//native
2
type Neondb = {
3
	apiKey: string
4
}
5
/**
6
 * Adds a JWKS URL to a project
7
 * Add a new JWKS URL to a project, such that it can be used for verifying JWTs used as the authentication mechanism for the specified project.
8
 */
9
export async function main(
10
	auth: Neondb,
11
	project_id: string,
12
	body: {
13
		jwks_url: string
14
		provider_name: string
15
		branch_id?: string
16
		jwt_audience?: string
17
		role_names?: string[]
18
	}
19
) {
20
	const url = new URL(`https://console.neon.tech/api/v2/projects/${project_id}/jwks`)
21

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