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)
CodePudding user response:
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"})