Class: OmniAuth::Strategies::Steam
- Inherits:
-
OpenID
- Object
- OpenID
- OmniAuth::Strategies::Steam
show all
- Defined in:
- lib/omniauth/strategies/steam.rb
Constant Summary
Constants inherited
from OpenID
OpenID::AX, OpenID::IDENTIFIER_URL_PARAMETER
Instance Attribute Summary
Attributes inherited from OpenID
#options
Instance Method Summary
collapse
Constructor Details
#initialize(app, store = nil, api_key = nil, options = {}, &block) ⇒ Steam
Returns a new instance of Steam.
5
6
7
8
9
10
|
# File 'lib/omniauth/strategies/steam.rb', line 5
def initialize(app, store = nil, api_key = nil, options = {}, &block)
options[:identifier] ||= "http://steamcommunity.com/openid"
options[:name] ||= 'steam'
@api_key = api_key
super(app, store, options, &block)
end
|
Instance Method Details
#auth_hash ⇒ Object
46
47
48
49
50
51
52
|
# File 'lib/omniauth/strategies/steam.rb', line 46
def auth_hash
OmniAuth::Utils.deep_merge(super, {
'uid' => @openid_response.display_identifier.split("/").last,
'user_info' => user_info,
'extra' => {'user_hash' => user_hash}
})
end
|
#user_hash ⇒ Object
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
|
# File 'lib/omniauth/strategies/steam.rb', line 29
def user_hash
if @api_key
unless @user_hash
uri = URI.parse("http://api.steampowered.com/")
req = Net::HTTP::Get.new("#{uri.path}ISteamUser/GetPlayerSummaries/v0001/?key=#{@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
|
#user_info(response = nil) ⇒ Object
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
|
# File 'lib/omniauth/strategies/steam.rb', line 12
def user_info(response=nil)
player = 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
|