Class Security

Handles Bearer token authentication for GitHub REST API requests.

const security = new Security('ghp_myPersonalAccessToken');

const headers = security.getHeaders();
// {
// Authorization: 'Bearer ghp_myPersonalAccessToken',
// Accept: 'application/vnd.github+json',
// 'Content-Type': 'application/json',
// 'X-GitHub-Api-Version': '2022-11-28',
// }

Constructors

  • Creates a new Security instance with a GitHub personal access token.

    Parameters

    • token: string

      A GitHub personal access token (e.g., ghp_...) or OAuth token

    • apiUrl: string = 'https://api.github.com'

      The base URL of the GitHub API. Defaults to 'https://api.github.com'. Must be a valid URL; throws if it cannot be parsed.

    Returns Security

    If apiUrl is not a valid URL

Methods

  • Returns the base URL of the GitHub API, without a trailing slash.

    Returns string

    The API base URL

  • Returns the value of the Authorization header for Bearer authentication.

    Returns string

    The Authorization header value in the format Bearer <token>

  • Returns the full set of HTTP headers required for authenticated GitHub API requests.

    Returns Record<string, string>

    An object containing Authorization, Accept, Content-Type, and X-GitHub-Api-Version headers

  • Returns headers for raw file content requests.

    Returns Record<string, string>

    Headers with Accept: application/vnd.github.raw+json