1

I am using the oauth gem to authenticate users through GitHub. I'm trying to get the person's username and avatar url. I can't find, or completely missed, where in the scopes I can get access to these things. This is from my user model and my initializer file:

# omniauth.rb
scope: "user, public_repo, repo"

# user.rb
def self.create_with_omniauth(auth)
  create! do |user|
    user.provider = auth["provider"]
    user.uid = auth["uid"]
    user.name = auth["info"]["name"]
    user.email = auth["info"]["email"]
  end
end

I have tried guessing what might get the username and avatar url with:

user.username = auth["info"]["login"]
user.avatar = auth["info"]["avatar_url"]
  • Try to print `auth` variable (i.e. use `p auth` or write it to log) and find appropriate fields. – Maxim Mar 08 '15 at 19:40
  • did that and the fields are "login" and "avatar_url" as i thought but they still show up as nil in the table –  Mar 08 '15 at 22:44

1 Answers1

1

This will return their username: auth.info.nickname

Also you can use this api to get avatars from the github api:

Get GitHub avatar from email or name

Community
  • 1
  • 1
ForgetfulFellow
  • 2,477
  • 2
  • 22
  • 33