Edits history of script submission #1745 for ' Get public key for the authenticated user (github)'

  • nativets
    One script reply has been approved by the moderators
    Ap­pro­ved
    type Github = {
      token: string;
    };
    /**
     * Get public key for the authenticated user
     * Gets your public key, which you need to encrypt secrets. You need to encrypt a secret before you can create or update secrets.
    
    You must authenticate using an access token with the `codespace` or `codespace:secrets` scope to use this endpoint. User must have Codespaces access to use this endpoint.
    
    GitHub Apps must have read access to the `codespaces_user_secrets` user permission to use this endpoint.
     */
    export async function main(auth: Github) {
      const url = new URL(
        `https://api.github.com/user/codespaces/secrets/public-key`
      );
    
      const response = await fetch(url, {
        method: "GET",
        headers: {
          Authorization: "Bearer " + auth.token,
        },
        body: undefined,
      });
      if (!response.ok) {
        const text = await response.text();
        throw new Error(`${response.status} ${text}`);
      }
      return await response.json();
    }
    

    Submitted by hugo697 367 days ago

  • nativets
    type Github = {
      token: string;
    };
    /**
     * Get public key for the authenticated user
     * Gets your public key, which you need to encrypt secrets. You need to encrypt a secret before you can create or update secrets.
    
    You must authenticate using an access token with the `codespace` or `codespace:secrets` scope to use this endpoint. User must have Codespaces access to use this endpoint.
    
    GitHub Apps must have read access to the `codespaces_user_secrets` user permission to use this endpoint.
     */
    export async function main(auth: Github) {
      const url = new URL(
        `https://api.github.com/user/codespaces/secrets/public-key`
      );
    
      const response = await fetch(url, {
        method: "GET",
        headers: {
          Authorization: "Bearer " + auth.token,
        },
        body: undefined,
      });
      if (!response.ok) {
        const text = await response.text();
        throw new Error(`${response.status} ${text}`);
      }
      return await response.json();
    }
    

    Submitted by hugo697 927 days ago