"POST /user/repos" does not support clientId/clientSecret basic authentication

268 Views Asked by At

I'm trying to create a Github Repository via an NPM package Octokit. I've set up the necessary oAuth stuff, but keep getting the same error:

HttpError: [@octokit/auth-oauth-app] "POST /user/repos" does not support clientId/clientSecret basic authentication.

import { Injectable } from '@nestjs/common';
import { Octokit } from "@octokit/rest";
import { createOAuthAppAuth } from "@octokit/auth-oauth-app";

@Injectable()
export class AppService {
  private auth() {
    return createOAuthAppAuth({
      clientType: "oauth-app",
      clientId: "xxxxxxxxxxxxxxx",
      clientSecret: "xxxxxxxxxxxxxxxxxxxxxxx",
    });
  };

  public async create() {
    const octokit = new Octokit({
      authStrategy: createOAuthAppAuth,
      auth: this.auth()
    });

    return await octokit.rest.repos.createForAuthenticatedUser({
      name: `repoName/${new Date().toString()}`
    }).then(({ data }) => { message: data });
  }

}

2

There are 2 best solutions below

0
On

I just needed to add a Personal Access Token rather than going to oAuth way.

const octokit = new Octokit({
  auth: "mypersonalaccesstoken123",
});

1
On

I can't thank you enough for taking the time to come back and answer your own question! I was stuck in recursive README hell going through all of the octokit repos until I found your answer