Pregunta

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.

¿Fue útil?

Solución

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)
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top