infinum_azure 0.1.0 → 0.2.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: f06378aa3fb152b879f9ad741a7bc83df51bffe7ca5f716b5769bf4a8ad20db1
4
- data.tar.gz: 517a2708e459b1c4d4f6d1577d604c1403aaab6cfe6511b5f382e85525fd2cb9
3
+ metadata.gz: 91e15ff1b9c4d10efe59515afefabb3d7cf30ab4e5db48a7f6d6a9a0ba0becd9
4
+ data.tar.gz: 2b9b9d955b4f66d029da9243ce62430988a040ae7995a12bd13d3059f07c1a07
5
5
  SHA512:
6
- metadata.gz: 7ae21e8407f07e7da940dae6aadc9e43ca5fae05fd8709725013ce09649d96ac205626315bb81e9513bf3ebc5f28550415f54c83ddc583a45f9f1ddb6ea7c954
7
- data.tar.gz: a785f790548ef0c29310ac696e796c96be84a7c22610f7be700273bbe9935ef28702582da49834a7cdd86b6c4fdb3ab0ba5da7312c461a359415e0712a41ec55
6
+ metadata.gz: c99b0116be82397a78d57d24f98de0cc8fbd2d26e1ee22b3a565205c1cfff1ea4598e507ed62071ed4d9f6446e9223e72c5f024f4d7ed968b54a56fff9e41583
7
+ data.tar.gz: 5c74771724c5bc818b7df7c78cfa27c14ebfb29948e226e01b5fb92014a24371ec39295cda1a06d33b1f92221942f1d00a58c99b023753b40bfc5bb99c63b3d6
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,9 @@
1
1
  ## [Unreleased]
2
2
 
3
+ ## [0.2.0] - 2023-04-20
4
+
5
+ - Added upsert webhook API for creating/updating resources
6
+
3
7
  ## [0.1.0] - 2023-03-15
4
8
 
5
9
  - 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.0)
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,33 @@
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
+ render json: { resource_name.underscore => action }
16
+ end
17
+
18
+ private
19
+
20
+ def resource
21
+ @resource ||= resource_class.where(uid: user_params[:uid], provider: InfinumAzure.provider).or(
22
+ resource_class.where(email: user_params[:email])
23
+ ).first
24
+ end
25
+
26
+ def user_params
27
+ params.require(:user)
28
+ .permit(InfinumAzure.resource_attributes)
29
+ .merge(provider: InfinumAzure.provider)
30
+ end
31
+ end
32
+ end
33
+ 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.0'
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.0
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,6 +299,7 @@ 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