omniauth-fidor 0.0.0 → 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,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- M2YyNzhiNzYzOGNiMWIyZjFlY2Y0MThmMmU3ZDlkNGRmZTk4MTcxNg==
4
+ MWFjN2E3ZDkyNTg0ODUxYzIzNGNiYmZjMjcyYjk5Mzg4YmE0MWYxMw==
5
5
  data.tar.gz: !binary |-
6
- NGQ4M2IxZDk3ZDNlYWRlOGE3ZGEwMWMxMzQzNWI4MGNkOTZkNjI4ZA==
6
+ ZGJhYTQ2NTdiYWY2NjJiY2ZiMWVkNTI0Yzg2NDEyMTZiYWVkOThiMw==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- ZjY5NmM0ZTYzN2E2ODdmN2NkNWU3ZmUzOTE5MGIzOWZhM2U4YWNhODZiNzU1
10
- YmFjODA0NWYyZWJhMDc4OWIxZjMyNWYzYzQ5NGUzNzYyZTVhZmI5YzUyNmM1
11
- Zjk0MzI4NWViMWFjYjI1YWYwZDgxYmFjM2QzZGExMzMxMTliODU=
9
+ NDJlOGJkMDEyZWFkZTQyMmI3MWQwZDI2OTk2ZDVkNDZkOTdkODE4ZTY1N2E5
10
+ MWU2OGRiNTcyNWI5YTk0NjBlMzcxYzkwYmQ0YjhhMjU1YzEzMTY3OGJiY2M4
11
+ YWU4MmJiMDQ3YzJlZTJkYmMxMWQ5N2Q0OTQ4YTUxNDdhY2Q1YzM=
12
12
  data.tar.gz: !binary |-
13
- OTU2MjAzMTU1MmI1MDhiMDdmMDhiMDk1ZGVhOTZmZWRiMzE3MzE1ZjNmMDJk
14
- NjljZGMyODE0Nzk5MDY0NGJlOTkxNGFjMDcxYjE0NmJlNjE3YWUzZWRiMTRk
15
- NTAzM2FlMDVmMjJiNmRjYTlhZDEzMzBmNGMzZDI2NzNiNjkwYmM=
13
+ ZjI0NzEyOTUyM2NlNWM0M2M1OGQyNTI2MzYwMTc1Njc1MTM4NjlhOWE0ZmFk
14
+ MWRlNzFmMWRlZTkyYjNjMzcyYjRlYzk4NzNiMTcyZDcxYmE2ZDM4ZmFjMWY1
15
+ MDlkMTMyMmEwOTIxNzA0ZmQwYzI4YWQ1NmNiZjU5N2I5ZjRhMDU=
data/CHANGELOG CHANGED
@@ -1 +1,4 @@
1
+ v0.1.0
2
+ - Introduces staging/production flag for builder
3
+ - Fixes bug with requesting user info by adding required request headers
1
4
  v0.0.0 Initial version.
data/Manifest CHANGED
@@ -4,10 +4,8 @@ Manifest
4
4
  README.md
5
5
  Rakefile
6
6
  lib/omniauth-fidor.rb
7
- lib/omniauth/fidor/config.rb
8
7
  lib/omniauth/fidor/version.rb
9
8
  lib/omniauth/strategies/fidor.rb
10
9
  test/helper.rb
11
- test/omniauth/fidor/config_test.rb
12
10
  test/omniauth/fidor/version_test.rb
13
11
  test/omniauth/strategies/fidor_test.rb
data/README.md CHANGED
@@ -47,8 +47,18 @@ new version, update the version number in the `CHANGELOG`, and then run `rake
47
47
  release`, which will create a git tag for the version, push git commits and
48
48
  tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
49
49
 
50
- You can also override the API and OAuth URLs used by setting values for the
51
- `FIDOR_API_URL` and/or `FIDOR_OAUTH_URL` environment variables.
50
+ You can also use the sandbox versions of the API and OAuth URLs for testing by
51
+ passing an optional fourth parameter to the builder:
52
+
53
+ ```ruby
54
+ use OmniAuth::Builder do
55
+ provider :fidor, ENV['FIDOR_KEY'], ENV['FIDOR_SECRET'], false
56
+ end
57
+ ```
58
+
59
+ If you need to use endpoints that differ from Fidor's production or sandbox
60
+ environments, you can override them by setting the `FIDOR_API_URL` and/or
61
+ `FIDOR_OAUTH_URL` environment variables.
52
62
 
53
63
  ## Contributing
54
64
 
@@ -1,32 +1,24 @@
1
1
  require 'omniauth-oauth2'
2
- require 'omniauth/fidor/config'
3
2
 
4
3
  module OmniAuth
5
4
  module Strategies
6
5
  class Fidor < OmniAuth::Strategies::OAuth2
7
- option :authorize_options, [:authorization_code]
6
+ FIDOR_API_HEADERS = {
7
+ :headers => {
8
+ 'Accept' => 'application/vnd.fidor.de; version=1,text/json',
9
+ 'Content-Type' => 'application/json',
10
+ },
11
+ }.freeze
12
+ FIDOR_API_URL = 'https://api.fidor.de'
13
+ FIDOR_SANDBOX_URL = 'https://aps.fidor.de'
14
+ FIDOR_OAUTH_URL = 'https://apm.fidor.de'
8
15
 
9
- option :client_options, {
10
- :authorize_url => OmniAuth::Fidor::Config.authorize_url,
11
- :site => OmniAuth::Fidor::Config.site,
12
- :token_url => OmniAuth::Fidor::Config.token_url,
13
- }
14
-
15
- option :scope, ['user']
16
-
17
- def request_phase
18
- super
19
- end
16
+ args [:client_id, :client_secret, :production?]
20
17
 
21
- def authorize_params
22
- super.tap do |params|
23
- %w[client_options scopes].each do |v|
24
- if request.params[v]
25
- params[v.to_sym] = request.params[v]
26
- end
27
- end
28
- end
29
- end
18
+ option :production?, true
19
+ option :token_params, {
20
+ grant_type: 'authorization_code',
21
+ }
30
22
 
31
23
  uid { raw_info['id'].to_s }
32
24
 
@@ -43,14 +35,58 @@ module OmniAuth
43
35
  {:raw_info => raw_info}
44
36
  end
45
37
 
38
+ def build_access_token
39
+ verifier = request.params["code"]
40
+ client.auth_code.get_token(verifier, {:client_id => client.id, :redirect_uri => callback_url}.merge(token_params.to_hash(:symbolize_keys => true)))
41
+ end
42
+
43
+ def client
44
+ options.client_options.authorize_url = build_oauth_url('/oauth/authorize')
45
+ options.client_options.site = build_api_url
46
+ options.client_options.token_url = build_oauth_url('/oauth/token')
47
+
48
+ super
49
+ end
50
+
51
+ def authorize_params
52
+ super.tap do |params|
53
+ %w[client_options scopes].each do |v|
54
+ if request.params[v]
55
+ params[v.to_sym] = request.params[v]
56
+ end
57
+ end
58
+ end
59
+ end
60
+
46
61
  def raw_info
47
- access_token.options[:mode] = :query
48
- @raw_info ||= access_token.get('users/current').parsed
62
+ @raw_info ||= access_token.get('users/current', FIDOR_API_HEADERS).parsed
49
63
  end
50
64
 
51
65
  def email
52
66
  raw_info['email']
53
67
  end
68
+
69
+ private
70
+
71
+ def build_api_url
72
+ if ENV['FIDOR_API_URL']
73
+ ENV['FIDOR_API_URL']
74
+ elsif options.production?
75
+ FIDOR_API_URL
76
+ else
77
+ FIDOR_SANDBOX_URL
78
+ end + '/'
79
+ end
80
+
81
+ def build_oauth_url(path)
82
+ if ENV['FIDOR_OAUTH_URL']
83
+ ENV['FIDOR_OAUTH_URL']
84
+ elsif options.production?
85
+ FIDOR_OAUTH_URL
86
+ else
87
+ FIDOR_SANDBOX_URL
88
+ end + path
89
+ end
54
90
  end
55
91
  end
56
92
  end
@@ -1,51 +1,51 @@
1
1
  # -*- encoding: utf-8 -*-
2
- # stub: omniauth-fidor 0.0.0 ruby lib
2
+ # stub: omniauth-fidor 0.1.0 ruby lib
3
3
 
4
4
  Gem::Specification.new do |s|
5
- s.name = "omniauth-fidor"
6
- s.version = "0.0.0"
5
+ s.name = "omniauth-fidor".freeze
6
+ s.version = "0.1.0"
7
7
 
8
- s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
9
- s.require_paths = ["lib"]
10
- s.authors = ["Sasha Gerrand"]
11
- s.date = "2016-04-17"
12
- s.description = "An OmniAuth OAuth2 based strategy for the Fidor Banking API."
13
- s.email = "rubygems-omniauth-fidor@sgerrand.com"
14
- s.extra_rdoc_files = ["CHANGELOG", "LICENSE.txt", "README.md", "lib/omniauth-fidor.rb", "lib/omniauth/fidor/config.rb", "lib/omniauth/fidor/version.rb", "lib/omniauth/strategies/fidor.rb"]
15
- s.files = ["CHANGELOG", "LICENSE.txt", "Manifest", "README.md", "Rakefile", "lib/omniauth-fidor.rb", "lib/omniauth/fidor/config.rb", "lib/omniauth/fidor/version.rb", "lib/omniauth/strategies/fidor.rb", "omniauth-fidor.gemspec", "test/helper.rb", "test/omniauth/fidor/config_test.rb", "test/omniauth/fidor/version_test.rb", "test/omniauth/strategies/fidor_test.rb"]
16
- s.homepage = "https://github.com/sgerrand/omniauth-fidor"
17
- s.licenses = ["MIT"]
18
- s.rdoc_options = ["--line-numbers", "--title", "Omniauth-fidor", "--main", "README.md"]
19
- s.required_ruby_version = Gem::Requirement.new(">= 2.0")
20
- s.rubyforge_project = "omniauth-fidor"
21
- s.rubygems_version = "2.4.5"
22
- s.summary = "OmniAuth strategy for the Fidor Banking API."
23
- s.test_files = ["test/omniauth/fidor/config_test.rb", "test/omniauth/fidor/version_test.rb", "test/omniauth/strategies/fidor_test.rb"]
8
+ s.required_rubygems_version = Gem::Requirement.new(">= 1.2".freeze) if s.respond_to? :required_rubygems_version=
9
+ s.require_paths = ["lib".freeze]
10
+ s.authors = ["Sasha Gerrand".freeze]
11
+ s.date = "2016-04-19"
12
+ s.description = "An OmniAuth OAuth2 based strategy for the Fidor Banking API.".freeze
13
+ s.email = "rubygems-omniauth-fidor@sgerrand.com".freeze
14
+ s.extra_rdoc_files = ["CHANGELOG".freeze, "LICENSE.txt".freeze, "README.md".freeze, "lib/omniauth-fidor.rb".freeze, "lib/omniauth/fidor/version.rb".freeze, "lib/omniauth/strategies/fidor.rb".freeze]
15
+ s.files = ["CHANGELOG".freeze, "LICENSE.txt".freeze, "Manifest".freeze, "README.md".freeze, "Rakefile".freeze, "lib/omniauth-fidor.rb".freeze, "lib/omniauth/fidor/version.rb".freeze, "lib/omniauth/strategies/fidor.rb".freeze, "omniauth-fidor.gemspec".freeze, "test/helper.rb".freeze, "test/omniauth/fidor/version_test.rb".freeze, "test/omniauth/strategies/fidor_test.rb".freeze]
16
+ s.homepage = "https://github.com/sgerrand/omniauth-fidor".freeze
17
+ s.licenses = ["MIT".freeze]
18
+ s.rdoc_options = ["--line-numbers".freeze, "--title".freeze, "Omniauth-fidor".freeze, "--main".freeze, "README.md".freeze]
19
+ s.required_ruby_version = Gem::Requirement.new(">= 2.0".freeze)
20
+ s.rubyforge_project = "omniauth-fidor".freeze
21
+ s.rubygems_version = "2.6.3".freeze
22
+ s.summary = "OmniAuth strategy for the Fidor Banking API.".freeze
23
+ s.test_files = ["test/omniauth/fidor/version_test.rb".freeze, "test/omniauth/strategies/fidor_test.rb".freeze]
24
24
 
25
25
  if s.respond_to? :specification_version then
26
26
  s.specification_version = 4
27
27
 
28
28
  if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
29
- s.add_runtime_dependency(%q<omniauth>, ["~> 1.0"])
30
- s.add_runtime_dependency(%q<omniauth-oauth2>, ["~> 1.3.1"])
31
- s.add_development_dependency(%q<bundler>, ["~> 1.11"])
32
- s.add_development_dependency(%q<codeclimate-test-reporter>, [">= 0"])
33
- s.add_development_dependency(%q<rake>, ["~> 10.0"])
34
- s.add_development_dependency(%q<minitest>, ["~> 5.0"])
29
+ s.add_runtime_dependency(%q<omniauth>.freeze, ["~> 1.0"])
30
+ s.add_runtime_dependency(%q<omniauth-oauth2>.freeze, ["~> 1.3.1"])
31
+ s.add_development_dependency(%q<bundler>.freeze, ["~> 1.11"])
32
+ s.add_development_dependency(%q<codeclimate-test-reporter>.freeze, [">= 0"])
33
+ s.add_development_dependency(%q<rake>.freeze, ["~> 10.0"])
34
+ s.add_development_dependency(%q<minitest>.freeze, ["~> 5.0"])
35
35
  else
36
- s.add_dependency(%q<omniauth>, ["~> 1.0"])
37
- s.add_dependency(%q<omniauth-oauth2>, ["~> 1.3.1"])
38
- s.add_dependency(%q<bundler>, ["~> 1.11"])
39
- s.add_dependency(%q<codeclimate-test-reporter>, [">= 0"])
40
- s.add_dependency(%q<rake>, ["~> 10.0"])
41
- s.add_dependency(%q<minitest>, ["~> 5.0"])
36
+ s.add_dependency(%q<omniauth>.freeze, ["~> 1.0"])
37
+ s.add_dependency(%q<omniauth-oauth2>.freeze, ["~> 1.3.1"])
38
+ s.add_dependency(%q<bundler>.freeze, ["~> 1.11"])
39
+ s.add_dependency(%q<codeclimate-test-reporter>.freeze, [">= 0"])
40
+ s.add_dependency(%q<rake>.freeze, ["~> 10.0"])
41
+ s.add_dependency(%q<minitest>.freeze, ["~> 5.0"])
42
42
  end
43
43
  else
44
- s.add_dependency(%q<omniauth>, ["~> 1.0"])
45
- s.add_dependency(%q<omniauth-oauth2>, ["~> 1.3.1"])
46
- s.add_dependency(%q<bundler>, ["~> 1.11"])
47
- s.add_dependency(%q<codeclimate-test-reporter>, [">= 0"])
48
- s.add_dependency(%q<rake>, ["~> 10.0"])
49
- s.add_dependency(%q<minitest>, ["~> 5.0"])
44
+ s.add_dependency(%q<omniauth>.freeze, ["~> 1.0"])
45
+ s.add_dependency(%q<omniauth-oauth2>.freeze, ["~> 1.3.1"])
46
+ s.add_dependency(%q<bundler>.freeze, ["~> 1.11"])
47
+ s.add_dependency(%q<codeclimate-test-reporter>.freeze, [">= 0"])
48
+ s.add_dependency(%q<rake>.freeze, ["~> 10.0"])
49
+ s.add_dependency(%q<minitest>.freeze, ["~> 5.0"])
50
50
  end
51
51
  end
@@ -4,7 +4,7 @@ class OmniAuth::Strategies::FidorTest < Minitest::Test
4
4
  def setup
5
5
  app = lambda { |_env| [404, {}, ['Awesome']] }
6
6
  @subject = OmniAuth::Strategies::Fidor.new(app)
7
- OmniAuth.config.test_mode = true
7
+ @sandbox = OmniAuth::Strategies::Fidor.new(app, '', '', false)
8
8
  end
9
9
 
10
10
  def teardown
@@ -19,15 +19,53 @@ class OmniAuth::Strategies::FidorTest < Minitest::Test
19
19
  refute @subject.options.provider_ignores_state
20
20
  end
21
21
 
22
- def test_client_options_has_correct_site
23
- assert_equal 'https://api.fidor.de/', @subject.options.client_options.site
22
+ def test_client_options_has_correct_production_authorize_url
23
+ assert_equal 'https://apm.fidor.de/oauth/authorize', @subject.client.authorize_url
24
24
  end
25
25
 
26
- def test_client_options_has_correct_authorize_url
27
- assert_equal 'https://apm.fidor.de/oauth/authorize', @subject.options.client_options.authorize_url
26
+ def test_client_options_has_correct_staging_authorize_url
27
+ assert_equal 'https://aps.fidor.de/oauth/authorize', @sandbox.client.authorize_url
28
28
  end
29
29
 
30
- def test_client_options_has_correct_token_url
31
- assert_equal 'https://apm.fidor.de/oauth/token', @subject.options.client_options.token_url
30
+ def test_client_options_environment_variable_overrides_authorize_url
31
+ around_env_url('FIDOR_OAUTH_URL', 'proto://another.url') do
32
+ assert_equal 'proto://another.url/oauth/authorize', @sandbox.client.authorize_url
33
+ end
34
+ end
35
+
36
+ def test_client_options_has_correct_production_site_url
37
+ assert_equal 'https://api.fidor.de/', @subject.client.site
38
+ end
39
+
40
+ def test_client_options_has_correct_staging_site_url
41
+ assert_equal 'https://aps.fidor.de/', @sandbox.client.site
42
+ end
43
+
44
+ def test_client_options_environment_variable_overrides_site_url
45
+ around_env_url('FIDOR_API_URL', 'proto://another.url') do
46
+ assert_equal 'proto://another.url/', @sandbox.client.site
47
+ end
48
+ end
49
+
50
+ def test_client_options_has_correct_production_token_url
51
+ assert_equal 'https://apm.fidor.de/oauth/token', @subject.client.token_url
52
+ end
53
+
54
+ def test_client_options_has_correct_staging_token_url
55
+ assert_equal 'https://aps.fidor.de/oauth/token', @sandbox.client.token_url
56
+ end
57
+
58
+ def test_client_options_environment_variable_overrides_token_url
59
+ around_env_url('FIDOR_OAUTH_URL', 'proto://another.url') do
60
+ assert_equal 'proto://another.url/oauth/token', @sandbox.client.token_url
61
+ end
62
+ end
63
+
64
+ private
65
+
66
+ def around_env_url(env_key, url, &block)
67
+ ENV[env_key] = url
68
+ yield block.call
69
+ ENV[env_key] = nil
32
70
  end
33
71
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: omniauth-fidor
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.0
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sasha Gerrand
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-04-17 00:00:00.000000000 Z
11
+ date: 2016-04-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: omniauth
@@ -103,7 +103,6 @@ extra_rdoc_files:
103
103
  - LICENSE.txt
104
104
  - README.md
105
105
  - lib/omniauth-fidor.rb
106
- - lib/omniauth/fidor/config.rb
107
106
  - lib/omniauth/fidor/version.rb
108
107
  - lib/omniauth/strategies/fidor.rb
109
108
  files:
@@ -113,12 +112,10 @@ files:
113
112
  - README.md
114
113
  - Rakefile
115
114
  - lib/omniauth-fidor.rb
116
- - lib/omniauth/fidor/config.rb
117
115
  - lib/omniauth/fidor/version.rb
118
116
  - lib/omniauth/strategies/fidor.rb
119
117
  - omniauth-fidor.gemspec
120
118
  - test/helper.rb
121
- - test/omniauth/fidor/config_test.rb
122
119
  - test/omniauth/fidor/version_test.rb
123
120
  - test/omniauth/strategies/fidor_test.rb
124
121
  homepage: https://github.com/sgerrand/omniauth-fidor
@@ -151,6 +148,5 @@ signing_key:
151
148
  specification_version: 4
152
149
  summary: OmniAuth strategy for the Fidor Banking API.
153
150
  test_files:
154
- - test/omniauth/fidor/config_test.rb
155
151
  - test/omniauth/fidor/version_test.rb
156
152
  - test/omniauth/strategies/fidor_test.rb
@@ -1,31 +0,0 @@
1
- require 'uri'
2
-
3
- module OmniAuth
4
- module Fidor
5
- class Config
6
- class << self
7
- def authorize_url
8
- oauth_url + '/oauth/authorize'
9
- end
10
-
11
- def site
12
- api_url + '/'
13
- end
14
-
15
- def token_url
16
- oauth_url + '/oauth/token'
17
- end
18
-
19
- private
20
-
21
- def api_url
22
- ENV['FIDOR_API_URL'] || 'https://api.fidor.de'
23
- end
24
-
25
- def oauth_url
26
- ENV['FIDOR_OAUTH_URL'] || 'https://apm.fidor.de'
27
- end
28
- end
29
- end
30
- end
31
- end
@@ -1,59 +0,0 @@
1
- require 'helper'
2
-
3
- class OmniAuth::Fidor::ConfigTest < Minitest::Test
4
- def test_that_it_has_a_authorize_url
5
- refute_nil ::OmniAuth::Fidor::Config.authorize_url
6
- end
7
-
8
- def test_default_value_for_authorize_url
9
- assert_equal 'https://apm.fidor.de/oauth/authorize',
10
- ::OmniAuth::Fidor::Config.authorize_url
11
- end
12
-
13
- def test_override_value_for_authorize_url
14
- around_env_url('FIDOR_OAUTH_URL', 'https://another.url') do
15
- assert_equal 'https://another.url/oauth/authorize',
16
- ::OmniAuth::Fidor::Config.authorize_url
17
- end
18
- end
19
-
20
- def test_that_it_has_a_site
21
- refute_nil ::OmniAuth::Fidor::Config.site
22
- end
23
-
24
- def test_default_value_for_site
25
- assert_equal 'https://api.fidor.de/',
26
- ::OmniAuth::Fidor::Config.site
27
- end
28
-
29
- def test_override_value_for_site
30
- around_env_url('FIDOR_API_URL', 'https://another.url') do
31
- assert_equal 'https://another.url/',
32
- ::OmniAuth::Fidor::Config.site
33
- end
34
- end
35
-
36
- def test_that_it_has_a_token_url
37
- refute_nil ::OmniAuth::Fidor::Config.token_url
38
- end
39
-
40
- def test_default_value_for_token_url
41
- assert_equal 'https://apm.fidor.de/oauth/token',
42
- ::OmniAuth::Fidor::Config.token_url
43
- end
44
-
45
- def test_override_value_for_token_url
46
- around_env_url('FIDOR_OAUTH_URL', 'https://another.url') do
47
- assert_equal 'https://another.url/oauth/token',
48
- ::OmniAuth::Fidor::Config.token_url
49
- end
50
- end
51
-
52
- private
53
-
54
- def around_env_url(env_key, url, &block)
55
- ENV[env_key] = url
56
- yield block.call
57
- ENV[env_key] = nil
58
- end
59
- end