Using Omniauth, how can I see the repositories of a user who logs in with Github?

Pierre

I've setup Omniauth on my Rails 4 application to allow a user to sign in using Github.

This part works fine.

Now, I would like to list the repositories of that user (I request the scope repo when asking the user to authorise my app.

I've done a lot of Googling, but I don't understand how to do that.

Can anyone please tell me how I can use the existing authentication to list the repositories of my user?

Ashitaka

Well, OmniAuth is just a flexible authentication library. Its only purpose is to authenticate users. Any custom behaviour you desire has to be implemented either by you or by another gem.

You can achieve what you want by simply using GitHub's well documented API:

# callbacks_controller.rb
require "open-uri"
require "json"

omniauth = env['omniauth.auth']
repositories_json = open(omniauth.extra.raw_info.repos_url,
  "Accept" => "application/vnd.github.v3+json",
  "Authorization" => "token #{omniauth.credentials.token}"
).read
repositories = JSON.parse(repositories_json)

If this is all you need, then by all means, use it. If you have other requirements besides this, then maybe you should take a look at the github gem.

Also, you should only use the scope repo if you want to access your users' private repos. And requesting access to a user's private repos is a bit intrusive, so don't do it lightly.

If you really want to access a user's private repos, then you have to append ?type=all to the end of the repos_url. So you would have to do something like:

open("#{omniauth.extra.raw_info.repos_url}?type=all" ... )

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

GitHub - how can I create sub repositories?

From Dev

How can I see previous logs with systemd?

From Dev

How can I see who has access to a user's calendar in office 365?

From Dev

Mac OS X: How can I see who is using the files I'm trying to delete?

From Dev

How can I view user's personal data with omniauth?

From Dev

How to get number of user repositories using GitHub api?

From Dev

How to see github organisations repositories in Stackdriver

From Dev

Can you see who is watching a repo on GitHub?

From Dev

How can I see who reordered the teamcity build queue?

From Dev

How can I see who and when logged remotely to my computer?

From Dev

How can I list all the repositories of a Github Organization by URL?

From Dev

How can I see my debug logs on Unity Android?

From Dev

How can I see AWS Gateway logs for external calls?

From Dev

How can I see unavailable servers in Nginx logs?

From Dev

How can I see system logs while booting up ubuntu?

From Dev

How to get all repositories of a specific GitHub user

From Java

How can I see all the issues I'm watching on Github?

From Dev

Can i make repositories in a NAS in GitHub for Windows?

From Dev

How can I display the email of the user who has booked

From Dev

How can I get pip to list the repositories it's using?

From Java

How can I see the size of a GitHub repository before cloning it?

From Dev

how can I see a submodule reflected in a project on github?

From Dev

When the user logs in how can I get that particular users details?

From Dev

How do I see Meteor logs when the server is being run by another user?

From Dev

How do I see Meteor logs when the server is being run by another user?

From Dev

How do I create nested repositories in GitHub?

From Dev

How do I see the iptables logs in systemd

From Dev

How can I see who and where is currently mounting at on my PC via nfs?

From Dev

How can I see the running time of the terminal? (Ubuntu user)

Related Related

  1. 1

    GitHub - how can I create sub repositories?

  2. 2

    How can I see previous logs with systemd?

  3. 3

    How can I see who has access to a user's calendar in office 365?

  4. 4

    Mac OS X: How can I see who is using the files I'm trying to delete?

  5. 5

    How can I view user's personal data with omniauth?

  6. 6

    How to get number of user repositories using GitHub api?

  7. 7

    How to see github organisations repositories in Stackdriver

  8. 8

    Can you see who is watching a repo on GitHub?

  9. 9

    How can I see who reordered the teamcity build queue?

  10. 10

    How can I see who and when logged remotely to my computer?

  11. 11

    How can I list all the repositories of a Github Organization by URL?

  12. 12

    How can I see my debug logs on Unity Android?

  13. 13

    How can I see AWS Gateway logs for external calls?

  14. 14

    How can I see unavailable servers in Nginx logs?

  15. 15

    How can I see system logs while booting up ubuntu?

  16. 16

    How to get all repositories of a specific GitHub user

  17. 17

    How can I see all the issues I'm watching on Github?

  18. 18

    Can i make repositories in a NAS in GitHub for Windows?

  19. 19

    How can I display the email of the user who has booked

  20. 20

    How can I get pip to list the repositories it's using?

  21. 21

    How can I see the size of a GitHub repository before cloning it?

  22. 22

    how can I see a submodule reflected in a project on github?

  23. 23

    When the user logs in how can I get that particular users details?

  24. 24

    How do I see Meteor logs when the server is being run by another user?

  25. 25

    How do I see Meteor logs when the server is being run by another user?

  26. 26

    How do I create nested repositories in GitHub?

  27. 27

    How do I see the iptables logs in systemd

  28. 28

    How can I see who and where is currently mounting at on my PC via nfs?

  29. 29

    How can I see the running time of the terminal? (Ubuntu user)

HotTag

Archive