gamora 0.12.0 → 0.14.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: b42990c52c0cce68d2464f8479c8de617b42c11475971194b15874ee570fefc5
4
- data.tar.gz: d03c696925417027a34bf19b9cf9f9c40a00e625a2f7bf14d59d01a31158747e
3
+ metadata.gz: d73a2356c80a3ae90435c16aaed089ceb8bab96a4c424fd66a819d7dbd9843c5
4
+ data.tar.gz: 950a900f569d1bd94c039bcbac19df6919ce83953122a71dcd3769dd26a9a848
5
5
  SHA512:
6
- metadata.gz: f03be26d3851c500561b50903bbc03475608822c69f21024fc4f969231b149049a2c3711ab4c234071a2f956efe01a5a9779a7bd105173cadad0e52dc998e119
7
- data.tar.gz: 6177e2b7e04290502fb6395d29be8389e5ee6e743aeecf6e23efc401cce42e743aa6f88a140deb0e92190f0444b2272776269044e7ed3b52a693279b16fd400a
6
+ metadata.gz: 95a2b078b3546d2a5ad193b45db7ab5c710847db8096ac7a813ddd1af644450fe5e30e443055af43c1860bf26526985eadab8d31500fbed943b9d8fc3fbaf7c9
7
+ data.tar.gz: d224336f131f0d1c0ff4ef68af57f460f2194288a3d61788d653abd994d20e43a43d9c03151c84400d2a2afcdfed00d954e346dba5488e877a4d3bde24a09ff6
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,
@@ -0,0 +1,17 @@
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
+ if Configuration.authorization_method.call(current_user)
11
+ render json: { message: "Authorized user" }, status: :ok
12
+ else
13
+ render json: { error: "Unauthorized user" }, status: :forbidden
14
+ end
15
+ end
16
+ end
17
+ 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
@@ -12,6 +12,7 @@ module Gamora
12
12
  family_name: :last_name,
13
13
  phone_number: :phone_number,
14
14
  email_verified: :email_verified,
15
+ associated_user_id: :associated_user_id,
15
16
  phone_number_verified: :phone_number_verified
16
17
  }.freeze
17
18
 
@@ -20,6 +20,7 @@ module Gamora
20
20
  mattr_accessor :allow_create, default: true
21
21
  mattr_accessor :userinfo_cache_expires_in, default: 1.minute
22
22
  mattr_accessor :introspect_cache_expires_in, default: 0.seconds
23
+ mattr_accessor :authorization_method, default: ->(user) { user }
23
24
 
24
25
  def setup
25
26
  yield(self) if block_given?
data/lib/gamora/user.rb CHANGED
@@ -12,6 +12,7 @@ module Gamora
12
12
  :first_name,
13
13
  :phone_number,
14
14
  :email_verified,
15
+ :associated_user_id,
15
16
  :phone_number_verified
16
17
  end
17
18
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Gamora
4
- VERSION = "0.12.0"
4
+ VERSION = "0.14.0"
5
5
  end
@@ -22,4 +22,5 @@ Gamora.setup do |config|
22
22
  # config.allow_create = true
23
23
  # config.userinfo_cache_expires_in = 1.minute
24
24
  # config.introspect_cache_expires_in = 0.seconds
25
+ # config.authorization_method = ->(user) { user.authorized? }
25
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.12.0
4
+ version: 0.14.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-07-22 00:00:00.000000000 Z
11
+ date: 2024-11-14 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.