0

I have been using Omniauth to retrieve an environment that contains the steam username.

The output looks like this:

<OmniAuth::AuthHash::InfoHash image="https://steamcdn-a.akamaihd.net/steamcommunity/public/images/avatars/d4/d45a66fee7932d270ec32d4457d865b485245cf1_medium.jpg" location="YT, CA" name="Daiki" nickname="Corybantic Walrus" urls=#<OmniAuth::AuthHash FriendList=#<URI::HTTP:0x0000000614f590 URL:http://api.steampowered.com/ISteamUser/GetFriendList/v0001/?key=4A8837BF7A6C439681B57F4962D8B011&steamid=76561198128055024&relationship=friend> Profile="http://steamcommunity.com/id/hatterkiller/">> provider="steam" uid="76561198128055024">

I don't really know how to format this inside Stack Overflow, so here is a cleaner Pastebin.

The information I need is inside the <Omniauth::AuthHash::Infohash thing of the code. Is there a way to use Ruby to retrieve the username (nickname) and to put it inside an array?

Sort of like this, but this only worked for the previous output format:

    auth = request.env['omniauth.auth']

 session[:current_user] = { :nickname => auth.info['nickname'],
                                      :image => auth.info['image'],
                                      :uid => auth.uid }
corybantic
  • 105
  • 2
  • 12

1 Answers1

1

Something like this:

session[:current_user] = {
  nickname: auth[:info][:nickname],
  image:    auth[:info][:image],
  uid:      auth[:uid]
}
Javier Valencia
  • 697
  • 7
  • 24
  • where come `auth`variable, from `request.env["omniauth.auth"]`? – Javier Valencia Aug 12 '15 at 09:00
  • Oh sorry! auth = request.env['omniauth.auth'] – corybantic Aug 12 '15 at 10:25
  • It's simple, before assign `session[:current_user]` try to do `logger.info auth.inspect` to assure that have values. – Javier Valencia Aug 12 '15 at 10:37
  • Ok. So they do have values. I managed to "puts" them onto my output index.erb page, with the following `{"nickname"=>"Corybantic Walrus", "image"=>"https://steamcdn-a.akamaihd.net/steamcommunity/public/images/avatars/d4/d45a66fee7932d270ec32d4457d865b485245cf1_medium.jpg", "uid"=>"76561198128055024"}` as the output. My current `

    <%= session[:current_user][:nickname] %>

    ` in the index erb isn't working. Is there another way?
    – corybantic Aug 13 '15 at 11:37
  • try with `session[:current_user] = { nickname: request.env["omniauth.auth"][:info][:nickname], image: request.env["omniauth.auth"][:info][:image], uid: request.env["omniauth.auth"][:uid] }` – Javier Valencia Aug 13 '15 at 15:29