omniauth-launchpad 0.0.1 → 0.1.0

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ffc66ef2a2bad8e4209bdd82da5d5630119e108b
4
- data.tar.gz: 508eee24e8f3a0f6a8eac9c6a77feb5d70edf072
3
+ metadata.gz: 8d070daeb3e1490ec25e3392882228c6688e3746
4
+ data.tar.gz: 152c9448d0a5180956e052fea005c739aaae31b6
5
5
  SHA512:
6
- metadata.gz: 6a24c601fb669238dcaafb4f8c4d7219554267caa8d5b21797a56c30e68a941cadac276718b1fae3a5c5f0a54e4873eea401cfcc147be4e506f8a743371f0b81
7
- data.tar.gz: a64270682397b08cbf43b6d6acecba996b82b9ce09832ab100cb98893376de50e5edbd94a4ef00361ef2440ec943ce8762262f84a0669737491a8ebf50338fab
6
+ metadata.gz: f21c0175ec7f1896cceab351a18e530efda254787949f6f04fd43996f05fb9552ab38bb3104e9d6b49d1c30d53118c55e32c56563204d27d0cd759f2a0ee9a71
7
+ data.tar.gz: e38f53fe5cb0224ccb6972c4c4e1987b1104d7da786f09755a629b82c14c2db7d35399daec006dc3a2842109104cecf51625dbdf127f1b1d189cd2c5d8fc6125
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --require spec_helper
@@ -0,0 +1,14 @@
1
+ before_install:
2
+ - gem update --system 2.1.11
3
+ language: ruby
4
+ rvm:
5
+ - "1.9.2"
6
+ - "1.9.3"
7
+ - "2.0.0"
8
+ - "2.1.0"
9
+ - "rbx"
10
+ - "jruby"
11
+ matrix:
12
+ allow_failures:
13
+ - rvm: "rbx"
14
+ - rvm: "jruby"
data/README.md CHANGED
@@ -1,6 +1,7 @@
1
1
  # Omniauth::Launchpad
2
+ Build status: [![Build Status](https://travis-ci.org/joaopapereira/omniauth-launchpad.png?branch=master)](https://travis-ci.org/joaopapereira/omniauth-launchpad)
2
3
 
3
- TODO: Write a gem description
4
+ This gem allows the user to login with the launchpad account
4
5
 
5
6
  ## Installation
6
7
 
@@ -20,11 +21,16 @@ Or install it yourself as:
20
21
 
21
22
  ## Usage
22
23
 
23
- TODO: Write usage instructions here
24
+ Add the middleware to a Rails app in config/initializers/omniauth.rb:
25
+ ```
26
+ Rails.application.config.middleware.use OmniAuth::Builder do
27
+ provider :launchpad, CONSUMER_KEY
28
+ end
29
+ ```
24
30
 
25
31
  ## Contributing
26
32
 
27
- 1. Fork it ( https://github.com/[my-github-username]/omniauth-launchpad/fork )
33
+ 1. Fork it ( https://github.com/joaopapereira/omniauth-launchpad/fork )
28
34
  2. Create your feature branch (`git checkout -b my-new-feature`)
29
35
  3. Commit your changes (`git commit -am 'Add some feature'`)
30
36
  4. Push to the branch (`git push origin my-new-feature`)
data/Rakefile CHANGED
@@ -1,2 +1,5 @@
1
1
  require "bundler/gem_tasks"
2
+ require File.join('rspec', 'core', 'rake_task')
2
3
 
4
+ RSpec::Core::RakeTask.new(:spec)
5
+ task :default => :spec
@@ -1,5 +1,5 @@
1
1
  module Omniauth
2
2
  module Launchpad
3
- VERSION = "0.0.1"
3
+ VERSION = "0.1.0"
4
4
  end
5
5
  end
@@ -24,7 +24,6 @@ module OmniAuth
24
24
  }
25
25
  def initialize(app, consumer_key="babun", options={}, &block)
26
26
  options[:oauth_consumer_key] = consumer_key
27
- options[:oauth_consumer_secret] = consumer_secret
28
27
  super(app, consumer_key, nil, options, &block)
29
28
  end
30
29
 
@@ -52,28 +51,27 @@ module OmniAuth
52
51
  { raw_user_info: raw_user_info }
53
52
  end
54
53
  def request_phase
55
- puts "Request info: #{options.request_param}"
56
54
  request_options = {:oauth_consumer_key => options[:oauth_consumer_key], :realm => "https://api.launchpad.net/"}
57
- request_options.merge!(options[:authorize_params])
58
-
59
- request_token = consumer.get_request_token({:oauth_callback => callback_url}, request_options)
60
- session['oauth'] ||= {}
61
- session['oauth'][name.to_s] = {'callback_confirmed' => request_token.callback_confirmed?, 'request_token' => request_token.token, 'request_secret' => request_token.secret}
62
- r = Rack::Response.new
63
-
64
- if request_token.callback_confirmed?
65
- r.redirect(request_token.authorize_url)
66
- else
67
- r.redirect(request_token.authorize_url(:oauth_callback => callback_url))
68
- end
69
- @request_token = request_token
70
- r.finish
71
-
72
- rescue ::Timeout::Error => e
73
- fail!(:timeout, e)
74
- rescue ::Net::HTTPFatalError, ::OpenSSL::SSL::SSLError => e
75
- fail!(:service_unavailable, e)
55
+ request_options.merge!(options[:authorize_params])
56
+
57
+ request_token = consumer.get_request_token({:oauth_callback => callback_url}, request_options)
58
+ session['oauth'] ||= {}
59
+ session['oauth'][name.to_s] = {'callback_confirmed' => request_token.callback_confirmed?, 'request_token' => request_token.token, 'request_secret' => request_token.secret}
60
+ r = Rack::Response.new
61
+
62
+ if request_token.callback_confirmed?
63
+ r.redirect(request_token.authorize_url)
64
+ else
65
+ r.redirect(request_token.authorize_url(:oauth_callback => callback_url))
76
66
  end
67
+ @request_token = request_token
68
+ r.finish
69
+
70
+ rescue ::Timeout::Error => e
71
+ fail!(:timeout, e)
72
+ rescue ::Net::HTTPFatalError, ::OpenSSL::SSL::SSLError => e
73
+ fail!(:service_unavailable, e)
74
+ end
77
75
  end
78
76
  end
79
77
  end
@@ -17,8 +17,9 @@ Gem::Specification.new do |spec|
17
17
  spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
18
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
19
  spec.require_paths = ["lib"]
20
+ spec.required_ruby_version = '>= 1.9.2'
20
21
 
21
- spec.add_development_dependency "bundler", "~> 1.7"
22
+ spec.add_development_dependency "bundler"
22
23
  spec.add_development_dependency "rake", "~> 10.0"
23
24
  spec.add_development_dependency 'rspec'
24
25
  spec.add_development_dependency 'webmock'
@@ -27,8 +28,5 @@ Gem::Specification.new do |spec|
27
28
 
28
29
  spec.add_runtime_dependency 'omniauth', '>= 1.1.1'
29
30
  spec.add_runtime_dependency 'omniauth-oauth'
30
- #spec.add_runtime_dependency 'faraday'
31
- #spec.add_runtime_dependency 'faraday_middleware'
32
- #spec.add_runtime_dependency 'simple_oauth'
33
31
  spec.add_runtime_dependency 'multi_json', '~> 1.3'
34
32
  end
@@ -0,0 +1,137 @@
1
+ require 'spec_helper'
2
+ require 'omniauth-launchpad'
3
+
4
+ describe OmniAuth::Strategies::Launchpad do
5
+ def app
6
+ Rack::Builder.new {
7
+ use OmniAuth::Test::PhonySession
8
+ use OmniAuth::Builder do
9
+ provider :launchpad, "testing-launchpad"
10
+ end
11
+ run lambda { |env| [404, {'Content-Type' => 'text/plain'}, [env.key?('omniauth.auth').to_s]] }
12
+ }.to_app
13
+ end
14
+ def strategy
15
+ # return the parameters to a Rack::Builder map call:
16
+ [OmniAuth::Strategies::Launchpad.new, 'bamm']
17
+ end
18
+ def session
19
+ last_request.env['rack.session']
20
+ end
21
+
22
+ before do
23
+ stub_request(:post, 'https://launchpad.net/+request-token').
24
+ to_return(:body => "oauth_token=yourtoken&oauth_token_secret=yoursecret&oauth_callback_confirmed=true")
25
+ end
26
+ it 'can be camel-cased' do
27
+ OmniAuth::Utils.camelize( 'launchpad' ).should == 'Launchpad'
28
+ end
29
+
30
+ describe '/auth/launchpad' do
31
+ context 'successful' do
32
+ before do
33
+ get '/auth/launchpad'
34
+ end
35
+
36
+ it 'should redirect to authorize_url' do
37
+ last_response.should be_redirect
38
+ last_response.headers['Location'].should == 'https://launchpad.net/+authorize-token?oauth_token=yourtoken'
39
+ end
40
+
41
+
42
+ it 'should set appropriate session variables' do
43
+ session['oauth'].should == {"launchpad"=>{"callback_confirmed"=>true, "request_token"=>"yourtoken", "request_secret"=>"yoursecret"}}
44
+ end
45
+ end
46
+
47
+ context 'unsuccessful' do
48
+ before do
49
+ stub_request(:post, 'https://launchpad.net/+request-token').
50
+ to_raise(::Net::HTTPFatalError.new(%Q{502 "Bad Gateway"}, nil))
51
+ get '/auth/launchpad'
52
+ end
53
+
54
+ it 'should call fail! with :service_unavailable' do
55
+ last_request.env['omniauth.error'].should be_kind_of(::Net::HTTPFatalError)
56
+ last_request.env['omniauth.error.type'] = :service_unavailable
57
+ end
58
+
59
+ context "SSL failure" do
60
+ before do
61
+ stub_request(:post, 'https://launchpad.net/+request-token').
62
+ to_raise(::OpenSSL::SSL::SSLError.new("SSL_connect returned=1 errno=0 state=SSLv3 read server certificate B: certificate verify failed"))
63
+ get '/auth/launchpad'
64
+ end
65
+
66
+ it 'should call fail! with :service_unavailable' do
67
+ last_request.env['omniauth.error'].should be_kind_of(::OpenSSL::SSL::SSLError)
68
+ last_request.env['omniauth.error.type'] = :service_unavailable
69
+ end
70
+ end
71
+ end
72
+ end
73
+
74
+ describe '/auth/launchpad/callback' do
75
+ before do
76
+ body =<<BODY
77
+ oauth_token=PsK9cpbll1KwehhRDckr&oauth_token_secret=M2hsnmsfEIAjS3bTWg6t8X2GKhlm152PRDjLLmtQdr9C8KFZWPl9c8QbLfWddE0qpz5L56pMKKFKEfv1&lp.context=None
78
+ BODY
79
+
80
+ stub_request(:post, 'https://launchpad.net/+request-token').
81
+ to_return(:body => "oauth_token=yourtoken&oauth_token_secret=yoursecret")
82
+ stub_request(:post, "https://launchpad.net/+access-token").
83
+ with(:body => hash_including({"oauth_consumer_key"=>"testing-launchpad",
84
+ "oauth_signature"=>"&yoursecret",
85
+ "oauth_signature_method"=>"PLAINTEXT",
86
+ "oauth_token"=>"yourtoken",
87
+ "oauth_version"=>"1.0"})).
88
+ to_return(:status => 200, :body => body, :headers => {})
89
+ stub_request(:get, "https://api.launchpad.net/devel/people/+me").
90
+ to_return(:status => 302, :headers => {"location" =>"https://api.launchpad.net/devel/~theguy"})
91
+ stub_request(:get, "https://api.launchpad.net/devel/~theguy").
92
+ to_return(:status => 200, :body => "bamm")
93
+
94
+ get '/auth/launchpad/callback', {}, {'rack.session' => {'oauth' => {"launchpad" => {'callback_confirmed' => true, 'request_token' => 'yourtoken', 'request_secret' => 'yoursecret'}}}}
95
+ end
96
+
97
+
98
+ context "bad gateway (or any 5xx) for access_token" do
99
+ before do
100
+ stub_request(:post, 'https://launchpad.net/+access-token').
101
+ to_raise(::Net::HTTPFatalError.new(%Q{502 "Bad Gateway"}, nil))
102
+ get '/auth/launchpad/callback', {:oauth_verifier => 'dudeman'}, {'rack.session' => {'oauth' => {"launchpad" => {'callback_confirmed' => true, 'request_token' => 'yourtoken', 'request_secret' => 'yoursecret'}}}}
103
+ end
104
+
105
+ it 'should call fail! with :service_unavailable' do
106
+ last_request.env['omniauth.error'].should be_kind_of(::Net::HTTPFatalError)
107
+ last_request.env['omniauth.error.type'] = :service_unavailable
108
+ end
109
+ end
110
+
111
+ context "SSL failure" do
112
+ before do
113
+ stub_request(:post, 'https://launchpad.net/+access-token').
114
+ to_raise(::OpenSSL::SSL::SSLError.new("SSL_connect returned=1 errno=0 state=SSLv3 read server certificate B: certificate verify failed"))
115
+ get '/auth/launchpad/callback', {:oauth_verifier => 'dudeman'}, {'rack.session' => {'oauth' => {"launchpad" => {'callback_confirmed' => true, 'request_token' => 'yourtoken', 'request_secret' => 'yoursecret'}}}}
116
+ end
117
+
118
+ it 'should call fail! with :service_unavailable' do
119
+ last_request.env['omniauth.error'].should be_kind_of(::OpenSSL::SSL::SSLError)
120
+ last_request.env['omniauth.error.type'] = :service_unavailable
121
+ end
122
+ end
123
+ end
124
+
125
+ describe '/auth/launchpad/callback with expired session' do
126
+ before do
127
+ stub_request(:post, 'https://launchpad.net/+request-token').
128
+ to_return(:body => "oauth_token=yourtoken&oauth_token_secret=yoursecret")
129
+ get '/auth/launchpad/callback', {:oauth_verifier => 'dudeman'}, {'rack.session' => {}}
130
+ end
131
+
132
+ it 'should call fail! with :session_expired' do
133
+ last_request.env['omniauth.error'].should be_kind_of(::OmniAuth::NoSessionError)
134
+ last_request.env['omniauth.error.type'] = :session_expired
135
+ end
136
+ end
137
+ end
@@ -0,0 +1,15 @@
1
+ $:.unshift File.expand_path('..', __FILE__)
2
+ $:.unshift File.expand_path('../../lib', __FILE__)
3
+ require 'simplecov'
4
+ SimpleCov.start
5
+ require 'rspec'
6
+ require 'rack/test'
7
+ require 'webmock/rspec'
8
+ require 'omniauth'
9
+ require 'omniauth-oauth'
10
+
11
+ RSpec.configure do |config|
12
+ config.include WebMock::API
13
+ config.include Rack::Test::Methods
14
+ config.extend OmniAuth::Test::StrategyMacros, :type => :strategy
15
+ end
metadata CHANGED
@@ -1,29 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: omniauth-launchpad
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - João Pereira
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-04-04 00:00:00.000000000 Z
11
+ date: 2017-04-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - "~>"
17
+ - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: '1.7'
19
+ version: '0'
20
20
  type: :development
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - "~>"
24
+ - - ">="
25
25
  - !ruby/object:Gem::Version
26
- version: '1.7'
26
+ version: '0'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rake
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -144,13 +144,12 @@ extensions: []
144
144
  extra_rdoc_files: []
145
145
  files:
146
146
  - ".gitignore"
147
+ - ".rspec"
148
+ - ".travis.yml"
147
149
  - Gemfile
148
150
  - LICENSE.txt
149
151
  - README.md
150
152
  - Rakefile
151
- - example/Gemfile
152
- - example/Gemfile.lock
153
- - example/config.ru
154
153
  - example/simple/Gemfile
155
154
  - example/simple/Gemfile.lock
156
155
  - example/simple/My Runner.run
@@ -160,6 +159,8 @@ files:
160
159
  - lib/omniauth/launchpad/version.rb
161
160
  - lib/omniauth/strategies/launchpad.rb
162
161
  - omniauth-launchpad.gemspec
162
+ - spec/omniauth/strategies/launchpad_spec.rb
163
+ - spec/spec_helper.rb
163
164
  homepage: ''
164
165
  licenses:
165
166
  - MIT
@@ -172,7 +173,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
172
173
  requirements:
173
174
  - - ">="
174
175
  - !ruby/object:Gem::Version
175
- version: '0'
176
+ version: 1.9.2
176
177
  required_rubygems_version: !ruby/object:Gem::Requirement
177
178
  requirements:
178
179
  - - ">="
@@ -180,8 +181,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
180
181
  version: '0'
181
182
  requirements: []
182
183
  rubyforge_project:
183
- rubygems_version: 2.4.2
184
+ rubygems_version: 2.6.10
184
185
  signing_key:
185
186
  specification_version: 4
186
187
  summary: Launchpad login for OmniAuth
187
- test_files: []
188
+ test_files:
189
+ - spec/omniauth/strategies/launchpad_spec.rb
190
+ - spec/spec_helper.rb
@@ -1,4 +0,0 @@
1
- source :rubygems
2
- gem 'sinatra'
3
- gem 'omniauth-launchpad', :path => '../../'
4
- gem 'omniauth'
@@ -1,36 +0,0 @@
1
- PATH
2
- remote: ../../
3
- specs:
4
- omniauth-launchpad (0.0.1)
5
- multi_json (~> 1.3)
6
- omniauth (>= 1.1.1)
7
- omniauth-oauth (>= 1.0.1)
8
-
9
- GEM
10
- remote: http://rubygems.org/
11
- specs:
12
- hashie (3.4.1)
13
- multi_json (1.11.0)
14
- oauth (0.4.7)
15
- omniauth (1.2.2)
16
- hashie (>= 1.2, < 4)
17
- rack (~> 1.0)
18
- omniauth-oauth (1.0.1)
19
- oauth
20
- omniauth (~> 1.0)
21
- rack (1.6.0)
22
- rack-protection (1.5.3)
23
- rack
24
- sinatra (1.4.6)
25
- rack (~> 1.4)
26
- rack-protection (~> 1.4)
27
- tilt (>= 1.3, < 3)
28
- tilt (2.0.1)
29
-
30
- PLATFORMS
31
- ruby
32
-
33
- DEPENDENCIES
34
- omniauth
35
- omniauth-launchpad!
36
- sinatra
@@ -1,43 +0,0 @@
1
- require 'bundler/setup'
2
- require 'sinatra/base'
3
- require 'omniauth'
4
- require 'launchpad'
5
-
6
-
7
-
8
- class App < Sinatra::Base
9
-
10
- get '/' do
11
- redirect '/auth/launchpad'
12
- end
13
- # Support both GET and POST for callbacks
14
- %w(get post).each do |method|
15
- send(method, "/auth/:provider/callback") do
16
- # Everything you care about is in env['omniauth.auth']
17
- # You'll probably want to keep track of your credential hash somewhere.
18
- # Loading it into a client object should be easy:
19
- # client.authorization.update_token!(credential_hash)
20
- content_type 'application/json'
21
- MultiJson.encode(request.env)
22
- end
23
- end
24
- get '/auth/failure' do
25
- content_type 'application/json'
26
- MultiJson.encode(request.env)
27
- end
28
- end
29
-
30
- use Rack::Session::Cookie
31
-
32
- use OmniAuth::Builder do
33
- provider :launchpad,
34
- ENV['CLIENT_ID'],
35
- ENV['CLIENT_SECRET'],
36
- :scope => [
37
- 'https://www.googleapis.com/auth/userinfo.profile',
38
- 'https://www.googleapis.com/auth/plus.me'
39
- ],
40
- :skip_info => false
41
- end
42
-
43
- run App.new