infinum_azure 0.1.0 → 0.2.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: f06378aa3fb152b879f9ad741a7bc83df51bffe7ca5f716b5769bf4a8ad20db1
4
- data.tar.gz: 517a2708e459b1c4d4f6d1577d604c1403aaab6cfe6511b5f382e85525fd2cb9
3
+ metadata.gz: 9d398fe751b6c5e4b20f5a859f6447282ae9d265a5081056be7d8655c44ffa1c
4
+ data.tar.gz: ab1415b92e1204eab1d18bddde14843c64042048046ccf2bcfdee4cb9e1a401c
5
5
  SHA512:
6
- metadata.gz: 7ae21e8407f07e7da940dae6aadc9e43ca5fae05fd8709725013ce09649d96ac205626315bb81e9513bf3ebc5f28550415f54c83ddc583a45f9f1ddb6ea7c954
7
- data.tar.gz: a785f790548ef0c29310ac696e796c96be84a7c22610f7be700273bbe9935ef28702582da49834a7cdd86b6c4fdb3ab0ba5da7312c461a359415e0712a41ec55
6
+ metadata.gz: 8337851fbce87882183719f0b3260aca0260bdab7b62dc81ea398a11fb926cf5ba93fcefcddde04db23f7bd2c07e947d5b86f297de802b833ab926b9f8f01476
7
+ data.tar.gz: bb79db00f82557befa5c3f2c7b0fc64750fec96516c19fad9b461ea6cbd1bc0303de87a488d7b80352b2d6817d62ff95b4fe292e28faf83e642a00cac31c953b
data/.rubocop.yml CHANGED
@@ -18,3 +18,7 @@ Metrics/BlockLength:
18
18
  Exclude:
19
19
  - '**/*.rake'
20
20
  - 'spec/**/*.rb'
21
+
22
+ Style/FrozenStringLiteralComment:
23
+ Exclude:
24
+ - 'spec/**/*.rb'
data/CHANGELOG.md CHANGED
@@ -1,5 +1,13 @@
1
1
  ## [Unreleased]
2
2
 
3
+ ## [0.2.1] - 2023-04-20
4
+
5
+ - Added after_upsert_resource & called it in upsert webhook API after the action
6
+
7
+ ## [0.2.0] - 2023-04-20
8
+
9
+ - Added upsert webhook API for creating/updating resources
10
+
3
11
  ## [0.1.0] - 2023-03-15
4
12
 
5
13
  - Initial release
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- infinum_azure (0.1.0)
4
+ infinum_azure (0.2.1)
5
5
  bundler
6
6
  devise
7
7
  dry-configurable
data/README.md CHANGED
@@ -43,12 +43,14 @@ Or install it yourself as:
43
43
  InfinumAzure.configure do |config|
44
44
  config.service_name = 'Revisor'
45
45
  config.resource_name = 'User'
46
+ config.resource_attributes = [:uid, :email, :first_name, :last_name]
46
47
  end
47
48
  ```
48
49
 
49
50
  Configuration options:
50
51
  * Service name - name of application
51
52
  * Resource name - name of resource on whom authentication is being done
53
+ * Resource attributes - attributes sent from InfinumAzure when user is created/updated that will be permitted
52
54
 
53
55
  ### Secrets
54
56
 
@@ -102,6 +104,30 @@ or, if you just want to clear the session, but not log out of Infinum Azure, you
102
104
  link_to 'Logout', logout_path
103
105
  ```
104
106
 
107
+ ## Known issues
108
+
109
+ If you don't get what you're looking for, check your terminal output and see if omniauth logs are saying anything similar to:
110
+
111
+ ```
112
+ DEBUG -- omniauth: (google_oauth2) Request phase initiated.
113
+ WARN -- omniauth: Attack prevented by OmniAuth::AuthenticityTokenProtection
114
+ ERROR -- omniauth: (google_oauth2) Authentication failure! authenticity_error: OmniAuth::AuthenticityError, Forbidden
115
+ ```
116
+
117
+ To resolve this issue, install the omniauth-rails_csrf_protection gem:
118
+
119
+ ```ruby
120
+ gem 'omniauth-rails_csrf_protection'
121
+ ```
122
+
123
+ Make sure to use HTTP method POST for authenticating. If you are using a link, you can set the HTTP method to POST like this:
124
+
125
+ ```ruby
126
+ link_to 'Login', user_infinum_azure_omniauth_authorize_path, method: :post
127
+ ```
128
+
129
+ or, simply with `#button_to` as mentioned above.
130
+
105
131
  ## License
106
132
 
107
133
  The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
@@ -0,0 +1,35 @@
1
+ # frozen_string_literal: true
2
+
3
+ module InfinumAzure
4
+ module Api
5
+ class WebhooksController < Api::BaseController
6
+ def upsert_resource_callback
7
+ if resource
8
+ resource.update(user_params)
9
+ action = 'updated'
10
+ else
11
+ resource_class.create(user_params)
12
+ action = 'created'
13
+ end
14
+
15
+ InfinumAzure::AfterUpsertResource.call(resource, params[:user])
16
+
17
+ render json: { resource_name.underscore => action }
18
+ end
19
+
20
+ private
21
+
22
+ def resource
23
+ @resource ||= resource_class.where(uid: user_params[:uid], provider: InfinumAzure.provider).or(
24
+ resource_class.where(email: user_params[:email])
25
+ ).first
26
+ end
27
+
28
+ def user_params
29
+ params.require(:user)
30
+ .permit(InfinumAzure.resource_attributes)
31
+ .merge(provider: InfinumAzure.provider)
32
+ end
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ module InfinumAzure
4
+ class AfterUpsertResource
5
+ def self.call(resource, params); end
6
+ end
7
+ end
data/config/routes.rb CHANGED
@@ -7,4 +7,12 @@ Rails.application.routes.draw do
7
7
  devise_for InfinumAzure.resource_name.pluralize.underscore, controllers: {
8
8
  omniauth_callbacks: 'infinum_azure/resources/omniauth_callbacks'
9
9
  }
10
+
11
+ namespace :infinum_azure do
12
+ namespace :api do
13
+ scope '/webhooks', controller: :webhooks do
14
+ post :upsert_resource_callback
15
+ end
16
+ end
17
+ end
10
18
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module InfinumAzure
4
- VERSION = '0.1.0'
4
+ VERSION = '0.2.1'
5
5
  end
data/lib/infinum_azure.rb CHANGED
@@ -12,6 +12,11 @@ module InfinumAzure
12
12
 
13
13
  setting :service_name, reader: true
14
14
  setting :resource_name, default: 'User', reader: true
15
+ setting :resource_attributes, default: [:uid, :email, :first_name, :last_name], reader: true
16
+
17
+ def self.provider
18
+ to_s.underscore
19
+ end
15
20
 
16
21
  def self.resource_class
17
22
  resource_name.constantize
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: infinum_azure
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Marko Ćilimković
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2023-03-15 00:00:00.000000000 Z
11
+ date: 2023-04-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -299,10 +299,12 @@ files:
299
299
  - README.md
300
300
  - Rakefile
301
301
  - app/controllers/infinum_azure/api/base_controller.rb
302
+ - app/controllers/infinum_azure/api/webhooks_controller.rb
302
303
  - app/controllers/infinum_azure/application_controller.rb
303
304
  - app/controllers/infinum_azure/resources/omniauth_callbacks_controller.rb
304
305
  - app/controllers/infinum_azure/resources_controller.rb
305
306
  - app/models/infinum_azure/application_record.rb
307
+ - app/services/infinum_azure/after_upsert_resource.rb
306
308
  - app/services/infinum_azure/resources/finder.rb
307
309
  - config/initializers/devise.rb
308
310
  - config/routes.rb