Edits history of script submission #15875 for ' Request an OIDC token (fly)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    type Fly = {
      token: string;
    };
    /**
     * Request an OIDC token
     * Request an Open ID Connect token for your machine. Customize the audience claim with the `aud` parameter. This returns a JWT token. Learn more about using OpenID Connect on Fly.io.
    
     */
    export async function main(
      auth: Fly,
      body: { aud?: string; aws_principal_tags?: false | true },
    ) {
      const url = new URL(`https://api.machines.dev/v1/tokens/oidc`);
    
      const response = await fetch(url, {
        method: "POST",
        headers: {
          "Content-Type": "application/json",
          Authorization: "Bearer " + auth.token,
        },
        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 235 days ago