omniauth-idcat_mobil 0.1.1 → 0.2.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 9691f8a5ce128b45dbd3cc8b48e979dd6a2e25d6d331b858a03cc46011f05aa2
4
- data.tar.gz: cd7b6247e1a629290a7474a655f1611b82e439fc156bc8e4571fa43376dcc581
3
+ metadata.gz: b2c510f98cc25863f8f7d1e8c4fa698993a71438f948d6f1cd039c3535ce735f
4
+ data.tar.gz: b743977b94da58395d324f3df3c8ed6b82ea14f3098836d162c9d0b42cec366b
5
5
  SHA512:
6
- metadata.gz: 7e436a5c9f6c65dde4a01fdf73e298c86dd42c1b41fe0155d15559cc8f8a8a97eed6e5ee9c029636585b1888e881183b43ffaaa3f321a0ec8a73ad8869caee66
7
- data.tar.gz: 05be1b35950d897ba8da644b973dbcf1652af4c4f3a64f5f123bced185a8433b2059ff5bedd956db69649760d4985037bb22d9bbec8dfe8ba76911cc333a3617
6
+ metadata.gz: ddc16470b5a9b7f4298d773568dbbbae3584d85aec130fe9728883da4ef9c8b36eb239aafcd3b841d8d428a200896fcaee1b5e73447ac6a5325d89bac94718dd
7
+ data.tar.gz: 15b24d49ae852316ea14be9d5c546035e2943b9b1cf87d3f1127f7b81f16f8976aa31bef02c03b9f6ab9019d7bc36bf41de31a93a1a888d5fcbf7c69fbe83307
data/.gitignore CHANGED
@@ -6,3 +6,4 @@
6
6
  /pkg/
7
7
  /spec/reports/
8
8
  /tmp/
9
+ Gemfile.lock
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ 2.7.5
data/CHANGELOG.md CHANGED
@@ -2,5 +2,20 @@
2
2
 
3
3
  ## next version:
4
4
 
5
+ ## Version 0.2.3 (PATCH)
6
+ - FIX: do not delete the session state before checking it.
7
+ - DOC: Correct mispelling in README
8
+
9
+ ## Version 0.2.2 (PATCH)
10
+ - FIX: Fix internal `log` method is wrongly invoked from `omniauth`.
11
+ - Bump Ruby version to 2.7.5
12
+
13
+ ## Version 0.2.1 (PATCH)
14
+ - Apply security upgrades
15
+ - Add a .ruby-version file
16
+
17
+ ## Version 0.2.0 (MINOR)
18
+ - Remove Gemfile.lock to avoid forcing the versioning of apps using this gem.
19
+
5
20
  ## Version 0.1.1 (PATCH)
6
21
  - [REFACTOR] Remove one declaration of info email field which was setted twice. \#[3](https://github.com/gencat/omniauth-idcat_mobil/pull/3)
data/Gemfile CHANGED
@@ -6,7 +6,7 @@ git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
6
6
  gemspec
7
7
 
8
8
  group :test do
9
- gem "rack", ">= 1.6.2"
9
+ gem "rack", ">= 2.1.4"
10
10
  gem "rack-test"
11
11
  gem "rspec", "~> 3.0"
12
12
  end
data/README.md CHANGED
@@ -39,7 +39,25 @@ end
39
39
 
40
40
  `omniauth-idcat_mobil` is a standard OAuth2 strategy. It is based on `omniauth-oauth2` that is just an `omniauth` extension. Thus, you can also integrate it using [`omniauth` integrating guide](https://github.com/omniauth/omniauth).
41
41
 
42
- ## Incon assets
42
+ ## Request/callback workflow
43
+
44
+ This is a quasi standard omniauth Strategy. It is not 100% standard because the standard is to have two phases. A +request_phase+, where our client application delegates the user authentication to the authentication provider (IdCat mòbil in this case), and a +callback_phase+, where the authentication provider invokes our application back with the result of the authentication and we negotiate the final access_token.
45
+ For IdCat mòbil we still need to perform an extra step during the +callback_phase+ to fetch users' data.
46
+
47
+ ### request_phase
48
+
49
+ `omniauth-idcat_mobil` does not implement this method, instead we rely in the default implementation in `OmniAuth::Strategies::OAuth2`.
50
+ It simply redirects the user to the authentiction provider to authenticate.
51
+ When users finish with the authentication workflow in IdCat mòbil, this authentication provider redirects them to our `callback_phase`.
52
+
53
+ ### callback_phase
54
+
55
+ This phase starts by checking the result of the authentication in the provider's site.
56
+ When users get authenticated, we still need to negotiate the access_token that we will need to perform extra requests to the provider system.
57
+ The access_token is obtained by performing a POST request to the provider. If this succeeds then we're ready to go and perform te `getUserInfo` request. This request is implemented in the `raw_info` method.
58
+ After a successful `getUserInfo` the superclass of this strategy fills the `info` so that our host application can access it and finishes with its authentication task.
59
+
60
+ ## Icon assets
43
61
  We're including _IdCat mòbil_ icons in lib/decidim/idcat_mobil for the joy of the developer. They can be used to complement the OAuth2 button or alike.
44
62
 
45
63
  ## Development
@@ -1,5 +1,5 @@
1
1
  module Omniauth
2
2
  module IdCatMobil
3
- VERSION = "0.1.1"
3
+ VERSION = "0.2.3"
4
4
  end
5
5
  end
@@ -12,7 +12,7 @@ module OmniAuth
12
12
  # IdCat mòbil references:
13
13
  # - https://www.aoc.cat/wp-content/uploads/2016/01/di-valid-1.pdf
14
14
  class IdCatMobil < OmniAuth::Strategies::OAuth2
15
- # constructor arguments after `app` the first argument that should be a RackApp
15
+ # constructor arguments after `app`, the first argument, that should be a RackApp
16
16
  args [:client_id, :client_secret, :site]
17
17
 
18
18
  option :name, :idcat_mobil
@@ -70,9 +70,37 @@ module OmniAuth
70
70
  super
71
71
  end
72
72
 
73
+ # The +request_phase+ is the first phase after the setup/initialization phase.
74
+ #
75
+ # It is implemented in the OAuth2 superclass, and does the follwing:
76
+ # redirect client.auth_code.authorize_url({:redirect_uri => callback_url}.merge(options.authorize_params))
77
+ #
78
+ # We're overriding solely to log.
79
+ def request_phase
80
+ idcat_log("In `request_phase`, with params: redirect_uri=>#{callback_url}, options=>#{options.authorize_params}")
81
+ idcat_log("`request_phase`, redirecting the user to AOC...")
82
+ super
83
+ end
84
+
85
+ # The +callback_phase+ is the second phase, after the user returns from the authentication provider site.
86
+ #
87
+ # The result of the authentication may have ended in error, or success.
88
+ # In case of success we still have to ask the authentication provider for the access_token.
89
+ # That's what we do in this callback.
90
+ def callback_phase
91
+ idcat_log("In `callback_phase` with request params: #{request.params}")
92
+ idcat_log("Both should be equal otherwise a 'CSRF detected' error is raised: params state[#{request.params["state"]}] =? [#{session["omniauth.state"]}] session state.")
93
+ super
94
+ end
95
+
73
96
  def raw_info
97
+ idcat_log("Access token response was: #{access_token.response}")
98
+ idcat_log("Performing getUserInfo...")
74
99
  unless @raw_info
75
- @raw_info= access_token.get(options.user_info_path).parsed
100
+ response= access_token.get(options.user_info_path)
101
+ result= %i(status headers body).collect {|m| response.send(m)}
102
+ idcat_log("getUserInfo response status/headers/body: #{result}")
103
+ @raw_info= response.parsed
76
104
  # Logout to avoid problems with IdCat mòbil's cookie session when trying to login again.
77
105
  logout_url= URI.join(options.site, "/o/oauth2/logout?token=#{access_token.token}").to_s
78
106
  access_token.get(logout_url)
@@ -80,10 +108,23 @@ module OmniAuth
80
108
  @raw_info
81
109
  end
82
110
 
111
+ # The url where the provider should redirect the users to after authenticating.
83
112
  # https://github.com/intridea/omniauth-oauth2/issues/81
84
113
  def callback_url
85
114
  full_host + script_name + callback_path
86
115
  end
116
+
117
+ # --------------------------------------------------
118
+ private
119
+ # --------------------------------------------------
120
+
121
+ def idcat_log(msg)
122
+ idcat_logger.debug(msg)
123
+ end
124
+
125
+ def idcat_logger
126
+ @idcat_logger||= defined?(Rails.logger) ? Rails.logger : Logger.new(STDOUT, progname: 'idcat_mobil')
127
+ end
87
128
  end
88
129
  end
89
130
  end
@@ -25,6 +25,6 @@ Gem::Specification.new do |spec|
25
25
 
26
26
  spec.add_dependency "omniauth", "~> 1.5"
27
27
  spec.add_dependency "omniauth-oauth2", ">= 1.4.0", "< 2.0"
28
- spec.add_development_dependency "bundler", "~> 1.16"
29
- spec.add_development_dependency "rake", "~> 10.0"
28
+ spec.add_development_dependency "bundler", "~> 2.2", ">= 2.2.10"
29
+ spec.add_development_dependency "rake", "~> 12.3", ">= 12.3.3"
30
30
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: omniauth-idcat_mobil
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.2.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Oliver Valls
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-01-28 00:00:00.000000000 Z
11
+ date: 2022-01-31 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: omniauth
@@ -50,28 +50,40 @@ dependencies:
50
50
  requirements:
51
51
  - - "~>"
52
52
  - !ruby/object:Gem::Version
53
- version: '1.16'
53
+ version: '2.2'
54
+ - - ">="
55
+ - !ruby/object:Gem::Version
56
+ version: 2.2.10
54
57
  type: :development
55
58
  prerelease: false
56
59
  version_requirements: !ruby/object:Gem::Requirement
57
60
  requirements:
58
61
  - - "~>"
59
62
  - !ruby/object:Gem::Version
60
- version: '1.16'
63
+ version: '2.2'
64
+ - - ">="
65
+ - !ruby/object:Gem::Version
66
+ version: 2.2.10
61
67
  - !ruby/object:Gem::Dependency
62
68
  name: rake
63
69
  requirement: !ruby/object:Gem::Requirement
64
70
  requirements:
65
71
  - - "~>"
66
72
  - !ruby/object:Gem::Version
67
- version: '10.0'
73
+ version: '12.3'
74
+ - - ">="
75
+ - !ruby/object:Gem::Version
76
+ version: 12.3.3
68
77
  type: :development
69
78
  prerelease: false
70
79
  version_requirements: !ruby/object:Gem::Requirement
71
80
  requirements:
72
81
  - - "~>"
73
82
  - !ruby/object:Gem::Version
74
- version: '10.0'
83
+ version: '12.3'
84
+ - - ">="
85
+ - !ruby/object:Gem::Version
86
+ version: 12.3.3
75
87
  description: Authentication method that uses OAuth 2.0 protocol.
76
88
  email:
77
89
  - oliver.vh@coditramuntana.com
@@ -80,11 +92,10 @@ extensions: []
80
92
  extra_rdoc_files: []
81
93
  files:
82
94
  - ".gitignore"
83
- - ".travis.yml"
95
+ - ".ruby-version"
84
96
  - CHANGELOG.md
85
97
  - CODE_OF_CONDUCT.md
86
98
  - Gemfile
87
- - Gemfile.lock
88
99
  - LICENSE
89
100
  - LICENSE.txt
90
101
  - README.md
@@ -116,8 +127,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
116
127
  - !ruby/object:Gem::Version
117
128
  version: '0'
118
129
  requirements: []
119
- rubyforge_project:
120
- rubygems_version: 2.7.6
130
+ rubygems_version: 3.1.6
121
131
  signing_key:
122
132
  specification_version: 4
123
133
  summary: User registration and login through IdCat mòbil.
data/.travis.yml DELETED
@@ -1,7 +0,0 @@
1
- ---
2
- sudo: false
3
- language: ruby
4
- cache: bundler
5
- rvm:
6
- - 2.5.1
7
- before_install: gem install bundler -v 1.16.4
data/Gemfile.lock DELETED
@@ -1,61 +0,0 @@
1
- PATH
2
- remote: .
3
- specs:
4
- omniauth-idcat_mobil (0.1.1)
5
- omniauth (~> 1.5)
6
- omniauth-oauth2 (>= 1.4.0, < 2.0)
7
-
8
- GEM
9
- remote: https://rubygems.org/
10
- specs:
11
- diff-lcs (1.3)
12
- faraday (0.15.4)
13
- multipart-post (>= 1.2, < 3)
14
- hashie (3.5.7)
15
- jwt (2.1.0)
16
- multi_json (1.13.1)
17
- multi_xml (0.6.0)
18
- multipart-post (2.0.0)
19
- oauth2 (1.4.1)
20
- faraday (>= 0.8, < 0.16.0)
21
- jwt (>= 1.0, < 3.0)
22
- multi_json (~> 1.3)
23
- multi_xml (~> 0.5)
24
- rack (>= 1.2, < 3)
25
- omniauth (1.8.1)
26
- hashie (>= 3.4.6, < 3.6.0)
27
- rack (>= 1.6.2, < 3)
28
- omniauth-oauth2 (1.5.0)
29
- oauth2 (~> 1.1)
30
- omniauth (~> 1.2)
31
- rack (2.0.6)
32
- rack-test (1.1.0)
33
- rack (>= 1.0, < 3)
34
- rake (10.4.2)
35
- rspec (3.8.0)
36
- rspec-core (~> 3.8.0)
37
- rspec-expectations (~> 3.8.0)
38
- rspec-mocks (~> 3.8.0)
39
- rspec-core (3.8.0)
40
- rspec-support (~> 3.8.0)
41
- rspec-expectations (3.8.2)
42
- diff-lcs (>= 1.2.0, < 2.0)
43
- rspec-support (~> 3.8.0)
44
- rspec-mocks (3.8.0)
45
- diff-lcs (>= 1.2.0, < 2.0)
46
- rspec-support (~> 3.8.0)
47
- rspec-support (3.8.0)
48
-
49
- PLATFORMS
50
- ruby
51
-
52
- DEPENDENCIES
53
- bundler (~> 1.16)
54
- omniauth-idcat_mobil!
55
- rack (>= 1.6.2)
56
- rack-test
57
- rake (~> 10.0)
58
- rspec (~> 3.0)
59
-
60
- BUNDLED WITH
61
- 1.16.4