model_driven_api 3.4.2 → 3.4.4

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: cc68530c0b5f4519866a975cea9ea23207cec6dc83aad73cd6a61da041760fee
4
- data.tar.gz: 5789f8c2a515b3385a6c53da9392fbc21fdb599aa247a9968b5a8a2f6b03f326
3
+ metadata.gz: ed7db62f6e456f3535221fe7fd09da02dfde4a4ac2c3951a15b229e249ca1706
4
+ data.tar.gz: fa80dce7d6e7fbca51b884ba7e368117c54308255572861fa4d14e75861360a9
5
5
  SHA512:
6
- metadata.gz: b58dc845ec1c3d228228e4f0527d8dcb0c82ebe9bf92cd1df86615cd9137a4c93539b076d1c8bb673feb8b6bc68daa7e4b332357995aabc11bb4c297b17dd372
7
- data.tar.gz: cbbabc3bb858b9d83d10bc01617f147c1cb9402a6ce65db269b9a41639ea8fedb16ccaed7f5c86dbde3c7a7c98c19f50d552804f6538d0dd33aa3b96a77cf38b
6
+ metadata.gz: 52d75ac780843f651052880108a662081c92ab55ded13cf8d69f241b979b6ce69b05552aca222ec63c01e9b0426ee7f81902196e13746d8cae89ad3a0280f0ff
7
+ data.tar.gz: 4854bef7827dbfdaa17ca41d255bcd2b297c42acafb45cca0ef21d399f24d6b704e69b62b1745284bfbb9f4ecd966036a906e339033cb07aefe1ca7766e8974b
@@ -15,18 +15,18 @@ class AuthorizeApiRequest
15
15
 
16
16
  def api_user
17
17
  Rails.logger.debug "AuthorizeApiRequest: api_user -> #{decoded_auth_token}"
18
- @api_user ||= User.find(decoded_auth_token[:user_id]) if decoded_auth_token
19
- if @api_user
18
+ @api_user ||= (decoded_auth_token.blank? ? User.find(decoded_auth_token[:user_id]) : nil)
19
+ unless @api_user.blank
20
20
  return @api_user
21
21
  else
22
- errors.add(:token, "Invalid token")
22
+ errors.add(:token, "Invalid or Expired token")
23
23
  return nil
24
24
  end
25
25
  end
26
26
 
27
27
  def decoded_auth_token
28
28
  Rails.logger.debug "AuthorizeApiRequest: decoded_auth_token -> http_auth_header -> #{http_auth_header}"
29
- @decoded_auth_token ||= JsonWebToken.decode(http_auth_header)
29
+ @decoded_auth_token ||= (JsonWebToken.decode(http_auth_header) rescue nil)
30
30
  @decoded_auth_token
31
31
  end
32
32
 
@@ -1,15 +1,8 @@
1
1
  module Api::V2::Auth
2
2
  class OauthController < ActionController::API
3
3
  def callback
4
- email = params['email']
4
+ user = ThecoreAuthCommons.check_user params['email'], params['given_name'], params['family_name'], params['provider']
5
5
 
6
- user = User.find_or_create_by(email: email) do |u|
7
- u.name = params['given_name']
8
- u.surname = params['family_name']
9
- u.password = u.password_confirmation = ThecoreAuthCommons.generate_secure_password
10
- u.auth_source = params['provider'] # 'google' or 'microsoft'
11
- u.admin = true
12
- end
13
6
  unless user
14
7
  render json: { error: "User not registered" }, status: :unauthorized
15
8
  return
data/config/routes.rb CHANGED
@@ -1,9 +1,8 @@
1
1
  # require 'ransack'
2
2
 
3
3
  Rails.application.routes.draw do
4
- oauth_test = (ENV['ENTRA_CLIENT_ID'].present? && ENV['ENTRA_CLIENT_SECRET'].present? && ENV['ENTRA_TENANT_ID'].present?) || (ENV['GOOGLE_CLIENT_ID'].present? && ENV['GOOGLE_CLIENT_SECRET'].present?)
5
4
  scope ENV.fetch("RAILS_RELATIVE_URL_ROOT", "/") do
6
- if oauth_test
5
+ if ThecoreAuthCommons.oauth_vars?
7
6
  # OmniAuth callbacks need these top-level paths:
8
7
  match '/auth/:provider/callback', to: redirect('/api/v2/auth/%{provider}/callback'), via: [:get, :post]
9
8
  match '/auth/failure', to: redirect('/api/v2/auth/failure'), via: [:get, :post]
@@ -11,7 +10,7 @@ Rails.application.routes.draw do
11
10
  namespace :api, constraints: { format: :json } do
12
11
  namespace :v2 do
13
12
  # Authentication via Oauth2 only if the environment variable is set
14
- if oauth_test
13
+ if ThecoreAuthCommons.oauth_vars?
15
14
  namespace :auth do
16
15
  # Omniauth routes for OAuth2 authentication
17
16
  match ':provider/callback', to: 'oauth#callback', via: [:get, :post]
@@ -1,3 +1,3 @@
1
1
  module ModelDrivenApi
2
- VERSION = "3.4.2".freeze
2
+ VERSION = "3.4.4".freeze
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: model_driven_api
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.4.2
4
+ version: 3.4.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gabriele Tassoni
@@ -132,7 +132,6 @@ files:
132
132
  - config/initializers/after_initialize_for_model_driven_api.rb
133
133
  - config/initializers/cors_api_thecore.rb
134
134
  - config/initializers/knock.rb
135
- - config/initializers/omniauth.rb
136
135
  - config/initializers/time_with_zone.rb
137
136
  - config/initializers/wrap_parameters.rb
138
137
  - config/routes.rb
@@ -1,20 +0,0 @@
1
- Rails.application.config.middleware.use OmniAuth::Builder do
2
- provider(
3
- :entra_id,
4
- {
5
- client_id: ENV['ENTRA_CLIENT_ID'],
6
- client_secret: ENV['ENTRA_CLIENT_SECRET'],
7
- tenant_id: ENV['ENTRA_TENANT_ID'], # Needed for Microsoft
8
- scope: 'User.Read',
9
- response_type: 'code'
10
- }
11
- )
12
- provider :google_oauth2, ENV['GOOGLE_CLIENT_ID'], ENV['GOOGLE_CLIENT_SECRET'], {
13
- scope: 'email,profile',
14
- prompt: 'select_account',
15
- access_type: 'online'
16
- }
17
- end
18
-
19
- OmniAuth.config.allowed_request_methods = [:get, :post]
20
- OmniAuth.config.silence_get_warning = true