0

Create an OAuth application

by
Published Apr 8, 2025

Creates a new OAuth application with the given name and callback URL for an instance. The callback URL must be a valid url. All URL schemes are allowed such as `http://`, `https://`, `myapp://`, etc...

Script clerk Verified

The script

Submitted by hugo697 Bun
Verified 428 days ago
1
//native
2
type Clerk = {
3
  apiKey: string;
4
};
5
/**
6
 * Create an OAuth application
7
 * Creates a new OAuth application with the given name and callback URL for an instance.
8
The callback URL must be a valid url.
9
All URL schemes are allowed such as `http://`, `https://`, `myapp://`, etc...
10
 */
11
export async function main(
12
  auth: Clerk,
13
  body: {
14
    name: string;
15
    callback_url: string;
16
    scopes?: string;
17
    public?: false | true;
18
  },
19
) {
20
  const url = new URL(`https://api.clerk.com/v1/oauth_applications`);
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