omniauth-twitchtv 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.gitignore +6 -0
- data/.rspec +2 -0
- data/.rvmrc +1 -0
- data/Gemfile +13 -0
- data/Guardfile +11 -0
- data/README.md +3 -0
- data/Rakefile +6 -0
- data/example/Gemfile +5 -0
- data/example/config.ru +30 -0
- data/lib/omniauth/.DS_Store +0 -0
- data/lib/omniauth/strategies/twitchtv.rb +127 -0
- data/lib/omniauth-twitchtv/version.rb +5 -0
- data/lib/omniauth-twitchtv.rb +8 -0
- data/omniauth-twitchtv.gemspec +25 -0
- data/spec/omniauth/.DS_Store +0 -0
- data/spec/omniauth/strategies/twitchtv_spec.rb +31 -0
- data/spec/spec_helper.rb +14 -0
- metadata +142 -0
data/.gitignore
ADDED
data/.rspec
ADDED
data/.rvmrc
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
rvm --create 1.9.3@omniauth-twitchtv
|
data/Gemfile
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
source "http://rubygems.org"
|
2
|
+
|
3
|
+
# Specify your gem's dependencies in omniauth-twitchtv.gemspec
|
4
|
+
gemspec
|
5
|
+
|
6
|
+
group :development, :test do
|
7
|
+
gem 'guard'
|
8
|
+
gem 'guard-rspec'
|
9
|
+
gem 'guard-bundler'
|
10
|
+
gem 'growl'
|
11
|
+
gem 'rb-fsevent'
|
12
|
+
gem 'multi_json'
|
13
|
+
end
|
data/Guardfile
ADDED
data/README.md
ADDED
data/Rakefile
ADDED
data/example/Gemfile
ADDED
data/example/config.ru
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
require 'bundler/setup'
|
2
|
+
require 'sinatra/base'
|
3
|
+
require 'omniauth-twitchtv'
|
4
|
+
|
5
|
+
class App < Sinatra::Base
|
6
|
+
get '/' do
|
7
|
+
redirect '/auth/twitchtv'
|
8
|
+
end
|
9
|
+
|
10
|
+
get '/auth/:provider/callback' do
|
11
|
+
content_type 'application/json'
|
12
|
+
MultiJson.encode(request.env)
|
13
|
+
end
|
14
|
+
|
15
|
+
get '/auth/failure' do
|
16
|
+
content_type 'application/json'
|
17
|
+
MultiJson.encode(request.env)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
use Rack::Session::Cookie
|
22
|
+
|
23
|
+
use OmniAuth::Builder do
|
24
|
+
#note that the scope is different from the default
|
25
|
+
#we also have to repeat the default fields in order to get
|
26
|
+
#the extra 'connections' field in there
|
27
|
+
provider :twitchtv, ENV['TWITCHTV_CONSUMER_KEY'], :scope => 'channel_read'
|
28
|
+
end
|
29
|
+
|
30
|
+
run App.new
|
Binary file
|
@@ -0,0 +1,127 @@
|
|
1
|
+
require 'omniauth/strategies/oauth'
|
2
|
+
|
3
|
+
module OmniAuth
|
4
|
+
module Strategies
|
5
|
+
class Twitchtv
|
6
|
+
include OmniAuth::Strategy
|
7
|
+
|
8
|
+
option :name, "twitchtv"
|
9
|
+
|
10
|
+
args [:client_id]
|
11
|
+
|
12
|
+
option :client_id, nil
|
13
|
+
option :client_options, {
|
14
|
+
:site => 'https://api.twitch.tv',
|
15
|
+
:api_url => 'https://api.twitch.tv/kraken',
|
16
|
+
:authorize_url => '/kraken/oauth2/authorize',
|
17
|
+
:proxy => ENV['http_proxy'] ? URI(ENV['http_proxy']) : nil,
|
18
|
+
:callback => nil
|
19
|
+
}
|
20
|
+
option :authorize_params, {}
|
21
|
+
option :authorize_options, [:scope, :response_type]
|
22
|
+
option :response_type, 'token'
|
23
|
+
|
24
|
+
attr_accessor :json
|
25
|
+
attr_accessor :access_token
|
26
|
+
|
27
|
+
def client
|
28
|
+
::OAuth2::Client.new(options.client_id, nil, deep_symbolize(options.client_options))
|
29
|
+
end
|
30
|
+
|
31
|
+
def callback_url
|
32
|
+
options.client_options.callback || full_host + script_name + callback_path
|
33
|
+
end
|
34
|
+
|
35
|
+
def request_phase
|
36
|
+
redirect client.auth_code.authorize_url({:redirect_uri => callback_url}.merge(authorize_params))
|
37
|
+
end
|
38
|
+
|
39
|
+
def authorize_params
|
40
|
+
options.authorize_params.merge(options.authorize_options.inject({}){|h,k| h[k.to_sym] = options[k] if options[k]; h})
|
41
|
+
end
|
42
|
+
|
43
|
+
def callback_phase
|
44
|
+
if request.params['error'] || request.params['error_reason']
|
45
|
+
raise CallbackError.new(request.params['error'], request.params['error_description'] || request.params['error_reason'], request.params['error_uri'])
|
46
|
+
end
|
47
|
+
|
48
|
+
@json = {}
|
49
|
+
self.access_token = request.params["access_token"]
|
50
|
+
begin
|
51
|
+
response = RestClient.get("#{options.client_options.api_url}/user", { 'Authorization' => "OAuth #{access_token}" })
|
52
|
+
user = MultiJson.decode(response.to_s)
|
53
|
+
# {
|
54
|
+
# "name" => "xxx",
|
55
|
+
# "created_at" => "2011-11-17T02:15:55Z",
|
56
|
+
# "updated_at" => "2012-09-12T08:40:39Z",
|
57
|
+
# "logo" => nil,
|
58
|
+
# "_links" => {
|
59
|
+
# "self" => "https://api.twitch.tv/kraken/users/xxx"
|
60
|
+
# },
|
61
|
+
# "staff" => false,
|
62
|
+
# "_id" => 23456789,
|
63
|
+
# "display_name" => "xxx",
|
64
|
+
# "email" => "xxx@gmail.com"
|
65
|
+
# }
|
66
|
+
@json.merge!(user)
|
67
|
+
super
|
68
|
+
rescue CallbackError, ::RestClient::Exception => e
|
69
|
+
fail!(:invalid_credentials, e)
|
70
|
+
rescue ::MultiJson::DecodeError => e
|
71
|
+
fail!(:invalid_response, e)
|
72
|
+
rescue ::Timeout::Error, ::Errno::ETIMEDOUT => e
|
73
|
+
fail!(:timeout, e)
|
74
|
+
rescue ::SocketError => e
|
75
|
+
fail!
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
credentials do
|
80
|
+
{'token' => access_token}
|
81
|
+
end
|
82
|
+
|
83
|
+
uid do
|
84
|
+
@json['_id']
|
85
|
+
end
|
86
|
+
|
87
|
+
info do
|
88
|
+
{
|
89
|
+
:email => @json['email'],
|
90
|
+
:nickname => @json['display_name']
|
91
|
+
}
|
92
|
+
end
|
93
|
+
|
94
|
+
extra do
|
95
|
+
{ 'raw_info' => @json }
|
96
|
+
end
|
97
|
+
|
98
|
+
protected
|
99
|
+
|
100
|
+
def deep_symbolize(hash)
|
101
|
+
hash.inject({}) do |h, (k,v)|
|
102
|
+
h[k.to_sym] = v.is_a?(Hash) ? deep_symbolize(v) : v
|
103
|
+
h
|
104
|
+
end
|
105
|
+
end
|
106
|
+
|
107
|
+
def build_access_token
|
108
|
+
verifier = request.params['code']
|
109
|
+
client.auth_code.get_token(verifier, {:redirect_uri => callback_url}.merge(token_params.to_hash(:symbolize_keys => true)))
|
110
|
+
end
|
111
|
+
|
112
|
+
# An error that is indicated in the OAuth 2.0 callback.
|
113
|
+
# This could be a `redirect_uri_mismatch` or other
|
114
|
+
class CallbackError < StandardError
|
115
|
+
attr_accessor :error, :error_reason, :error_uri
|
116
|
+
|
117
|
+
def initialize(error, error_reason=nil, error_uri=nil)
|
118
|
+
self.error = error
|
119
|
+
self.error_reason = error_reason
|
120
|
+
self.error_uri = error_uri
|
121
|
+
end
|
122
|
+
end
|
123
|
+
|
124
|
+
end
|
125
|
+
end
|
126
|
+
end
|
127
|
+
OmniAuth.config.add_camelization 'twitchtv', 'Twitchtv'
|
@@ -0,0 +1,25 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
require "omniauth-twitchtv/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = "omniauth-twitchtv"
|
7
|
+
s.version = Omniauth::Twitchtv::VERSION
|
8
|
+
s.authors = ["Claudio Poli"]
|
9
|
+
s.email = ["claudio@audiobox.fm"]
|
10
|
+
s.homepage = "https://github.com/masterkain/omniauth-twitchtv"
|
11
|
+
s.summary = %q{Twitch.TV strategy for OmniAuth.}
|
12
|
+
s.description = %q{Twitch.TV strategy for OmniAuth.}
|
13
|
+
|
14
|
+
s.files = `git ls-files`.split("\n")
|
15
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
16
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
17
|
+
s.require_paths = ["lib"]
|
18
|
+
|
19
|
+
s.add_runtime_dependency 'omniauth-oauth', '~> 1.0'
|
20
|
+
|
21
|
+
s.add_development_dependency 'rspec', '~> 2.7'
|
22
|
+
s.add_development_dependency 'rake'
|
23
|
+
s.add_development_dependency 'webmock'
|
24
|
+
s.add_development_dependency 'rack-test'
|
25
|
+
end
|
Binary file
|
@@ -0,0 +1,31 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe "OmniAuth::Strategies::Twitchtv" do
|
4
|
+
subject do
|
5
|
+
OmniAuth::Strategies::Twitchtv.new(nil, @options || {})
|
6
|
+
end
|
7
|
+
|
8
|
+
it 'should add a camelization for itself' do
|
9
|
+
OmniAuth::Utils.camelize('twitchtv').should == 'Twitchtv'
|
10
|
+
end
|
11
|
+
|
12
|
+
context 'client options' do
|
13
|
+
it 'has correct Twitchtv site' do
|
14
|
+
subject.options.client_options.site.should eq('https://api.twitchtv.com')
|
15
|
+
end
|
16
|
+
|
17
|
+
it 'has correct authorize url' do
|
18
|
+
subject.options.client_options.authorize_url.should eq('https://api.twitchtv.com/kraken/oauth2/authorize')
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
context '#uid' do
|
23
|
+
before :each do
|
24
|
+
subject.stub(:raw_info) { { 'id' => '123' } }
|
25
|
+
end
|
26
|
+
|
27
|
+
it 'returns the id from raw_info' do
|
28
|
+
subject.uid.should eq('123')
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
$:.unshift File.expand_path('..', __FILE__)
|
2
|
+
$:.unshift File.expand_path('../../lib', __FILE__)
|
3
|
+
|
4
|
+
require 'rspec'
|
5
|
+
require 'rack/test'
|
6
|
+
require 'webmock/rspec'
|
7
|
+
require 'omniauth'
|
8
|
+
require 'omniauth-twitchtv'
|
9
|
+
|
10
|
+
RSpec.configure do |config|
|
11
|
+
config.include WebMock::API
|
12
|
+
config.include Rack::Test::Methods
|
13
|
+
config.extend OmniAuth::Test::StrategyMacros, :type => :strategy
|
14
|
+
end
|
metadata
ADDED
@@ -0,0 +1,142 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: omniauth-twitchtv
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease: false
|
5
|
+
segments:
|
6
|
+
- 0
|
7
|
+
- 0
|
8
|
+
- 1
|
9
|
+
version: 0.0.1
|
10
|
+
platform: ruby
|
11
|
+
authors:
|
12
|
+
- Claudio Poli
|
13
|
+
autorequire:
|
14
|
+
bindir: bin
|
15
|
+
cert_chain: []
|
16
|
+
|
17
|
+
date: 2013-01-17 00:00:00 -08:00
|
18
|
+
default_executable:
|
19
|
+
dependencies:
|
20
|
+
- !ruby/object:Gem::Dependency
|
21
|
+
name: omniauth-oauth
|
22
|
+
prerelease: false
|
23
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
24
|
+
requirements:
|
25
|
+
- - ~>
|
26
|
+
- !ruby/object:Gem::Version
|
27
|
+
segments:
|
28
|
+
- 1
|
29
|
+
- 0
|
30
|
+
version: "1.0"
|
31
|
+
type: :runtime
|
32
|
+
version_requirements: *id001
|
33
|
+
- !ruby/object:Gem::Dependency
|
34
|
+
name: rspec
|
35
|
+
prerelease: false
|
36
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ~>
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
segments:
|
41
|
+
- 2
|
42
|
+
- 7
|
43
|
+
version: "2.7"
|
44
|
+
type: :development
|
45
|
+
version_requirements: *id002
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: rake
|
48
|
+
prerelease: false
|
49
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
50
|
+
requirements:
|
51
|
+
- - ">="
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
segments:
|
54
|
+
- 0
|
55
|
+
version: "0"
|
56
|
+
type: :development
|
57
|
+
version_requirements: *id003
|
58
|
+
- !ruby/object:Gem::Dependency
|
59
|
+
name: webmock
|
60
|
+
prerelease: false
|
61
|
+
requirement: &id004 !ruby/object:Gem::Requirement
|
62
|
+
requirements:
|
63
|
+
- - ">="
|
64
|
+
- !ruby/object:Gem::Version
|
65
|
+
segments:
|
66
|
+
- 0
|
67
|
+
version: "0"
|
68
|
+
type: :development
|
69
|
+
version_requirements: *id004
|
70
|
+
- !ruby/object:Gem::Dependency
|
71
|
+
name: rack-test
|
72
|
+
prerelease: false
|
73
|
+
requirement: &id005 !ruby/object:Gem::Requirement
|
74
|
+
requirements:
|
75
|
+
- - ">="
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
segments:
|
78
|
+
- 0
|
79
|
+
version: "0"
|
80
|
+
type: :development
|
81
|
+
version_requirements: *id005
|
82
|
+
description: Twitch.TV strategy for OmniAuth.
|
83
|
+
email:
|
84
|
+
- claudio@audiobox.fm
|
85
|
+
executables: []
|
86
|
+
|
87
|
+
extensions: []
|
88
|
+
|
89
|
+
extra_rdoc_files: []
|
90
|
+
|
91
|
+
files:
|
92
|
+
- .gitignore
|
93
|
+
- .rspec
|
94
|
+
- .rvmrc
|
95
|
+
- Gemfile
|
96
|
+
- Guardfile
|
97
|
+
- README.md
|
98
|
+
- Rakefile
|
99
|
+
- example/Gemfile
|
100
|
+
- example/config.ru
|
101
|
+
- lib/omniauth-twitchtv.rb
|
102
|
+
- lib/omniauth-twitchtv/version.rb
|
103
|
+
- lib/omniauth/.DS_Store
|
104
|
+
- lib/omniauth/strategies/twitchtv.rb
|
105
|
+
- omniauth-twitchtv.gemspec
|
106
|
+
- spec/omniauth/.DS_Store
|
107
|
+
- spec/omniauth/strategies/twitchtv_spec.rb
|
108
|
+
- spec/spec_helper.rb
|
109
|
+
has_rdoc: true
|
110
|
+
homepage: https://github.com/masterkain/omniauth-twitchtv
|
111
|
+
licenses: []
|
112
|
+
|
113
|
+
post_install_message:
|
114
|
+
rdoc_options: []
|
115
|
+
|
116
|
+
require_paths:
|
117
|
+
- lib
|
118
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
119
|
+
requirements:
|
120
|
+
- - ">="
|
121
|
+
- !ruby/object:Gem::Version
|
122
|
+
segments:
|
123
|
+
- 0
|
124
|
+
version: "0"
|
125
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
126
|
+
requirements:
|
127
|
+
- - ">="
|
128
|
+
- !ruby/object:Gem::Version
|
129
|
+
segments:
|
130
|
+
- 0
|
131
|
+
version: "0"
|
132
|
+
requirements: []
|
133
|
+
|
134
|
+
rubyforge_project:
|
135
|
+
rubygems_version: 1.3.6
|
136
|
+
signing_key:
|
137
|
+
specification_version: 3
|
138
|
+
summary: Twitch.TV strategy for OmniAuth.
|
139
|
+
test_files:
|
140
|
+
- spec/omniauth/.DS_Store
|
141
|
+
- spec/omniauth/strategies/twitchtv_spec.rb
|
142
|
+
- spec/spec_helper.rb
|