Kemal Mutlu
Kemal Mutlu

Reputation: 49

Cannot connect to Github account using octokit

I fail to connect to GitHub and get my account credential using the "octokit" gem.

client = Octokit::Client.new(
    client_id: ENV['GITHUB_CLIENT_ID'],
    client_secret: ENV['GITHUB_CLIENT_SECRET'],
 )

Gem File:

ruby '2.7.2'
gem 'rails', '~> 6.1.4', '>= 6.1.4.3'
gem "octokit", "~> 4.0"

Error message: Octokit::Unauthorized (GET https://api.github.com/user: 401 - Requires authentication // See: https://docs.github.com/rest/reference/users#get-the-authenticated-user)

Upvotes: 3

Views: 714

Answers (1)

codescaptain
codescaptain

Reputation: 98

I had the same problem. I solved problem just like this:

client.user(ENV['GITHUB_LOGIN'], :headers => { "X-GitHub-OTP" => "2fa-token"})

If you don't have an ENV['GITHUB_LOGIN'], just type Github username

client.user('codescaptain', :headers => { "X-GitHub-OTP" => "2fa-token"})

Upvotes: 2

Related Questions