gamora 0.11.0 → 0.13.0

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: e35b31caf66937012f903a789beed12bac91e7e7a809a3e08fd3f1afc69cad19
4
- data.tar.gz: f4ec146d7b34b0e6f011f923998d4abfefac5c6ebb421eb4b6eb650d40f63898
3
+ metadata.gz: 5e104c740e37e365b1a0026c7cc35c4484bfe4e3546f2ecc7f29cdc2d983b1c8
4
+ data.tar.gz: 4e5386d4a3d3cb3541c9d1b6c67ac648ea33bd0d088aa77c6b598a612e155501
5
5
  SHA512:
6
- metadata.gz: c71974d1b67d1d7ba20cebc8d5df51b1a948400a18aa74f3e39d37f4cd74f80c8675ab1388d067f8917d69ca31efca6893396a4efcddf3bcc1a95a0241267731
7
- data.tar.gz: b1c6c5a879a035bc768e4c98a9f67d42d5f8e80aa9e0f42aff1fd6dfeacb02bd2611967b171471f328595cf38a73c676bfd08bc51087614dd83380eeb2a95f6b
6
+ metadata.gz: 3fe807fc7d017463448981f708a68f3e3a0ae6d61ae1985d794230af707cdf0d76e1da05f267afccbe564262273b520e70229548f9f06edafc7e2305573b3a6e
7
+ data.tar.gz: 2827ef0787c8e7ccbf7462be3b921c7a82e699f35d91b48c34528db9526209ef34a9ca0aac32e180027ce6fb564cb65e9f37a3117916c787b5c99fa169d5e785
data/README.md CHANGED
@@ -132,6 +132,23 @@ Gamora.setup do |config|
132
132
  end
133
133
  ```
134
134
 
135
+ ## Authorization
136
+
137
+ In order to inform if a user's access token is granted to access the IDP
138
+ client, it is possible to configure the authorization method in the initializer
139
+ that will be used in the `/auth/amco/authorized` endpoint.
140
+
141
+ ```ruby
142
+ Gamora.setup do |config|
143
+ ...
144
+
145
+ config.authorization_method = -> (user) { MyAuthorizationService.call(user) }
146
+ end
147
+ ```
148
+
149
+ Then implement the `MyAuthorizationService` based on your needs and return
150
+ true if the user is granted, otherwise return false.
151
+
135
152
  ## Development
136
153
 
137
154
  After checking out the repo, run `bin/setup` to install dependencies. Then,
@@ -2,6 +2,18 @@
2
2
 
3
3
  module Gamora
4
4
  module AuthorizationUrl
5
+ ALLOWED_PARAMS = %i[
6
+ scope
7
+ state
8
+ theme
9
+ prompt
10
+ max_age
11
+ strategy
12
+ branding
13
+ ui_locales
14
+ allow_create
15
+ ].freeze
16
+
5
17
  def authorization_url(params, extra_params = {})
6
18
  data =
7
19
  default_params
@@ -21,21 +33,13 @@ module Gamora
21
33
  prompt: Configuration.default_prompt,
22
34
  strategy: Configuration.default_strategy,
23
35
  branding: Configuration.default_branding,
24
- ui_locales: Configuration.ui_locales.call
36
+ ui_locales: Configuration.ui_locales.call,
37
+ allow_create: Configuration.allow_create
25
38
  }
26
39
  end
27
40
 
28
41
  def authorization_params(params)
29
- params.permit(
30
- :scope,
31
- :state,
32
- :theme,
33
- :prompt,
34
- :max_age,
35
- :strategy,
36
- :branding,
37
- :ui_locales
38
- )
42
+ params.permit(*ALLOWED_PARAMS)
39
43
  end
40
44
  end
41
45
  end
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Gamora
4
+ class AuthorizationController < ApplicationController
5
+ include Gamora::Authentication::Headers
6
+
7
+ before_action :authenticate_user!
8
+
9
+ def show
10
+ Configuration.authorization_method.call(current_user) ?
11
+ render(json: { message: "Authorized user" }, status: :ok) :
12
+ render(json: { error: "Unauthorized user" }, status: :forbidden)
13
+ end
14
+ end
15
+ end
data/config/routes.rb CHANGED
@@ -2,6 +2,7 @@
2
2
 
3
3
  Gamora::Engine.routes.draw do
4
4
  get "amco", to: "authentication#show", as: :authentication
5
- get "logout", to: "unauthentication#show", as: :logout
5
+ get "amco/logout", to: "unauthentication#show", as: :logout
6
+ get "amco/authorized", to: "authorization#show", as: :authorized
6
7
  get "amco/callback", to: "callback#show", as: :callback
7
8
  end
@@ -17,8 +17,10 @@ module Gamora
17
17
  mattr_accessor :default_branding, default: "amco"
18
18
  mattr_accessor :default_theme, default: "default"
19
19
  mattr_accessor :ui_locales, default: -> { I18n.locale }
20
+ mattr_accessor :allow_create, default: true
20
21
  mattr_accessor :userinfo_cache_expires_in, default: 1.minute
21
22
  mattr_accessor :introspect_cache_expires_in, default: 0.seconds
23
+ mattr_accessor :authorization_method, default: -> (user) { !!user }
22
24
 
23
25
  def setup
24
26
  yield(self) if block_given?
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Gamora
4
- VERSION = "0.11.0"
4
+ VERSION = "0.13.0"
5
5
  end
@@ -19,6 +19,8 @@ Gamora.setup do |config|
19
19
  # config.default_branding = "amco"
20
20
  # config.default_theme = "default"
21
21
  # config.ui_locales = -> { I18n.locale }
22
+ # config.allow_create = true
22
23
  # config.userinfo_cache_expires_in = 1.minute
23
24
  # config.introspect_cache_expires_in = 0.seconds
25
+ # config.authorization_method = -> (user) { user.authorized? }
24
26
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gamora
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.11.0
4
+ version: 0.13.0
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: 2024-02-21 00:00:00.000000000 Z
11
+ date: 2024-10-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: oauth2
@@ -52,6 +52,7 @@ files:
52
52
  - app/controllers/concerns/gamora/authorization_url.rb
53
53
  - app/controllers/gamora/application_controller.rb
54
54
  - app/controllers/gamora/authentication_controller.rb
55
+ - app/controllers/gamora/authorization_controller.rb
55
56
  - app/controllers/gamora/callback_controller.rb
56
57
  - app/controllers/gamora/unauthentication_controller.rb
57
58
  - app/models/gamora/application_record.rb
@@ -91,7 +92,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
91
92
  - !ruby/object:Gem::Version
92
93
  version: '0'
93
94
  requirements: []
94
- rubygems_version: 3.4.17
95
+ rubygems_version: 3.5.11
95
96
  signing_key:
96
97
  specification_version: 4
97
98
  summary: OpenID Connect Relying Party for rails apps.