1

I want my GitHub app to perform actions on behalf of a user, like creating an issue.

I am authenticating my user this way:

const { createOAuthAppAuth } = require('@octokit/auth-oauth-app');

const auth = createOAuthAppAuth({
  clientType: 'oauth-app',
  clientId: clientGithubID,
  clientSecret: clientSecretGithub,
});

const userAuthenticationFromWebFlow = await auth({
  type: 'oauth-user',
  code,
  state: userId,
});

// console.log(useAuthenticationFromWebFlow)
// {
//   "type": "token",
//   "tokenType": "oauth",
//   "clientType": "oauth-app",
//   "clientId": "Iv1.CLIENTID",
//   "clientSecret": "CLIENTSECRET",
//   "token": "ghu_bunchofchars",
//   "scopes": []
// }

It seems that the token that I get is good.

Now the problem is when I try to create an Octokit later in my code this doesn't work

octokit = new Octokit({
  authStrategy: userAuthenticationFromWebFlow,
});
await octokit.issues.createComment({...props})

What is the proper way to create an Octokit instance ?

Thank you !

Sydney C.
  • 950
  • 10
  • 21

1 Answers1

2

So I just found the answer,

may be that can help someone.

const { createOAuthAppAuth } = require('@octokit/auth-oauth-app');

    octokit = new Octokit({
      authStrategy: createOAuthAppAuth,
      auth: userAuthenticationFromWebFlow.token,
    });

And it works !

Sydney C.
  • 950
  • 10
  • 21
  • Hi Sydney, can I know how you got the authentication code which is the 1st step? I am trying to use OAuth without a node server. I can't get the code with the right scope – Annapoorna C K Jul 20 '23 at 20:18