了解如何结合GitHub的API使用omniauth,github上的宝石 [英] Understanding how to use omniauth-github gem in conjunction with the Github API

查看:200
本文介绍了了解如何结合GitHub的API使用omniauth,github上的宝石的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经决定使用omniauth,github上的宝石会同github_api宝石。不过,我不是100%确定如何使用我已经收到回授权从GitHub使用github_api宝石。我知道
Github.new basic_auth:'用户名:密码 Github.new组oauth_token'令牌',但我不完全知道如何让该令牌作为响应。任何帮助将是AP preciated!谢谢老乡Ruby专家。

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.

推荐答案

如果您在您的认证/会话/回调控制器动作的开头添加code的以下行:

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

您就可以通过检查返回GitHub的散列的内容,看看那里的标记位于哈希里。

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

碰巧的是,你可以用标记= ENV [omniauth.auth]得到它。credentials.token

您现在可以令牌创建一个新的github_api客户端实例:

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

Github.new(oauth_token: token)

这篇关于了解如何结合GitHub的API使用omniauth,github上的宝石的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆