omniauth-twitchtv 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/omniauth-twitchtv.rb +2 -1
- data/lib/omniauth-twitchtv/version.rb +2 -1
- data/lib/omniauth/strategies/twitchtv.rb +38 -0
- data/omniauth-twitchtv.gemspec +1 -0
- metadata +17 -1
data/lib/omniauth-twitchtv.rb
CHANGED
@@ -13,6 +13,44 @@ module OmniAuth
|
|
13
13
|
option :authorize_params, {}
|
14
14
|
option :authorize_options, [:scope, :response_type]
|
15
15
|
option :response_type, 'code'
|
16
|
+
|
17
|
+
uid do
|
18
|
+
access_token.token
|
19
|
+
end
|
20
|
+
|
21
|
+
info do
|
22
|
+
{
|
23
|
+
name: raw_info["name"]
|
24
|
+
}
|
25
|
+
end
|
26
|
+
|
27
|
+
def raw_info
|
28
|
+
get_hash_from_channel = lambda do |token|
|
29
|
+
http_client = HTTPClient.new
|
30
|
+
header = {"Authorization"=>"OAuth #{token}"}
|
31
|
+
response = http_client.get(info_url, "", header)
|
32
|
+
if response.code != "200"
|
33
|
+
raise Omniauth::Twitchtv::TwitchtvError.new("Failed to get user details from twitchtv")
|
34
|
+
end
|
35
|
+
response
|
36
|
+
end
|
37
|
+
@raw_info ||= JSON.parse(get_hash_from_channel.call(access_token.token).body)
|
38
|
+
end
|
39
|
+
|
40
|
+
def info_url
|
41
|
+
url = if self.options.scopes && (self.options.scopes.index("user_read") || self.options.scopes.index(:user_read)) then
|
42
|
+
"https://api.twitch.tv/kraken/user"
|
43
|
+
elsif self.options.scopes && (self.options.scopes.index("channel_read") || self.options.scopes.index(:channel_read)) then
|
44
|
+
"https://api.twitch.tv/kraken/channel"
|
45
|
+
elsif self.options.scope.to_sym == :user_read then
|
46
|
+
"https://api.twitch.tv/kraken/user"
|
47
|
+
elsif self.options.scope.to_sym == :channel_read then
|
48
|
+
"https://api.twitch.tv/kraken/channel"
|
49
|
+
else
|
50
|
+
raise Omniauth::Twitchtv::TwitchtvError.new("Must include at least either the channel or user read scope in omniauth-twitchtv initializer")
|
51
|
+
end
|
52
|
+
url
|
53
|
+
end
|
16
54
|
end
|
17
55
|
end
|
18
56
|
end
|
data/omniauth-twitchtv.gemspec
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: omniauth-twitchtv
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -27,6 +27,22 @@ dependencies:
|
|
27
27
|
- !ruby/object:Gem::Version
|
28
28
|
version: '1.1'
|
29
29
|
none: false
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: httpclient
|
32
|
+
prerelease: false
|
33
|
+
requirement: !ruby/object:Gem::Requirement
|
34
|
+
requirements:
|
35
|
+
- - ! '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
38
|
+
none: false
|
39
|
+
type: :runtime
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
requirements:
|
42
|
+
- - ! '>='
|
43
|
+
- !ruby/object:Gem::Version
|
44
|
+
version: '0'
|
45
|
+
none: false
|
30
46
|
- !ruby/object:Gem::Dependency
|
31
47
|
name: rspec
|
32
48
|
prerelease: false
|