Understanding how to use omniauth-github gem in conjunction with the Github API

匆匆过客 提交于 2020-01-05 08:56:05

问题


I've decided to use the omniauth-github gem in conjunction with the github_api gem. However, I'm not 100% sure how to use the authorization I've received back from github to use the github_api gem. I know Github.new basic_auth: 'user:password' and Github.new oauth_token 'token' but I'm not exactly sure how to get that token as a response. Any help would be appreciated! Thank you fellow rubyists.


回答1:


If you add the following line of code at the beginning of your authentications/sessions/callbacks controller action:

render :text => "<pre>" + env["omniauth.auth"].to_yaml and return

You'll be able to inspect the contents of the hash returned by GitHub and see where the token is located inside the hash.

As it happens, you can get it with token = env["omniauth.auth"].credentials.token.

You can now create a new github_api client instance with the token:

Github.new(oauth_token: token)


来源:https://stackoverflow.com/questions/22121989/understanding-how-to-use-omniauth-github-gem-in-conjunction-with-the-github-api

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!