Edits history of script submission #11972 for ' Create an OAuth application (clerk)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    type Clerk = {
      apiKey: string;
    };
    /**
     * Create an OAuth application
     * 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...
     */
    export async function main(
      auth: Clerk,
      body: {
        name: string;
        callback_url: string;
        scopes?: string;
        public?: false | true;
      },
    ) {
      const url = new URL(`https://api.clerk.com/v1/oauth_applications`);
    
      const response = await fetch(url, {
        method: "POST",
        headers: {
          "Content-Type": "application/json",
          Authorization: "Bearer " + auth.apiKey,
        },
        body: JSON.stringify(body),
      });
      if (!response.ok) {
        const text = await response.text();
        throw new Error(`${response.status} ${text}`);
      }
      return await response.json();
    }
    

    Submitted by hugo697 428 days ago