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

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

问题描述

我决定将 omniauth-github gem 与 github_api gem 结合使用.但是,我不是 100% 确定如何使用我从 github 收到的授权来使用 github_api gem.我知道Github.new basic_auth: 'user:password'Github.new oauth_token 'token' 但我不确定如何获取该令牌作为响应.任何帮助,将不胜感激!谢谢红宝石爱好者.

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.

推荐答案

如果您在 authentications/sessions/callbacks 控制器操作的开头添加以下代码行:

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 返回的散列的内容,并查看 token 在散列中的位置.

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

碰巧的是,您可以通过 token = env["omniauth.auth"].credentials.token 获得它.

As it happens, you can get it with token = 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 gem的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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