{"size": 1409, "ext": "js", "max_stars_repo_path": "node_modules/@octokit/auth-app/dist-src/get-oauth-authentication.js", "max_stars_repo_name": "moreeyesplz/meeper", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "node_modules/@octokit/auth-app/dist-src/get-oauth-authentication.js", "max_issues_repo_name": "moreeyesplz/meeper", "max_issues_repo_issues_event_min_datetime": "2021-02-02T15:25:13.000Z", "max_issues_repo_issues_event_max_datetime": "2021-02-02T15:53:27.000Z", "max_forks_repo_path": "node_modules/@octokit/auth-app/dist-src/get-oauth-authentication.js", "max_forks_repo_name": "moreeyesplz/meeper", "max_forks_repo_forks_event_min_datetime": "2021-02-07T21:29:51.000Z", "max_forks_repo_forks_event_max_datetime": "2021-02-07T21:29:51.000Z"}
{"max_stars_count": null, "max_issues_count": 5, "max_forks_count": 1, "avg_line_length": 41.4411764706, "max_line_length": 112, "alphanum_fraction": 0.6309439319}
import { RequestError } from "@octokit/request-error";
export async function getOAuthAuthentication(state, options, customRequest) {
    const request = customRequest || state.request;
    // The "/login/oauth/access_token" is not part of the REST API hosted on api.github.com,
    // instead it’s using the github.com domain.
    const route = /^https:\/\/(api\.)?github\.com$/.test(state.request.endpoint.DEFAULTS.baseUrl)
        ? "POST https://github.com/login/oauth/access_token"
        : `POST ${state.request.endpoint.DEFAULTS.baseUrl.replace("/api/v3", "/login/oauth/access_token")}`;
    const parameters = {
        headers: {
            accept: `application/json`,
        },
        client_id: state.clientId,
        client_secret: state.clientSecret,
        code: options.code,
        state: options.state,
        redirect_uri: options.redirectUrl,
    };
    const response = await request(route, parameters);
    if (response.data.error !== undefined) {
        throw new RequestError(`${response.data.error_description} (${response.data.error})`, response.status, {
            headers: response.headers,
            request: request.endpoint(route, parameters),
        });
    }
    const { data: { access_token: token, scope }, } = response;
    return {
        type: "token",
        tokenType: "oauth",
        token,
        scopes: scope.split(/,\s*/).filter(Boolean),
    };
}
