Edits history of script submission #17387 for ' Revoke token (v1) (miro)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    type Miro = {
      token: string;
    };
    /**
     * Revoke token (v1)
     * Please use the new revoke endpoint /v2/oauth/revoke. This endpoint is considered vulnerable and deprecated due to access token passed publicly in the URL. Revoke the current access token. Revoking an access token means that the access token will no longer work. When an access token is revoked, the refresh token is also revoked and no longer valid. This does not uninstall the application for the user.
     */
    export async function main(auth: Miro, access_token: string | undefined) {
      const url = new URL(`https://api.miro.com//v1/oauth/revoke`);
      for (const [k, v] of [["access_token", access_token]]) {
        if (v !== undefined && v !== "" && k !== undefined) {
          url.searchParams.append(k, v);
        }
      }
      const response = await fetch(url, {
        method: "POST",
        headers: {
          Authorization: "Bearer " + auth.token,
        },
        body: undefined,
      });
      if (!response.ok) {
        const text = await response.text();
        throw new Error(`${response.status} ${text}`);
      }
      return await response.text();
    }
    

    Submitted by hugo697 235 days ago