Created
November 23, 2011 14:20
-
-
Save scottkf/1388780 to your computer and use it in GitHub Desktop.
omniauth-steam, prior to being bundled
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module OmniAuth | |
module Strategies | |
class Steam < OmniAuth::Strategies::OpenID | |
include OmniAuth::Strategy | |
args [:store, :api_key] | |
option :options, {} | |
option :identifier, "http://steamcommunity.com/openid" | |
option :name, :steam | |
uid { @openid_response.display_identifier.split("/").last } | |
info do | |
{ | |
:nickname => user_info["personaname"], | |
:name => user_info["realname"], | |
:url => user_info["profileurl"], | |
:location => "#{user_info["loccityid"]}, #{user_info["locstatecode"]}, #{user_info["loccountrycode"]}", | |
:avatar => user_info["avatar"] | |
} | |
end | |
extra do | |
{'raw_info' => user_hash} | |
end | |
def user_info(response=nil) | |
user_hash['response']['players']['player'].first | |
# nickname = player["personaname"] | |
# name = player["realname"] | |
# url = player["profileurl"] | |
# country = player["loccountrycode"] | |
# state = player["locstatecode"] | |
# city = player["loccityid"] | |
# | |
# { | |
# 'nickname' => nickname, | |
# 'name' => name, | |
# 'url' => url, | |
# 'location' => "#{city}, #{state}, #{country}" | |
# } | |
end | |
def user_hash | |
# Steam provides no information back on a openid response other than a 64bit user id | |
# Need to use this information and make a API call to get user information from steam. | |
if !options.api_key.blank? | |
unless @user_hash | |
uri = URI.parse("http://api.steampowered.com/") | |
req = Net::HTTP::Get.new("#{uri.path}ISteamUser/GetPlayerSummaries/v0001/?key=#{options.api_key}&steamids=#{@openid_response.display_identifier.split("/").last}") | |
res = Net::HTTP.start(uri.host, uri.port) {|http| | |
http.request(req) | |
} | |
end | |
@user_hash ||= MultiJson.decode(res.body) | |
else | |
{} | |
end | |
end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment