decidim-api 0.32.0 → 0.32.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: e0d0eddc032a0b48736746b609b28e9b73854f3559673d05607fdafe0babe019
4
- data.tar.gz: 34c8d3ba36cba38b7f290bd1d903bf72407a9e179de511dec6f7ef0de1b47dcf
3
+ metadata.gz: 711ce76f6b6ef54bacaa6bc29c43a19b85700f4774f27e103d40e20431951e4a
4
+ data.tar.gz: 914f1dd7ea6ef1aa92ac99b571c42d9d469190d9834969b820a0b088e8bbddc0
5
5
  SHA512:
6
- metadata.gz: 96734ffd4b043c6a6806e053f25a8c3c2ce895e8553d3961053d8339e84e87a9ce0c136b461aaa34ac09db5bcd291543b2111b89592d926b83b8b7b78dcaea86
7
- data.tar.gz: a86d42ef455a52e18685645186fcf37ffe9dca7de7c8358cbd608318af8c7f7d913488fd0270f4f816b3d8c908eaf45f6af2569d162f1d123ab5a72ba6937a90
6
+ metadata.gz: 05c4829b1bc14b3e49fb8b5a2063fb2a9342503dba997f9ae4c7872a6cbaebd2aaa8dcdb15fc0d0f9801f34631cd3b99ff1d6f6ff998715e8a58945c4ada5ca1
7
+ data.tar.gz: ffdc03c642bbb04d4c325eb48a53be3bc8951b1a86b2900d4c8a8718d167368051eeef3821a7616a4f7be3761e94e48373324462003c9e0ec7d74131da51ecd5
@@ -0,0 +1,19 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "active_support/concern"
4
+
5
+ module Decidim
6
+ module Api
7
+ # This concern adds the JWT authenticable strategy for the User models to
8
+ # allow regular users to sign in through the API (if configured from the
9
+ # system panel). Allows normal users to utilize the API e.g. through mobile
10
+ # applications.
11
+ module UserExtension
12
+ extend ActiveSupport::Concern
13
+
14
+ included do
15
+ devise :jwt_authenticatable, jwt_revocation_strategy: Decidim::Api::JwtDenylist
16
+ end
17
+ end
18
+ end
19
+ end
data/decidim-api.gemspec CHANGED
@@ -3,7 +3,7 @@
3
3
  $LOAD_PATH.push File.expand_path("lib", __dir__)
4
4
 
5
5
  Gem::Specification.new do |s|
6
- version = "0.32.0"
6
+ version = "0.32.1"
7
7
  s.version = version
8
8
  s.authors = ["Josep Jaume Rey Peroy", "Marc Riera Casals", "Oriol Gual Oliva"]
9
9
  s.email = ["josepjaume@gmail.com", "mrc2407@gmail.com", "oriolgual@gmail.com"]
@@ -41,6 +41,45 @@ module Decidim
41
41
  end
42
42
  end
43
43
 
44
+ initializer "decidim_api.devise", before: "add_routing_paths" do |app|
45
+ config.to_prepare do
46
+ Decidim::User.include Decidim::Api::UserExtension
47
+ end
48
+
49
+ # Required for the development environment because otherwise the JWT
50
+ # authentication strategy would be lost during code reloads.
51
+ app.reloader.after_class_unload do
52
+ Decidim::User.include Decidim::Api::UserExtension
53
+ end
54
+ end
55
+
56
+ initializer "decidim_api.devise_jwt", after: "devise.secret_key" do
57
+ Devise.jwt do |jwt|
58
+ # In order to be compatible with the JWT authentication, we need to set these
59
+ # configurations. JWT secret is being used by the devise-jwt to sign the
60
+ # tokens, once the user authenticated. The token signature ensures the
61
+ # validity of the token and that the user has not tampered with it. If the
62
+ # secret is not set correctly, the API authentication does not work.
63
+ #
64
+ # Note that the `dispatch_requests` and `revocation_requests` paths are the
65
+ # full paths because we do not want the JWT tokens to be dispatched or revoked
66
+ # during normal Decidim user sign ins or sign outs. This also requires a small
67
+ # override to `Warden::JWTAuth` which is defined at
68
+ # `decidim-api/lib/warden/jwt_auth/decidim_overrides.rb`.
69
+ jwt.secret = Decidim::Env.new("DECIDIM_API_JWT_SECRET").value || Devise.secret_key
70
+ raise "Please define the secret key for Devise" unless jwt.secret
71
+
72
+ jwt.dispatch_requests = [
73
+ ["POST", %r{^/api/sign_in$}]
74
+ ]
75
+ jwt.revocation_requests = [
76
+ ["DELETE", %r{^/api/sign_out$}]
77
+ ]
78
+ jwt.expiration_time = Decidim::Api.jwt_expires_in.minutes.to_i
79
+ jwt.aud_header = "X_JWT_AUD"
80
+ end
81
+ end
82
+
44
83
  initializer "decidim_api.data_migrate", after: "decidim_core.data_migrate" do
45
84
  DataMigrate.configure do |config|
46
85
  config.data_migrations_path << root.join("db/data").to_s
@@ -4,7 +4,7 @@ module Decidim
4
4
  # This holds the decidim-api version.
5
5
  module Api
6
6
  def self.version
7
- "0.32.0"
7
+ "0.32.1"
8
8
  end
9
9
  end
10
10
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: decidim-api
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.32.0
4
+ version: 0.32.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Josep Jaume Rey Peroy
@@ -17,14 +17,14 @@ dependencies:
17
17
  requirements:
18
18
  - - '='
19
19
  - !ruby/object:Gem::Version
20
- version: 0.32.0
20
+ version: 0.32.1
21
21
  type: :runtime
22
22
  prerelease: false
23
23
  version_requirements: !ruby/object:Gem::Requirement
24
24
  requirements:
25
25
  - - '='
26
26
  - !ruby/object:Gem::Version
27
- version: 0.32.0
27
+ version: 0.32.1
28
28
  - !ruby/object:Gem::Dependency
29
29
  name: devise-jwt
30
30
  requirement: !ruby/object:Gem::Requirement
@@ -111,56 +111,56 @@ dependencies:
111
111
  requirements:
112
112
  - - '='
113
113
  - !ruby/object:Gem::Version
114
- version: 0.32.0
114
+ version: 0.32.1
115
115
  type: :development
116
116
  prerelease: false
117
117
  version_requirements: !ruby/object:Gem::Requirement
118
118
  requirements:
119
119
  - - '='
120
120
  - !ruby/object:Gem::Version
121
- version: 0.32.0
121
+ version: 0.32.1
122
122
  - !ruby/object:Gem::Dependency
123
123
  name: decidim-comments
124
124
  requirement: !ruby/object:Gem::Requirement
125
125
  requirements:
126
126
  - - '='
127
127
  - !ruby/object:Gem::Version
128
- version: 0.32.0
128
+ version: 0.32.1
129
129
  type: :development
130
130
  prerelease: false
131
131
  version_requirements: !ruby/object:Gem::Requirement
132
132
  requirements:
133
133
  - - '='
134
134
  - !ruby/object:Gem::Version
135
- version: 0.32.0
135
+ version: 0.32.1
136
136
  - !ruby/object:Gem::Dependency
137
137
  name: decidim-dev
138
138
  requirement: !ruby/object:Gem::Requirement
139
139
  requirements:
140
140
  - - '='
141
141
  - !ruby/object:Gem::Version
142
- version: 0.32.0
142
+ version: 0.32.1
143
143
  type: :development
144
144
  prerelease: false
145
145
  version_requirements: !ruby/object:Gem::Requirement
146
146
  requirements:
147
147
  - - '='
148
148
  - !ruby/object:Gem::Version
149
- version: 0.32.0
149
+ version: 0.32.1
150
150
  - !ruby/object:Gem::Dependency
151
151
  name: decidim-participatory_processes
152
152
  requirement: !ruby/object:Gem::Requirement
153
153
  requirements:
154
154
  - - '='
155
155
  - !ruby/object:Gem::Version
156
- version: 0.32.0
156
+ version: 0.32.1
157
157
  type: :development
158
158
  prerelease: false
159
159
  version_requirements: !ruby/object:Gem::Requirement
160
160
  requirements:
161
161
  - - '='
162
162
  - !ruby/object:Gem::Version
163
- version: 0.32.0
163
+ version: 0.32.1
164
164
  description: API engine for decidim
165
165
  email:
166
166
  - josepjaume@gmail.com
@@ -177,6 +177,7 @@ files:
177
177
  - app/controllers/decidim/api/graphiql_controller.rb
178
178
  - app/controllers/decidim/api/queries_controller.rb
179
179
  - app/controllers/decidim/api/sessions_controller.rb
180
+ - app/models/concerns/decidim/api/user_extension.rb
180
181
  - app/models/decidim/api/api_user.rb
181
182
  - app/models/decidim/api/jwt_denylist.rb
182
183
  - app/packs/entrypoints/decidim_api_docs.js
@@ -189,7 +190,6 @@ files:
189
190
  - app/views/decidim/api/graphiql/show.html.erb
190
191
  - app/views/layouts/decidim/api/documentation.html.erb
191
192
  - config/assets.rb
192
- - config/initializers/devise.rb
193
193
  - config/locales/am-ET.yml
194
194
  - config/locales/ar.yml
195
195
  - config/locales/bg.yml
@@ -1,26 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- Devise.jwt do |jwt|
4
- # In order to be compatible with the JWT authentication, we need to set these
5
- # configurations. JWT secret is being used by the devise-jwt to sign the
6
- # tokens, once the user authenticated. The token signature ensures the
7
- # validity of the token and that the user has not tampered with it. If the
8
- # secret is not set correctly, the API authentication does not work.
9
- #
10
- # Note that the `dispatch_requests` and `revocation_requests` paths are the
11
- # full paths because we do not want the JWT tokens to be dispatched or revoked
12
- # during normal Decidim user sign ins or sign outs. This also requires a small
13
- # override to `Warden::JWTAuth` which is defined at
14
- # `decidim-api/lib/warden/jwt_auth/decidim_overrides.rb`.
15
- jwt.secret = Decidim::Env.new("DECIDIM_API_JWT_SECRET").value
16
- next unless jwt.secret
17
-
18
- jwt.dispatch_requests = [
19
- ["POST", %r{^/api/sign_in$}]
20
- ]
21
- jwt.revocation_requests = [
22
- ["DELETE", %r{^/api/sign_out$}]
23
- ]
24
- jwt.expiration_time = Decidim::Api.jwt_expires_in.minutes.to_i
25
- jwt.aud_header = "X_JWT_AUD"
26
- end