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.
@@ -3,6 +3,7 @@ require 'omniauth/strategies/twitchtv'
3
3
 
4
4
  module Omniauth
5
5
  module Twitchtv
6
- # Your code goes here...
6
+ class TwitchtvError < OmniAuth::Error
7
+ end
7
8
  end
8
9
  end
@@ -1,5 +1,6 @@
1
1
  module Omniauth
2
2
  module Twitchtv
3
- VERSION = "0.1.0"
3
+ VERSION = "0.2.0"
4
4
  end
5
5
  end
6
+
@@ -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
@@ -17,6 +17,7 @@ Gem::Specification.new do |s|
17
17
  s.require_paths = ["lib"]
18
18
 
19
19
  s.add_runtime_dependency 'omniauth-oauth2', '~> 1.1'
20
+ s.add_runtime_dependency 'httpclient'
20
21
 
21
22
  s.add_development_dependency 'rspec', '~> 2.7'
22
23
  s.add_development_dependency 'rake'
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.1.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