omniauth-heroku 0.2.0.pre → 0.2.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,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- M2ZlY2IwZjQ5NmNhN2QyMjRhODI0MGE4MmQ5ODFkNzIxZDZiNThlYg==
4
+ NzQ0NTZiYTZlYTcxNDc0MzYzNDBmM2Y0NmM4M2Q1OTYwYWM2ZjM4NQ==
5
5
  data.tar.gz: !binary |-
6
- MDEyNDQ1MjUzMThjMzQzYjU4NDFmMjQzNjYxYzBkZDVlOTE0OGU4Mw==
7
- !binary "U0hBNTEy":
6
+ YmNiZTI4ZTkzZGMyMTI3YTIxMmE2MTJlNWIxMDZhOGRlY2MyOGY3MQ==
7
+ SHA512:
8
8
  metadata.gz: !binary |-
9
- MDJkMTc0MTBiNTIzZGU4ZDI4Y2YwYWRkOGEwNDJkNWFlYTczNzJiNzJmODRk
10
- YjJjNmNiZTk5NjU0MTNhNWE4ZDcyNTAyZGQwNWJjMGU5NTIzNjI0ZDIwYjVk
11
- YmRjODNlZGZlZDY5YjU1OGQ0ZTAzYWMxMTk2NGNlMGM3Njg4MTU=
9
+ NWFhMDBmNDQwZDZmOTgzNTY2OTIwZjdhNmU5NWYxN2ZiN2YyZDliM2MyMWMx
10
+ Zjg1NzE2ZTI2OGIzZDE0OTRmODQwZTRkMjZmODg3MWRjZTY0YTAyN2UyNzQx
11
+ Zjg0YTQ0Njg4MzJmYjJmNGJmYjdiMDg3ZTk5NTc3YjdkMTgxMmQ=
12
12
  data.tar.gz: !binary |-
13
- NDFiYjc5NzNmMzE0MWZhYWFjYTdlZWE5MDdlM2ViOGU5MDNkNGFiZThjYmQz
14
- NTQ1NjczYzg2MDQ1MjMxNzU0OGIzNGNkMDUzMTMyZDI0ZWI0NGViOWFlNzJi
15
- YzI2NWNiNTViMTAwYzU1ZDBmMzRiYTE3YTc2MzNlMWYyNTQ4MzE=
13
+ NTJhOTBjOTE5ZGQxYjhkMzM4Y2FhNDJiOTgwYzQ3OTIzMTU5MzBhYzk5Y2Q2
14
+ YzVkNDJiNGI0MzVmOWJhY2Q0ZmIwOGMwMGU0MmJmY2FhMjdjOTA5YTNlN2Rm
15
+ NGFiZjk5MDg3OTRmYTNlZDc2OThkMjQzYTFiNDJhYThlODViNDE=
@@ -1,7 +1,7 @@
1
1
  language: ruby
2
2
  rvm:
3
- - 2.1.2
4
- - 2.1.0
3
+ - 2.1.4
4
+ - 2.0.0
5
5
  - 1.9.3
6
6
  cache: bundler
7
7
  notifications:
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Pedro Belo
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.
@@ -44,6 +44,18 @@ module OmniAuth
44
44
  end
45
45
  end
46
46
 
47
+ # override method in OmniAuth::Strategies::OAuth2 to error
48
+ # when we don't have a client_id or secret:
49
+ def request_phase
50
+ if missing_client_id?
51
+ fail!(:missing_client_id)
52
+ elsif missing_client_secret?
53
+ fail!(:missing_client_secret)
54
+ else
55
+ super
56
+ end
57
+ end
58
+
47
59
  def account_info
48
60
  @account_info ||= MultiJson.decode(heroku_api.get("/account").body)
49
61
  end
@@ -56,6 +68,14 @@ module OmniAuth
56
68
  "Authorization" => "Bearer #{access_token.token}",
57
69
  })
58
70
  end
71
+
72
+ def missing_client_id?
73
+ [nil, ""].include?(options.client_id)
74
+ end
75
+
76
+ def missing_client_secret?
77
+ [nil, ""].include?(options.client_secret)
78
+ end
59
79
  end
60
80
  end
61
81
  end
@@ -4,12 +4,13 @@ Gem::Specification.new do |gem|
4
4
  gem.description = %q{OmniAuth strategy for Heroku.}
5
5
  gem.summary = %q{OmniAuth strategy for Heroku.}
6
6
  gem.homepage = "https://github.com/heroku/omniauth-heroku"
7
+ gem.license = "MIT"
7
8
 
8
9
  gem.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
9
10
  gem.files = `git ls-files`.split("\n")
10
11
  gem.name = "omniauth-heroku"
11
12
  gem.require_paths = ["lib"]
12
- gem.version = "0.2.0.pre"
13
+ gem.version = "0.2.0"
13
14
 
14
15
  gem.add_dependency 'omniauth', '~> 1.2'
15
16
  gem.add_dependency 'omniauth-oauth2', '~> 1.2'
@@ -29,12 +29,8 @@ describe OmniAuth::Strategies::Heroku do
29
29
  end
30
30
 
31
31
  it "receives the callback" do
32
- # start the callback, get the session state
33
- get "/auth/heroku"
34
- assert_equal 302, last_response.status
35
- state = last_response.headers["Location"].match(/state=([\w\d]+)/)[1]
36
-
37
32
  # trigger the callback setting the state as a param and in the session
33
+ state = SecureRandom.hex(8)
38
34
  get "/auth/heroku/callback", { "state" => state },
39
35
  { "rack.session" => { "omniauth.state" => state }}
40
36
  assert_equal 200, last_response.status
@@ -58,11 +54,8 @@ describe OmniAuth::Strategies::Heroku do
58
54
  with(headers: { "Authorization" => "Bearer #{@token}" }).
59
55
  to_return(body: MultiJson.encode(account_info))
60
56
 
61
- # do the oauth dance
62
- get "/auth/heroku"
63
- assert_equal 302, last_response.status
64
- state = last_response.headers["Location"].match(/state=([\w\d]+)/)[1]
65
-
57
+ # hit the OAuth callback
58
+ state = SecureRandom.hex(8)
66
59
  get "/auth/heroku/callback", { "state" => state },
67
60
  { "rack.session" => { "omniauth.state" => state }}
68
61
  assert_equal 200, last_response.status
@@ -75,4 +68,22 @@ describe OmniAuth::Strategies::Heroku do
75
68
  assert_equal "John", omniauth_env["info"]["name"]
76
69
  assert_equal account_info, omniauth_env["extra"]
77
70
  end
71
+
72
+ describe "error handling" do
73
+ it "renders an error when client_id is not informed" do
74
+ @app = make_app(client_id: nil)
75
+ get "/auth/heroku"
76
+ assert_equal 302, last_response.status
77
+ redirect = URI.parse(last_response.headers["Location"])
78
+ assert_equal "/auth/failure", redirect.path
79
+ end
80
+
81
+ it "renders an error when client_secret is not informed" do
82
+ @app = make_app(client_secret: "") # should also handle empty strings
83
+ get "/auth/heroku"
84
+ assert_equal 302, last_response.status
85
+ redirect = URI.parse(last_response.headers["Location"])
86
+ assert_equal "/auth/failure", redirect.path
87
+ end
88
+ end
78
89
  end
@@ -28,6 +28,15 @@ RSpec.configure do |config|
28
28
  end
29
29
 
30
30
  def make_app(omniauth_heroku_options={})
31
+ client_id = ENV["HEROKU_OAUTH_ID"]
32
+ client_secret = ENV["HEROKU_OAUTH_SECRET"]
33
+ if omniauth_heroku_options.has_key?(:client_id)
34
+ client_id = omniauth_heroku_options.delete(:client_id)
35
+ end
36
+ if omniauth_heroku_options.has_key?(:client_secret)
37
+ client_secret = omniauth_heroku_options.delete(:client_secret)
38
+ end
39
+
31
40
  Sinatra.new do
32
41
  configure do
33
42
  enable :sessions
@@ -36,8 +45,7 @@ RSpec.configure do |config|
36
45
  end
37
46
 
38
47
  use OmniAuth::Builder do
39
- provider :heroku, ENV["HEROKU_OAUTH_ID"], ENV["HEROKU_OAUTH_SECRET"],
40
- omniauth_heroku_options
48
+ provider :heroku, client_id, client_secret, omniauth_heroku_options
41
49
  end
42
50
 
43
51
  get "/auth/heroku/callback" do
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: omniauth-heroku
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0.pre
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Pedro Belo
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-09-11 00:00:00.000000000 Z
11
+ date: 2014-11-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: omniauth
@@ -49,6 +49,7 @@ files:
49
49
  - .rspec
50
50
  - .travis.yml
51
51
  - Gemfile
52
+ - LICENSE
52
53
  - README.md
53
54
  - Rakefile
54
55
  - lib/omniauth-heroku.rb
@@ -57,7 +58,8 @@ files:
57
58
  - spec/omniauth_heroku_spec.rb
58
59
  - spec/spec_helper.rb
59
60
  homepage: https://github.com/heroku/omniauth-heroku
60
- licenses: []
61
+ licenses:
62
+ - MIT
61
63
  metadata: {}
62
64
  post_install_message:
63
65
  rdoc_options: []
@@ -70,12 +72,12 @@ required_ruby_version: !ruby/object:Gem::Requirement
70
72
  version: '0'
71
73
  required_rubygems_version: !ruby/object:Gem::Requirement
72
74
  requirements:
73
- - - ! '>'
75
+ - - ! '>='
74
76
  - !ruby/object:Gem::Version
75
- version: 1.3.1
77
+ version: '0'
76
78
  requirements: []
77
79
  rubyforge_project:
78
- rubygems_version: 2.0.7
80
+ rubygems_version: 2.2.2
79
81
  signing_key:
80
82
  specification_version: 4
81
83
  summary: OmniAuth strategy for Heroku.