gamora 0.5.0 → 0.6.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 563e700187ac79aef45f7d11aad774aee205f7917870f5431d3f1d6d63d7850b
4
- data.tar.gz: 9817af7d6c4eb85abb6bdaa76d53efc0f1016f6516df95c674366b89ab920b49
3
+ metadata.gz: aa6a4fbbe3e75fdacdc78a5cf6635e0859cc459e4319446e65de3893b9c17959
4
+ data.tar.gz: 78182a8c53dd683fba71650fa5af83ec3637251903b1343722e27146aec5c042
5
5
  SHA512:
6
- metadata.gz: 34de3119b475580ec5b65cab413d8f6ca7aed17fe433542ea81c6ef5ba314a67d9a29c384dd2aaafc9a9ff267510efbf6649a33f43fb7d41a15a0d3b7c308661
7
- data.tar.gz: 2848933923aee39b310b107e77c6ec219b6642f0bda21c0e61677fbf056f3f80629f0d9bed0dbb81ea2637483d333de77292a871d86a358f19d98e1bade10b69
6
+ metadata.gz: c5d719440c65a62611fddbc9153a5d0f64585d1f67d45a3b29b9eba82d02940ce63f776092f829c0a1b3a55c292b4fe94a8515a38ef9126d150e705c44b7799d
7
+ data.tar.gz: d6de59c853d9fd0b8369ac583aa0235007c4576f7684431441620e3da2e2ee16d6a1def3b5718eaceef443a7e2a1fb2188b7bad4bbaf471f3bad6ee061ef59af
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2023 Alejandro Gutiérrez
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md CHANGED
@@ -38,6 +38,41 @@ end
38
38
  To see the full list of configuration options please check your gamora
39
39
  initializer.
40
40
 
41
+ ## Mount Gamora Engine
42
+
43
+ In order to have the authorization and callback endpoints mount the
44
+ engine in the `config/routes.rb` file:
45
+
46
+ ```ruby
47
+ Rails.application.routes.draw do
48
+ ...
49
+ mount Gamora::Engine => "/auth"
50
+
51
+ ...
52
+ end
53
+ ```
54
+
55
+ This will enable the following routes in the parent application:
56
+
57
+ #### `gamora.authorization_path`
58
+
59
+ This endpoint will redirect users to the IDP generating url and query
60
+ params based on the configuration. This endpoint is called automatically
61
+ when the user is not logged in and the application requires users to be
62
+ authenticated.
63
+
64
+ #### `gamora.logout_path`
65
+
66
+ This endpoint allows users to be logged out from the application and the
67
+ IDP. It removes the access and refresh tokens and redirects to IDP in order
68
+ to force users to authenticate again.
69
+
70
+ #### `gamora.callback_path`
71
+
72
+ This endpoint is the responsible to received the auth code provided by
73
+ the IDP and generate and access token. This endpoint is called automatically
74
+ once the user authenticates successfully in the IDP.
75
+
41
76
  ## User authentication
42
77
 
43
78
  ### Web-based applications
@@ -80,8 +115,32 @@ Optionally, if you want to do something different when authentication
80
115
  fails, you just need to override the `user_authentication_failed!`
81
116
  method in you controller and customize it as you wish.
82
117
 
118
+ ## Development
119
+
120
+ After checking out the repo, run `bin/setup` to install dependencies. Then,
121
+ run `rake spec` to run the tests. You can also run `bin/console` for an
122
+ interactive prompt that will allow you to experiment.
123
+
124
+ To install this gem onto your local machine, run `bundle exec rake install`.
125
+ To release a new version, update the version number in `version.rb`, and
126
+ then run `bundle exec rake release`, which will create a git tag for the
127
+ version, push git commits and the created tag, and push the `.gem` file
128
+ to [rubygems.org](https://rubygems.org).
129
+
83
130
  ## Contributing
84
- Contribution directions go here.
131
+
132
+ Bug reports and pull requests are welcome on GitHub at https://github.com/amco/gamora-rb.
133
+ This project is intended to be a safe, welcoming space for collaboration, and
134
+ contributors are expected to adhere to the
135
+ [code of conduct](https://github.com/amco/gamora-rb/blob/main/CODE_OF_CONDUCT.md).
85
136
 
86
137
  ## License
87
- The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
138
+
139
+ The gem is available as open source under the terms of the
140
+ [MIT License](https://opensource.org/licenses/MIT).
141
+
142
+ ## Code of Conduct
143
+
144
+ Everyone interacting in the Gamora project's codebases, issue trackers,
145
+ chat rooms and mailing lists is expected to follow the
146
+ [code of conduct](https://github.com/amco/gamora-rb/blob/main/CODE_OF_CONDUCT.md).
@@ -1,7 +1,21 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Gamora
2
4
  module AuthorizationUrl
3
5
  def authorization_url(params, extra_params = {})
4
- default_params = {
6
+ data =
7
+ default_params
8
+ .merge(extra_params)
9
+ .merge(authorization_params(params))
10
+ .compact_blank
11
+
12
+ Client.from_config.auth_code.authorize_url(data)
13
+ end
14
+
15
+ private
16
+
17
+ def default_params
18
+ {
5
19
  scope: Configuration.default_scope,
6
20
  theme: Configuration.default_theme,
7
21
  prompt: Configuration.default_prompt,
@@ -9,18 +23,8 @@ module Gamora
9
23
  branding: Configuration.default_branding,
10
24
  ui_locales: Configuration.ui_locales.call
11
25
  }
12
-
13
- data =
14
- default_params.
15
- merge(extra_params).
16
- merge(authorization_params(params)).
17
- compact_blank
18
-
19
- Client.from_config.auth_code.authorize_url(data)
20
26
  end
21
27
 
22
- private
23
-
24
28
  def authorization_params(params)
25
29
  params.permit(
26
30
  :scope,
@@ -6,8 +6,8 @@ module Gamora
6
6
 
7
7
  def show
8
8
  redirect_to authorization_url(params),
9
- allow_other_host: true,
10
- status: :see_other
9
+ allow_other_host: true,
10
+ status: :see_other
11
11
  end
12
12
  end
13
13
  end
@@ -7,7 +7,6 @@ module Gamora
7
7
  session[:access_token] = access_token.token
8
8
  session[:refresh_token] = access_token.refresh_token
9
9
  redirect_to session.delete("gamora.origin") || main_app.root_path
10
-
11
10
  rescue OAuth2::Error
12
11
  render plain: "Invalid authorization code"
13
12
  end
@@ -9,8 +9,8 @@ module Gamora
9
9
  session[:refresh_token] = nil
10
10
 
11
11
  redirect_to authorization_url(params, { max_age: 0 }),
12
- allow_other_host: true,
13
- status: :see_other
12
+ allow_other_host: true,
13
+ status: :see_other
14
14
  end
15
15
  end
16
16
  end
@@ -47,6 +47,7 @@ module Gamora
47
47
 
48
48
  def resource_owner_claims(access_token)
49
49
  return {} if access_token.blank?
50
+
50
51
  resource_owner_claims!(access_token)
51
52
  end
52
53
 
@@ -9,6 +9,7 @@ module Gamora
9
9
 
10
10
  def validate_authentication!
11
11
  return if current_user.present?
12
+
12
13
  user_authentication_failed!
13
14
  end
14
15
 
@@ -16,6 +17,7 @@ module Gamora
16
17
  pattern = /^Bearer /
17
18
  header = request.headers["Authorization"]
18
19
  return unless header&.match(pattern)
20
+
19
21
  header.gsub(pattern, "")
20
22
  end
21
23
 
@@ -13,6 +13,7 @@ module Gamora
13
13
 
14
14
  def validate_authentication!
15
15
  return if current_user.present?
16
+
16
17
  session["gamora.origin"] = request.original_url
17
18
  user_authentication_failed!
18
19
  end
data/lib/gamora/client.rb CHANGED
@@ -2,10 +2,18 @@
2
2
 
3
3
  module Gamora
4
4
  class Client < OAuth2::Client
5
- def self.from_config
6
- new(
7
- Configuration.client_id,
8
- Configuration.client_secret,
5
+ class << self
6
+ def from_config
7
+ new(
8
+ Configuration.client_id,
9
+ Configuration.client_secret,
10
+ client_options
11
+ )
12
+ end
13
+
14
+ private
15
+
16
+ def client_options
9
17
  {
10
18
  site: Configuration.site,
11
19
  token_url: Configuration.token_url,
@@ -14,7 +22,7 @@ module Gamora
14
22
  userinfo_url: Configuration.userinfo_url,
15
23
  authorize_url: Configuration.authorize_url
16
24
  }
17
- )
25
+ end
18
26
  end
19
27
 
20
28
  def userinfo(access_token)
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Gamora
4
- VERSION = "0.5.0"
4
+ VERSION = "0.6.1"
5
5
  end
metadata CHANGED
@@ -1,27 +1,27 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gamora
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.0
4
+ version: 0.6.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alejandro Gutiérrez
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-09-05 00:00:00.000000000 Z
11
+ date: 2023-07-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: oauth2
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - "~>"
17
+ - - ">="
18
18
  - !ruby/object:Gem::Version
19
19
  version: '1.4'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - "~>"
24
+ - - ">="
25
25
  - !ruby/object:Gem::Version
26
26
  version: '1.4'
27
27
  - !ruby/object:Gem::Dependency
@@ -46,7 +46,7 @@ executables: []
46
46
  extensions: []
47
47
  extra_rdoc_files: []
48
48
  files:
49
- - MIT-LICENSE
49
+ - LICENSE.txt
50
50
  - README.md
51
51
  - Rakefile
52
52
  - app/controllers/concerns/gamora/authorization_url.rb
@@ -68,13 +68,13 @@ files:
68
68
  - lib/generators/gamora/install_generator.rb
69
69
  - lib/generators/gamora/templates/gamora.rb
70
70
  - lib/tasks/gamora_tasks.rake
71
- homepage: https://github.com/amco/gamora_rb
71
+ homepage: https://github.com/amco/gamora-rb
72
72
  licenses:
73
73
  - MIT
74
74
  metadata:
75
- homepage_uri: https://github.com/amco/gamora_rb
76
- source_code_uri: https://github.com/amco/gamora_rb
77
- changelog_uri: https://github.com/amco/gamora_rb/blob/master/CHANGELOG.md
75
+ homepage_uri: https://github.com/amco/gamora-rb
76
+ source_code_uri: https://github.com/amco/gamora-rb
77
+ changelog_uri: https://github.com/amco/gamora-rb/blob/main/CHANGELOG.md
78
78
  rubygems_mfa_required: 'true'
79
79
  post_install_message:
80
80
  rdoc_options: []
@@ -91,7 +91,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
91
91
  - !ruby/object:Gem::Version
92
92
  version: '0'
93
93
  requirements: []
94
- rubygems_version: 3.3.7
94
+ rubygems_version: 3.4.17
95
95
  signing_key:
96
96
  specification_version: 4
97
97
  summary: OpenID Connect Relying Party for rails apps.
data/MIT-LICENSE DELETED
@@ -1,20 +0,0 @@
1
- Copyright 2022 Alejandro Gutiérrez
2
-
3
- Permission is hereby granted, free of charge, to any person obtaining
4
- a copy of this software and associated documentation files (the
5
- "Software"), to deal in the Software without restriction, including
6
- without limitation the rights to use, copy, modify, merge, publish,
7
- distribute, sublicense, and/or sell copies of the Software, and to
8
- permit persons to whom the Software is furnished to do so, subject to
9
- the following conditions:
10
-
11
- The above copyright notice and this permission notice shall be
12
- included in all copies or substantial portions of the Software.
13
-
14
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
- EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
- MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
- NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
- LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
- OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
- WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.