omniauth-rtm 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.
@@ -0,0 +1,18 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+ vendor
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --format nested
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source :rubygems
2
+
3
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2012 Nickolay Abdrafikov
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,53 @@
1
+ # Omniauth RTM Strategy
2
+
3
+ This gem provides a simple way to authenticate to [remember the milk](http://rememberthemilk.com) using OmniAuth.
4
+
5
+ ## Usage
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'omniauth'
11
+ gem 'omniauth-rtm'
12
+ ```
13
+
14
+ Then integrate the strategy into your middleware:
15
+
16
+ ```ruby
17
+ use OmniAuth::Builder do
18
+ provider :rtm, ENV['RTM_KEY'], ENV['RTM_SECRET']
19
+ end
20
+ ```
21
+
22
+ In Rails, you'll want to add to the middleware stack:
23
+
24
+ ```ruby
25
+ Rails.application.config.middleware.use OmniAuth::Builder do
26
+ provider :rtm, ENV['RTM_KEY'], ENV['RTM_SECRET']
27
+ end
28
+ ```
29
+
30
+ ## Auth Hash Schema
31
+
32
+ The following information is provided back to you for this provider:
33
+
34
+ ```ruby
35
+ {
36
+ uid: '12345',
37
+ info: {
38
+ nickname: 'name',
39
+ name: 'Full Name'
40
+ },
41
+ credentials: {
42
+ token: 'thetoken' # can be used to auth to the API
43
+ }
44
+ }
45
+ ```
46
+
47
+ ## Contributing
48
+
49
+ 1. Fork it
50
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
51
+ 3. Commit your changes (`git commit -am 'Added some feature'`)
52
+ 4. Push to the branch (`git push origin my-new-feature`)
53
+ 5. Create new Pull Request
@@ -0,0 +1,9 @@
1
+ #!/usr/bin/env rake
2
+ require 'bundler/gem_tasks'
3
+ require 'rspec/core/rake_task'
4
+
5
+ desc 'Default: run specs.'
6
+ task :default => :spec
7
+
8
+ desc 'Run specs'
9
+ RSpec::Core::RakeTask.new
@@ -0,0 +1,2 @@
1
+ require "omniauth-rtm/version"
2
+ require "omniauth/strategies/rtm"
@@ -0,0 +1,5 @@
1
+ module Omniauth
2
+ module RTM
3
+ VERSION = "0.0.1"
4
+ end
5
+ end
@@ -0,0 +1,80 @@
1
+ require 'omniauth'
2
+ require 'moocow'
3
+
4
+ module OmniAuth
5
+ module Strategies
6
+ class RTM
7
+ include OmniAuth::Strategy
8
+
9
+ args [:consumer_key, :consumer_secret]
10
+
11
+ option :consumer_key, nil
12
+ option :consumer_secret, nil
13
+
14
+ def request_phase
15
+ auth_url = rtm_auth.url :delete, :web #, "http://localhost:3000/auth/rtm/callback"
16
+
17
+ session['oauth'] ||= {}
18
+ session['oauth']['rtm'] = {}
19
+
20
+ redirect(auth_url)
21
+ rescue ::Timeout::Error => e
22
+ fail!(:timeout, e)
23
+ rescue ::Net::HTTPFatalError => e
24
+ fail!(:service_unavailable, e)
25
+ end
26
+
27
+ def callback_phase
28
+ raise OmniAuth::NoSessionError.new("Session Expired") if session['oauth'].nil?
29
+
30
+ rtm_auth.frob = request.params['frob']
31
+
32
+ @token = rtm_auth.get_token
33
+ rtm.token = @token
34
+
35
+ resp = rtm.check_token
36
+
37
+ @uid = resp['auth']['user']['id']
38
+ @nickname = resp['auth']['user']['username']
39
+ @fullname = resp['auth']['user']['fullname']
40
+
41
+ super
42
+ rescue ::Timeout::Error => e
43
+ fail!(:timeout, e)
44
+ rescue ::Net::HTTPFatalError, ::OpenSSL::SSL::SSLError => e
45
+ fail!(:service_unavailable, e)
46
+ rescue ::RTM::VerificationException => e
47
+ fail!(:invalid_credentials, e)
48
+ rescue ::OmniAuth::NoSessionError => e
49
+ fail!(:session_expired, e)
50
+ end
51
+
52
+ uid { @uid }
53
+
54
+ info do
55
+ {
56
+ :name => @fullname,
57
+ :nickname => @nickname
58
+ }
59
+ end
60
+
61
+ credentials do
62
+ {
63
+ :token => @token
64
+ }
65
+ end
66
+
67
+ private
68
+
69
+ def rtm
70
+ @rtm ||= ::RTM::RTM.new(::RTM::Endpoint.new(options.consumer_key, options.consumer_secret))
71
+ end
72
+
73
+ def rtm_auth
74
+ @auth ||= rtm.auth
75
+ end
76
+ end
77
+ end
78
+ end
79
+
80
+ OmniAuth.config.add_camelization 'rtm', 'RTM'
@@ -0,0 +1,24 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require File.expand_path('../lib/omniauth-rtm/version', __FILE__)
3
+
4
+ Gem::Specification.new do |gem|
5
+ gem.authors = ["Nickolay Abdrafikov"]
6
+ gem.email = ["nicck.olay@gmail.com"]
7
+ gem.description = %q{OmniAuth strategy for Remember The Milk}
8
+ gem.summary = %q{OmniAuth strategy for Remember The Milk}
9
+ gem.homepage = "http://github.com/nicck/omniauth-rtm"
10
+
11
+ gem.add_runtime_dependency 'omniauth', '~> 1.0'
12
+ gem.add_runtime_dependency 'moocow', '~> 1.1.0'
13
+
14
+ gem.add_development_dependency 'rspec', '~> 2.6'
15
+ gem.add_development_dependency 'simplecov'
16
+ gem.add_development_dependency 'rack-test'
17
+
18
+ gem.files = `git ls-files`.split($\)
19
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
20
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
21
+ gem.name = "omniauth-rtm"
22
+ gem.require_paths = ["lib"]
23
+ gem.version = Omniauth::RTM::VERSION
24
+ end
@@ -0,0 +1,190 @@
1
+ require "spec_helper"
2
+
3
+ describe "OmniAuth::Strategies::RTM" do
4
+ def app
5
+ Rack::Builder.new {
6
+ use OmniAuth::Test::PhonySession
7
+ use OmniAuth::Builder do
8
+ provider :rtm, 'apikey', 'apisec'
9
+ end
10
+ run lambda { |env| [404, {'Content-Type' => 'text/plain'}, [env.key?('omniauth.auth').to_s]] }
11
+ }.to_app
12
+ end
13
+
14
+ def session
15
+ last_request.env['rack.session']
16
+ end
17
+
18
+ it 'should add a camelization for itself' do
19
+ OmniAuth::Utils.camelize('rtm').should == 'RTM'
20
+ end
21
+
22
+ let(:rtm){ double 'rtm' }
23
+ let(:rtm_auth){ double 'rtm_auth' }
24
+ let(:auth_url){ double 'auth_url' }
25
+
26
+ before do
27
+ RTM::RTM.stub(:new).and_return(rtm)
28
+ rtm.stub(:auth).and_return(rtm_auth)
29
+ rtm_auth.stub(:url).and_return(auth_url)
30
+ end
31
+
32
+ describe '/auth/rtm' do
33
+ context 'successful' do
34
+ it 'should redirect to authorize_url' do
35
+ rtm_auth.should_receive(:url).with(:delete, :web).and_return(auth_url)
36
+
37
+ get '/auth/rtm'
38
+
39
+ last_response.should be_redirect
40
+ last_response.headers['Location'].should == auth_url
41
+ end
42
+ end
43
+
44
+ context 'unsuccessful' do
45
+ it 'should call fail! with :timeout' do
46
+ rtm_auth.stub(:url).and_raise(::Timeout::Error)
47
+
48
+ get '/auth/rtm'
49
+
50
+ last_request.env['omniauth.error'].should be_kind_of(::Timeout::Error)
51
+ last_request.env['omniauth.error.type'] = :timeout
52
+ end
53
+
54
+ it 'should call fail! with :service_unavailable' do
55
+ rtm_auth.stub(:url).and_raise(::Net::HTTPFatalError.new(%Q{502 "Bad Gateway"}, nil))
56
+
57
+ get '/auth/rtm'
58
+
59
+ last_request.env['omniauth.error'].should be_kind_of(::Net::HTTPFatalError)
60
+ last_request.env['omniauth.error.type'] = :service_unavailable
61
+ end
62
+ end
63
+ end
64
+
65
+ describe '/auth/rtm/callback' do
66
+ before do
67
+ rtm_auth.stub(:frob=)
68
+ rtm_auth.stub(:get_token).and_return('rtmaccesstoken')
69
+ rtm.stub(:token=)
70
+ rtm.stub(:check_token).and_return({
71
+ 'auth' => {'user' => {
72
+ 'id' => 123456,
73
+ 'username' => 'nicck',
74
+ 'fullname' => 'Nickolay Abdrafikov',
75
+ }}
76
+ })
77
+ end
78
+
79
+ it 'should call through to the master app' do
80
+ get '/auth/rtm/callback', {:frob => '123frob456'}, {'rack.session' => {'oauth' => {"rtm" => {}}}}
81
+ last_response.body.should == 'true'
82
+ end
83
+
84
+ it 'should pass uid to env' do
85
+ get '/auth/rtm/callback', {:frob => '123frob456'}, {'rack.session' => {'oauth' => {"rtm" => {}}}}
86
+ last_request.env['omniauth.auth']['uid'].should == 123456
87
+ end
88
+
89
+ it 'should pass token to env' do
90
+ get '/auth/rtm/callback', {:frob => '123frob456'}, {'rack.session' => {'oauth' => {"rtm" => {}}}}
91
+ last_request.env['omniauth.auth']['provider'].should == 'rtm'
92
+ last_request.env['omniauth.auth']['credentials']['token'].should == 'rtmaccesstoken'
93
+ end
94
+
95
+ it 'should pass info to env' do
96
+ get '/auth/rtm/callback', {:frob => '123frob456'}, {'rack.session' => {'oauth' => {"rtm" => {}}}}
97
+ last_request.env['omniauth.auth']['info']['name'].should == 'Nickolay Abdrafikov'
98
+ last_request.env['omniauth.auth']['info']['nickname'].should == 'nicck'
99
+ end
100
+
101
+ describe 'rtm_api' do
102
+ after do
103
+ get '/auth/rtm/callback', {:frob => '123frob456'}, {'rack.session' => {'oauth' => {"rtm" => {}}}}
104
+ end
105
+
106
+ it 'should pass frob to rtm_auth' do
107
+ rtm_auth.should_receive(:frob=).with('123frob456')
108
+ end
109
+
110
+ it 'should get token from rtm_auth' do
111
+ rtm_auth.should_receive(:get_token)
112
+ end
113
+
114
+ it 'should pass token to rtm' do
115
+ rtm.should_receive(:token=).with('rtmaccesstoken')
116
+ end
117
+
118
+ it 'should fetch user info from rtm' do
119
+ rtm.should_receive(:check_token)
120
+ end
121
+ end
122
+
123
+ context "bad gateway (or any 5xx) for access_token" do
124
+ before do
125
+ rtm_auth.stub(:get_token).
126
+ and_raise(::Net::HTTPFatalError.new(%Q{502 "Bad Gateway"}, nil))
127
+
128
+ get '/auth/rtm/callback', {:frob => '123frob456'}, {'rack.session' => {'oauth' => {"rtm" => {}}}}
129
+ end
130
+
131
+ it 'should call fail! with :service_unavailable' do
132
+ last_request.env['omniauth.error'].should be_kind_of(::Net::HTTPFatalError)
133
+ last_request.env['omniauth.error.type'] = :service_unavailable
134
+ end
135
+ end
136
+
137
+ context "SSL failure" do
138
+ before do
139
+ rtm_auth.stub(:get_token).
140
+ and_raise(::OpenSSL::SSL::SSLError.new("SSL_connect returned=1 errno=0 state=SSLv3 read server certificate B: certificate verify failed"))
141
+
142
+ get '/auth/rtm/callback', {:frob => '123frob456'}, {'rack.session' => {'oauth' => {"rtm" => {'callback_confirmed' => true, 'request_token' => 'yourtoken', 'request_secret' => 'yoursecret'}}}}
143
+ end
144
+
145
+ it 'should call fail! with :service_unavailable' do
146
+ last_request.env['omniauth.error'].should be_kind_of(::OpenSSL::SSL::SSLError)
147
+ last_request.env['omniauth.error.type'] = :service_unavailable
148
+ end
149
+ end
150
+
151
+ context "Timeout failure" do
152
+ before do
153
+ rtm_auth.stub(:get_token).
154
+ and_raise(::Timeout::Error)
155
+
156
+ get '/auth/rtm/callback', {:frob => '123frob456'}, {'rack.session' => {'oauth' => {"rtm" => {'callback_confirmed' => true, 'request_token' => 'yourtoken', 'request_secret' => 'yoursecret'}}}}
157
+ end
158
+
159
+ it 'should call fail! with :timeout' do
160
+ last_request.env['omniauth.error'].should be_kind_of(::Timeout::Error)
161
+ last_request.env['omniauth.error.type'] = :timeout
162
+ end
163
+ end
164
+
165
+ context "Invalid frob failure" do
166
+ before do
167
+ rtm_auth.stub(:get_token).
168
+ and_raise(::RTM::VerificationException)
169
+
170
+ get '/auth/rtm/callback', {:frob => '123frob456'}, {'rack.session' => {'oauth' => {"rtm" => {'callback_confirmed' => true, 'request_token' => 'yourtoken', 'request_secret' => 'yoursecret'}}}}
171
+ end
172
+
173
+ it 'should call fail! with :invalid_credentials' do
174
+ last_request.env['omniauth.error'].should be_kind_of(::RTM::VerificationException)
175
+ last_request.env['omniauth.error.type'] = :invalid_credentials
176
+ end
177
+ end
178
+ end
179
+
180
+ describe '/auth/rtm/callback with expired session' do
181
+ before do
182
+ get '/auth/rtm/callback', {:from => '123frob456'}, {'rack.session' => {}}
183
+ end
184
+
185
+ it 'should call fail! with :session_expired' do
186
+ last_request.env['omniauth.error'].should be_kind_of(::OmniAuth::NoSessionError)
187
+ last_request.env['omniauth.error.type'] = :session_expired
188
+ end
189
+ end
190
+ end
@@ -0,0 +1,24 @@
1
+ $:.unshift File.expand_path('..', __FILE__)
2
+ $:.unshift File.expand_path('../../lib', __FILE__)
3
+
4
+ if ENV["COVERAGE"]
5
+ require 'simplecov'
6
+
7
+ SimpleCov.start {
8
+ add_filter "/vendor/"
9
+ add_filter "/spec/"
10
+ }
11
+ end
12
+
13
+ require 'rspec'
14
+ require 'rack/test'
15
+ require 'omniauth'
16
+ require 'omniauth-rtm'
17
+
18
+ RSpec.configure do |config|
19
+ config.include Rack::Test::Methods
20
+ config.extend OmniAuth::Test::StrategyMacros, :type => :strategy
21
+
22
+ config.mock_with :rspec
23
+ config.fail_fast
24
+ end
metadata ADDED
@@ -0,0 +1,120 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: omniauth-rtm
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Nickolay Abdrafikov
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-03-24 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: omniauth
16
+ requirement: &2193240960 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: '1.0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: *2193240960
25
+ - !ruby/object:Gem::Dependency
26
+ name: moocow
27
+ requirement: &2193240460 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ~>
31
+ - !ruby/object:Gem::Version
32
+ version: 1.1.0
33
+ type: :runtime
34
+ prerelease: false
35
+ version_requirements: *2193240460
36
+ - !ruby/object:Gem::Dependency
37
+ name: rspec
38
+ requirement: &2193240000 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ~>
42
+ - !ruby/object:Gem::Version
43
+ version: '2.6'
44
+ type: :development
45
+ prerelease: false
46
+ version_requirements: *2193240000
47
+ - !ruby/object:Gem::Dependency
48
+ name: simplecov
49
+ requirement: &2193239620 !ruby/object:Gem::Requirement
50
+ none: false
51
+ requirements:
52
+ - - ! '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ type: :development
56
+ prerelease: false
57
+ version_requirements: *2193239620
58
+ - !ruby/object:Gem::Dependency
59
+ name: rack-test
60
+ requirement: &2193239160 !ruby/object:Gem::Requirement
61
+ none: false
62
+ requirements:
63
+ - - ! '>='
64
+ - !ruby/object:Gem::Version
65
+ version: '0'
66
+ type: :development
67
+ prerelease: false
68
+ version_requirements: *2193239160
69
+ description: OmniAuth strategy for Remember The Milk
70
+ email:
71
+ - nicck.olay@gmail.com
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - .gitignore
77
+ - .rspec
78
+ - Gemfile
79
+ - LICENSE
80
+ - README.md
81
+ - Rakefile
82
+ - lib/omniauth-rtm.rb
83
+ - lib/omniauth-rtm/version.rb
84
+ - lib/omniauth/strategies/rtm.rb
85
+ - omniauth-rtm.gemspec
86
+ - spec/omniauth/strategies/rtm_spec.rb
87
+ - spec/spec_helper.rb
88
+ homepage: http://github.com/nicck/omniauth-rtm
89
+ licenses: []
90
+ post_install_message:
91
+ rdoc_options: []
92
+ require_paths:
93
+ - lib
94
+ required_ruby_version: !ruby/object:Gem::Requirement
95
+ none: false
96
+ requirements:
97
+ - - ! '>='
98
+ - !ruby/object:Gem::Version
99
+ version: '0'
100
+ segments:
101
+ - 0
102
+ hash: -2558610393677787504
103
+ required_rubygems_version: !ruby/object:Gem::Requirement
104
+ none: false
105
+ requirements:
106
+ - - ! '>='
107
+ - !ruby/object:Gem::Version
108
+ version: '0'
109
+ segments:
110
+ - 0
111
+ hash: -2558610393677787504
112
+ requirements: []
113
+ rubyforge_project:
114
+ rubygems_version: 1.8.11
115
+ signing_key:
116
+ specification_version: 3
117
+ summary: OmniAuth strategy for Remember The Milk
118
+ test_files:
119
+ - spec/omniauth/strategies/rtm_spec.rb
120
+ - spec/spec_helper.rb