infinum_azure 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: f06378aa3fb152b879f9ad741a7bc83df51bffe7ca5f716b5769bf4a8ad20db1
4
+ data.tar.gz: 517a2708e459b1c4d4f6d1577d604c1403aaab6cfe6511b5f382e85525fd2cb9
5
+ SHA512:
6
+ metadata.gz: 7ae21e8407f07e7da940dae6aadc9e43ca5fae05fd8709725013ce09649d96ac205626315bb81e9513bf3ebc5f28550415f54c83ddc583a45f9f1ddb6ea7c954
7
+ data.tar.gz: a785f790548ef0c29310ac696e796c96be84a7c22610f7be700273bbe9935ef28702582da49834a7cdd86b6c4fdb3ab0ba5da7312c461a359415e0712a41ec55
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.rubocop.yml ADDED
@@ -0,0 +1,20 @@
1
+ AllCops:
2
+ TargetRubyVersion: 2.7
3
+
4
+ Style/StringLiterals:
5
+ Enabled: true
6
+ EnforcedStyle: single_quotes
7
+
8
+ Layout/LineLength:
9
+ Max: 120
10
+
11
+ Style/Documentation:
12
+ Enabled: false
13
+
14
+ Style/SymbolArray:
15
+ Enabled: false
16
+
17
+ Metrics/BlockLength:
18
+ Exclude:
19
+ - '**/*.rake'
20
+ - 'spec/**/*.rb'
data/CHANGELOG.md ADDED
@@ -0,0 +1,5 @@
1
+ ## [Unreleased]
2
+
3
+ ## [0.1.0] - 2023-03-15
4
+
5
+ - Initial release
@@ -0,0 +1,74 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ In the interest of fostering an open and welcoming environment, we as
6
+ contributors and maintainers pledge to making participation in our project and
7
+ our community a harassment-free experience for everyone, regardless of age, body
8
+ size, disability, ethnicity, gender identity and expression, level of experience,
9
+ nationality, personal appearance, race, religion, or sexual identity and
10
+ orientation.
11
+
12
+ ## Our Standards
13
+
14
+ Examples of behavior that contributes to creating a positive environment
15
+ include:
16
+
17
+ * Using welcoming and inclusive language
18
+ * Being respectful of differing viewpoints and experiences
19
+ * Gracefully accepting constructive criticism
20
+ * Focusing on what is best for the community
21
+ * Showing empathy towards other community members
22
+
23
+ Examples of unacceptable behavior by participants include:
24
+
25
+ * The use of sexualized language or imagery and unwelcome sexual attention or
26
+ advances
27
+ * Trolling, insulting/derogatory comments, and personal or political attacks
28
+ * Public or private harassment
29
+ * Publishing others' private information, such as a physical or electronic
30
+ address, without explicit permission
31
+ * Other conduct which could reasonably be considered inappropriate in a
32
+ professional setting
33
+
34
+ ## Our Responsibilities
35
+
36
+ Project maintainers are responsible for clarifying the standards of acceptable
37
+ behavior and are expected to take appropriate and fair corrective action in
38
+ response to any instances of unacceptable behavior.
39
+
40
+ Project maintainers have the right and responsibility to remove, edit, or
41
+ reject comments, commits, code, wiki edits, issues, and other contributions
42
+ that are not aligned to this Code of Conduct, or to ban temporarily or
43
+ permanently any contributor for other behaviors that they deem inappropriate,
44
+ threatening, offensive, or harmful.
45
+
46
+ ## Scope
47
+
48
+ This Code of Conduct applies both within project spaces and in public spaces
49
+ when an individual is representing the project or its community. Examples of
50
+ representing a project or community include using an official project e-mail
51
+ address, posting via an official social media account, or acting as an appointed
52
+ representative at an online or offline event. Representation of a project may be
53
+ further defined and clarified by project maintainers.
54
+
55
+ ## Enforcement
56
+
57
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
+ reported by contacting the project team at dajana.jeroncic@infinum.hr. All
59
+ complaints will be reviewed and investigated and will result in a response that
60
+ is deemed necessary and appropriate to the circumstances. The project team is
61
+ obligated to maintain confidentiality with regard to the reporter of an incident.
62
+ Further details of specific enforcement policies may be posted separately.
63
+
64
+ Project maintainers who do not follow or enforce the Code of Conduct in good
65
+ faith may face temporary or permanent repercussions as determined by other
66
+ members of the project's leadership.
67
+
68
+ ## Attribution
69
+
70
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
+ available at [http://contributor-covenant.org/version/1/4][version]
72
+
73
+ [homepage]: http://contributor-covenant.org
74
+ [version]: http://contributor-covenant.org/version/1/4/
data/Gemfile ADDED
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ source 'https://rubygems.org'
4
+
5
+ git_source(:github) { |repo_name| "https://github.com/#{repo_name}" }
6
+
7
+ # Specify your gem's dependencies in infinum_azure.gemspec
8
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,299 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ infinum_azure (0.1.0)
5
+ bundler
6
+ devise
7
+ dry-configurable
8
+ http
9
+ omniauth-infinum_azure (>= 0.1.6, < 2.0)
10
+ responders
11
+
12
+ GEM
13
+ remote: https://rubygems.org/
14
+ specs:
15
+ actioncable (7.0.4.3)
16
+ actionpack (= 7.0.4.3)
17
+ activesupport (= 7.0.4.3)
18
+ nio4r (~> 2.0)
19
+ websocket-driver (>= 0.6.1)
20
+ actionmailbox (7.0.4.3)
21
+ actionpack (= 7.0.4.3)
22
+ activejob (= 7.0.4.3)
23
+ activerecord (= 7.0.4.3)
24
+ activestorage (= 7.0.4.3)
25
+ activesupport (= 7.0.4.3)
26
+ mail (>= 2.7.1)
27
+ net-imap
28
+ net-pop
29
+ net-smtp
30
+ actionmailer (7.0.4.3)
31
+ actionpack (= 7.0.4.3)
32
+ actionview (= 7.0.4.3)
33
+ activejob (= 7.0.4.3)
34
+ activesupport (= 7.0.4.3)
35
+ mail (~> 2.5, >= 2.5.4)
36
+ net-imap
37
+ net-pop
38
+ net-smtp
39
+ rails-dom-testing (~> 2.0)
40
+ actionpack (7.0.4.3)
41
+ actionview (= 7.0.4.3)
42
+ activesupport (= 7.0.4.3)
43
+ rack (~> 2.0, >= 2.2.0)
44
+ rack-test (>= 0.6.3)
45
+ rails-dom-testing (~> 2.0)
46
+ rails-html-sanitizer (~> 1.0, >= 1.2.0)
47
+ actiontext (7.0.4.3)
48
+ actionpack (= 7.0.4.3)
49
+ activerecord (= 7.0.4.3)
50
+ activestorage (= 7.0.4.3)
51
+ activesupport (= 7.0.4.3)
52
+ globalid (>= 0.6.0)
53
+ nokogiri (>= 1.8.5)
54
+ actionview (7.0.4.3)
55
+ activesupport (= 7.0.4.3)
56
+ builder (~> 3.1)
57
+ erubi (~> 1.4)
58
+ rails-dom-testing (~> 2.0)
59
+ rails-html-sanitizer (~> 1.1, >= 1.2.0)
60
+ activejob (7.0.4.3)
61
+ activesupport (= 7.0.4.3)
62
+ globalid (>= 0.3.6)
63
+ activemodel (7.0.4.3)
64
+ activesupport (= 7.0.4.3)
65
+ activerecord (7.0.4.3)
66
+ activemodel (= 7.0.4.3)
67
+ activesupport (= 7.0.4.3)
68
+ activestorage (7.0.4.3)
69
+ actionpack (= 7.0.4.3)
70
+ activejob (= 7.0.4.3)
71
+ activerecord (= 7.0.4.3)
72
+ activesupport (= 7.0.4.3)
73
+ marcel (~> 1.0)
74
+ mini_mime (>= 1.1.0)
75
+ activesupport (7.0.4.3)
76
+ concurrent-ruby (~> 1.0, >= 1.0.2)
77
+ i18n (>= 1.6, < 2)
78
+ minitest (>= 5.1)
79
+ tzinfo (~> 2.0)
80
+ addressable (2.8.1)
81
+ public_suffix (>= 2.0.2, < 6.0)
82
+ bcrypt (3.1.18)
83
+ builder (3.2.4)
84
+ byebug (11.1.3)
85
+ coderay (1.1.3)
86
+ concurrent-ruby (1.2.2)
87
+ crack (0.4.5)
88
+ rexml
89
+ crass (1.0.6)
90
+ date (3.3.3)
91
+ devise (4.9.0)
92
+ bcrypt (~> 3.0)
93
+ orm_adapter (~> 0.1)
94
+ railties (>= 4.1.0)
95
+ responders
96
+ warden (~> 1.2.3)
97
+ diff-lcs (1.5.0)
98
+ docile (1.4.0)
99
+ domain_name (0.5.20190701)
100
+ unf (>= 0.0.5, < 1.0.0)
101
+ dry-configurable (1.0.1)
102
+ dry-core (~> 1.0, < 2)
103
+ zeitwerk (~> 2.6)
104
+ dry-core (1.0.0)
105
+ concurrent-ruby (~> 1.0)
106
+ zeitwerk (~> 2.6)
107
+ erubi (1.12.0)
108
+ factory_bot (6.2.1)
109
+ activesupport (>= 5.0.0)
110
+ factory_bot_rails (6.2.0)
111
+ factory_bot (~> 6.2.0)
112
+ railties (>= 5.0.0)
113
+ faker (3.1.1)
114
+ i18n (>= 1.8.11, < 2)
115
+ faraday (2.7.4)
116
+ faraday-net_http (>= 2.0, < 3.1)
117
+ ruby2_keywords (>= 0.0.4)
118
+ faraday-net_http (3.0.2)
119
+ ffi (1.15.5)
120
+ ffi-compiler (1.0.1)
121
+ ffi (>= 1.0.0)
122
+ rake
123
+ globalid (1.1.0)
124
+ activesupport (>= 5.0)
125
+ hashdiff (1.0.1)
126
+ hashie (5.0.0)
127
+ http (4.4.1)
128
+ addressable (~> 2.3)
129
+ http-cookie (~> 1.0)
130
+ http-form_data (~> 2.2)
131
+ http-parser (~> 1.2.0)
132
+ http-cookie (1.0.5)
133
+ domain_name (~> 0.5)
134
+ http-form_data (2.3.0)
135
+ http-parser (1.2.3)
136
+ ffi-compiler (>= 1.0, < 2.0)
137
+ i18n (1.12.0)
138
+ concurrent-ruby (~> 1.0)
139
+ jwt (2.7.0)
140
+ loofah (2.19.1)
141
+ crass (~> 1.0.2)
142
+ nokogiri (>= 1.5.9)
143
+ mail (2.8.1)
144
+ mini_mime (>= 0.1.1)
145
+ net-imap
146
+ net-pop
147
+ net-smtp
148
+ marcel (1.0.2)
149
+ method_source (1.0.0)
150
+ mini_mime (1.1.2)
151
+ minitest (5.18.0)
152
+ multi_xml (0.6.0)
153
+ net-imap (0.3.4)
154
+ date
155
+ net-protocol
156
+ net-pop (0.1.2)
157
+ net-protocol
158
+ net-protocol (0.2.1)
159
+ timeout
160
+ net-smtp (0.3.3)
161
+ net-protocol
162
+ nio4r (2.5.8)
163
+ nokogiri (1.14.2-arm64-darwin)
164
+ racc (~> 1.4)
165
+ oauth2 (2.0.9)
166
+ faraday (>= 0.17.3, < 3.0)
167
+ jwt (>= 1.0, < 3.0)
168
+ multi_xml (~> 0.5)
169
+ rack (>= 1.2, < 4)
170
+ snaky_hash (~> 2.0)
171
+ version_gem (~> 1.1)
172
+ omniauth (2.1.1)
173
+ hashie (>= 3.4.6)
174
+ rack (>= 2.2.3)
175
+ rack-protection
176
+ omniauth-infinum_azure (0.1.6)
177
+ omniauth-oauth2
178
+ omniauth-oauth2 (1.8.0)
179
+ oauth2 (>= 1.4, < 3)
180
+ omniauth (~> 2.0)
181
+ orm_adapter (0.5.0)
182
+ pry (0.14.2)
183
+ coderay (~> 1.1)
184
+ method_source (~> 1.0)
185
+ pry-byebug (3.10.1)
186
+ byebug (~> 11.0)
187
+ pry (>= 0.13, < 0.15)
188
+ pry-rails (0.3.9)
189
+ pry (>= 0.10.4)
190
+ public_suffix (5.0.1)
191
+ racc (1.6.2)
192
+ rack (2.2.6.4)
193
+ rack-protection (3.0.5)
194
+ rack
195
+ rack-test (2.1.0)
196
+ rack (>= 1.3)
197
+ rails (7.0.4.3)
198
+ actioncable (= 7.0.4.3)
199
+ actionmailbox (= 7.0.4.3)
200
+ actionmailer (= 7.0.4.3)
201
+ actionpack (= 7.0.4.3)
202
+ actiontext (= 7.0.4.3)
203
+ actionview (= 7.0.4.3)
204
+ activejob (= 7.0.4.3)
205
+ activemodel (= 7.0.4.3)
206
+ activerecord (= 7.0.4.3)
207
+ activestorage (= 7.0.4.3)
208
+ activesupport (= 7.0.4.3)
209
+ bundler (>= 1.15.0)
210
+ railties (= 7.0.4.3)
211
+ rails-dom-testing (2.0.3)
212
+ activesupport (>= 4.2.0)
213
+ nokogiri (>= 1.6)
214
+ rails-html-sanitizer (1.5.0)
215
+ loofah (~> 2.19, >= 2.19.1)
216
+ railties (7.0.4.3)
217
+ actionpack (= 7.0.4.3)
218
+ activesupport (= 7.0.4.3)
219
+ method_source
220
+ rake (>= 12.2)
221
+ thor (~> 1.0)
222
+ zeitwerk (~> 2.5)
223
+ rake (12.3.3)
224
+ responders (3.1.0)
225
+ actionpack (>= 5.2)
226
+ railties (>= 5.2)
227
+ rexml (3.2.5)
228
+ rspec (3.12.0)
229
+ rspec-core (~> 3.12.0)
230
+ rspec-expectations (~> 3.12.0)
231
+ rspec-mocks (~> 3.12.0)
232
+ rspec-core (3.12.1)
233
+ rspec-support (~> 3.12.0)
234
+ rspec-expectations (3.12.2)
235
+ diff-lcs (>= 1.2.0, < 2.0)
236
+ rspec-support (~> 3.12.0)
237
+ rspec-mocks (3.12.4)
238
+ diff-lcs (>= 1.2.0, < 2.0)
239
+ rspec-support (~> 3.12.0)
240
+ rspec-rails (6.0.1)
241
+ actionpack (>= 6.1)
242
+ activesupport (>= 6.1)
243
+ railties (>= 6.1)
244
+ rspec-core (~> 3.11)
245
+ rspec-expectations (~> 3.11)
246
+ rspec-mocks (~> 3.11)
247
+ rspec-support (~> 3.11)
248
+ rspec-support (3.12.0)
249
+ ruby2_keywords (0.0.5)
250
+ simplecov (0.22.0)
251
+ docile (~> 1.1)
252
+ simplecov-html (~> 0.11)
253
+ simplecov_json_formatter (~> 0.1)
254
+ simplecov-html (0.12.3)
255
+ simplecov_json_formatter (0.1.4)
256
+ snaky_hash (2.0.1)
257
+ hashie
258
+ version_gem (~> 1.1, >= 1.1.1)
259
+ sqlite3 (1.6.1-arm64-darwin)
260
+ thor (1.2.1)
261
+ timeout (0.3.2)
262
+ tzinfo (2.0.6)
263
+ concurrent-ruby (~> 1.0)
264
+ unf (0.1.4)
265
+ unf_ext
266
+ unf_ext (0.0.8.2)
267
+ version_gem (1.1.1)
268
+ warden (1.2.9)
269
+ rack (>= 2.0.9)
270
+ webmock (3.18.1)
271
+ addressable (>= 2.8.0)
272
+ crack (>= 0.3.2)
273
+ hashdiff (>= 0.4.0, < 2.0.0)
274
+ websocket-driver (0.7.5)
275
+ websocket-extensions (>= 0.1.0)
276
+ websocket-extensions (0.1.5)
277
+ zeitwerk (2.6.7)
278
+
279
+ PLATFORMS
280
+ arm64-darwin-21
281
+
282
+ DEPENDENCIES
283
+ bundler
284
+ factory_bot_rails
285
+ faker
286
+ infinum_azure!
287
+ pry
288
+ pry-byebug
289
+ pry-rails
290
+ rails (~> 7.0)
291
+ rake (~> 12.0)
292
+ rspec (~> 3.0)
293
+ rspec-rails
294
+ simplecov
295
+ sqlite3
296
+ webmock
297
+
298
+ BUNDLED WITH
299
+ 2.4.6
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2023 Infinum
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,107 @@
1
+ # InfinumAzure Engine
2
+
3
+ InfinumAzure Engine is gem for resource authentication with Infinum Azure AD server.
4
+
5
+ ## Table of Contents
6
+ - [Installation](#installation)
7
+ - [Dependencies](#dependencies)
8
+ - [Configuration](#configuration)
9
+ * [InfinumAzure](#infinumazure)
10
+ * [Secrets](#secrets)
11
+ - [Usage](#usage)
12
+
13
+ ## Installation
14
+
15
+ Add this line to your application's Gemfile:
16
+
17
+ ```ruby
18
+ gem 'infinum_azure'
19
+ ```
20
+
21
+ And then execute:
22
+
23
+ $ bundle
24
+
25
+ Or install it yourself as:
26
+
27
+ $ gem install infinum_azure
28
+
29
+ ## Dependencies
30
+
31
+ * [Devise](https://github.com/plataformatec/devise)
32
+ * [Dry configurable](https://github.com/dry-rb/dry-configurable)
33
+ * [Http](https://github.com/httprb/http)
34
+ * [Omniauth::InfinumAzure](https://github.com/infinum/ruby-infinum-azure-omniauth)
35
+
36
+ ## Configuration
37
+
38
+ ### InfinumAzure
39
+
40
+ ```ruby
41
+ # config/initializers/infinum_azure.rb
42
+
43
+ InfinumAzure.configure do |config|
44
+ config.service_name = 'Revisor'
45
+ config.resource_name = 'User'
46
+ end
47
+ ```
48
+
49
+ Configuration options:
50
+ * Service name - name of application
51
+ * Resource name - name of resource on whom authentication is being done
52
+
53
+ ### Secrets
54
+
55
+ Needed secrets:
56
+
57
+ ```ruby
58
+ # config/secrets.yml
59
+
60
+ infinum_azure:
61
+ client_id: 'client_id_from_InfinumAzure'
62
+ client_secret: 'client_secret_from_InfinumAzure'
63
+ tenant: 'InfinumAzure_tenant'
64
+ ```
65
+
66
+ ## Usage
67
+
68
+ 1. Add columns to resource via migration.
69
+
70
+ <b>Required columns:</b> email, uid and provider <br />
71
+ <b>Optional columns:</b> name
72
+
73
+ 2. Add following rows to resource model:
74
+
75
+ ```ruby
76
+ devise :omniauthable, omniauth_providers: [:infinum_azure]
77
+ ```
78
+
79
+ 3. Use devise's method `#authenticate_user!` to authenticate users on API endpoints
80
+
81
+ ```ruby
82
+ class AuthenticatedController < ApplicationController
83
+ before_action :authenticate_user!
84
+ end
85
+ ```
86
+
87
+ 4. In case your model is named `User`, you can use the `#user_infinum_azure_omniauth_authorize_path` for the login button:
88
+
89
+ ```ruby
90
+ button_to 'Login', user_infinum_azure_omniauth_authorize_path
91
+ ```
92
+
93
+ 5. In case you want logging out, you can use `#infinum_azure_logout_path` for logging out of Infinum Azure and your app:
94
+
95
+ ```ruby
96
+ link_to 'Logout', infinum_azure_logout_path
97
+ ```
98
+
99
+ or, if you just want to clear the session, but not log out of Infinum Azure, you can use:
100
+
101
+ ```ruby
102
+ link_to 'Logout', logout_path
103
+ ```
104
+
105
+ ## License
106
+
107
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,21 @@
1
+ # frozen_string_literal: true
2
+
3
+ begin
4
+ require 'bundler/setup'
5
+ rescue LoadError
6
+ puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
7
+ end
8
+ APP_RAKEFILE = File.expand_path('spec/rails_app/Rakefile', __dir__)
9
+ load 'rails/tasks/engine.rake'
10
+
11
+ load 'rails/tasks/statistics.rake'
12
+
13
+ require 'bundler/gem_tasks'
14
+
15
+ require 'rspec/core/rake_task'
16
+
17
+ RSpec::Core::RakeTask.new(:spec) do |spec|
18
+ spec.pattern = 'spec/**/*spec.rb'
19
+ end
20
+
21
+ task default: :spec
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ module InfinumAzure
4
+ module Api
5
+ class BaseController < ActionController::Base
6
+ protect_from_forgery with: :null_session
7
+ respond_to :json
8
+
9
+ delegate :resource_name, :resource_class, to: InfinumAzure
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,14 @@
1
+ # frozen_string_literal: true
2
+
3
+ module InfinumAzure
4
+ class ApplicationController < ActionController::Base
5
+ protect_from_forgery with: :exception
6
+ respond_to :html
7
+
8
+ delegate :resource_name, :resource_class, to: InfinumAzure
9
+
10
+ def current_resource
11
+ method("current_#{resource_name.underscore}").call
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,31 @@
1
+ # frozen_string_literal: true
2
+
3
+ module InfinumAzure
4
+ module Resources
5
+ class OmniauthCallbacksController < Devise::OmniauthCallbacksController
6
+ def infinum_azure
7
+ resource = InfinumAzure::Resources::Finder.from_omniauth_by_email(omniauth['info']['email'])
8
+
9
+ if resource
10
+ flash[:notice] = I18n.t 'devise.omniauth_callbacks.success', kind: 'Azure'
11
+ sign_in_and_redirect resource, event: :authentication
12
+ else
13
+ flash[:notice] = 'You do not have permission to access this application.'
14
+ redirect_to root_path
15
+ end
16
+ end
17
+
18
+ def failure
19
+ set_flash_message! :alert, :failure, kind: OmniAuth::Utils.camelize(failed_strategy.name),
20
+ reason: failure_message
21
+ redirect_to root_path
22
+ end
23
+
24
+ private
25
+
26
+ def omniauth
27
+ @omniauth ||= request.env['omniauth.auth']
28
+ end
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+
3
+ module InfinumAzure
4
+ class ResourcesController < InfinumAzure::ApplicationController
5
+ def passthru
6
+ render status: 404, plain: 'Not found. Logout passthru.'
7
+ end
8
+
9
+ def destroy
10
+ sign_out current_resource
11
+
12
+ redirect_to root_path
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ module InfinumAzure
4
+ class ApplicationRecord < ActiveRecord::Base
5
+ self.abstract_class = true
6
+ end
7
+ end
@@ -0,0 +1,18 @@
1
+ # frozen_string_literal: true
2
+
3
+ module InfinumAzure
4
+ module Resources
5
+ class Finder
6
+ def self.from_omniauth(auth)
7
+ InfinumAzure.resource_class.find_by(provider: auth.provider, uid: auth.uid)
8
+ end
9
+
10
+ # this is a temporary method which won't be used in subsequent versions
11
+ # the user data first has to be migrated (update provider to azure and uid from B2C)
12
+ # in the meantime, we'll use a lowercased email as a unique identifier
13
+ def self.from_omniauth_by_email(email)
14
+ InfinumAzure.resource_class.find_for_authentication(email: email)
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,22 @@
1
+ Devise.setup do |config|
2
+ require 'devise/orm/active_record'
3
+
4
+ config.case_insensitive_keys = [:email]
5
+ config.strip_whitespace_keys = [:email]
6
+
7
+ config.skip_session_storage = [:http_auth]
8
+
9
+ config.stretches = Rails.env.test? ? 1 : 11
10
+
11
+ config.reconfirmable = true
12
+
13
+ config.expire_all_remember_me_on_sign_out = true
14
+
15
+ config.email_regexp = /\A[^@\s]+@[^@\s]+\z/
16
+
17
+ config.sign_out_via = :get
18
+
19
+ # ==> OmniAuth
20
+ config.omniauth :infinum_azure, InfinumAzure.client_id, InfinumAzure.client_secret,
21
+ client_options: { tenant: InfinumAzure.tenant }
22
+ end
data/config/routes.rb ADDED
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ Rails.application.routes.draw do
4
+ get '/users/auth/infinum_azure/logout', to: 'infinum_azure/resources#passthru', as: :infinum_azure_logout
5
+ get '/users/auth/logout', to: 'infinum_azure/resources#destroy', as: :logout
6
+
7
+ devise_for InfinumAzure.resource_name.pluralize.underscore, controllers: {
8
+ omniauth_callbacks: 'infinum_azure/resources/omniauth_callbacks'
9
+ }
10
+ end
@@ -0,0 +1,53 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'lib/infinum_azure/version'
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = 'infinum_azure'
7
+ spec.version = InfinumAzure::VERSION
8
+ spec.authors = ['Marko Ćilimković']
9
+ spec.email = ['marko.cilimkovic@infinum.hr']
10
+
11
+ spec.summary = 'Authentication mechanism for Rails apps with devise via OAuth2'
12
+ spec.homepage = 'https://github.com/infinum/rails-infinum-azure-engine'
13
+ spec.license = 'MIT'
14
+ spec.required_ruby_version = '>= 2.7.0'
15
+
16
+ spec.metadata['allowed_push_host'] = 'https://rubygems.org'
17
+
18
+ spec.metadata['homepage_uri'] = spec.homepage
19
+ spec.metadata['source_code_uri'] = 'https://github.com/infinum/rails-infinum-azure-engine'
20
+ spec.metadata['changelog_uri'] = 'https://github.com/infinum/rails-infinum-azure-engine/blob/master/CHANGELOG.md'
21
+
22
+ # Specify which files should be added to the gem when it is released.
23
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
24
+ spec.files = Dir.chdir(__dir__) do
25
+ `git ls-files -z`.split("\x0").reject do |f|
26
+ (f == __FILE__) || f.match(%r{\A(?:(?:bin|test|spec|features)/|\.(?:git|circleci)|appveyor)})
27
+ end
28
+ end
29
+ spec.bindir = 'exe'
30
+ spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
31
+ spec.require_paths = ['lib']
32
+
33
+ spec.add_development_dependency 'bundler'
34
+ spec.add_development_dependency 'factory_bot_rails'
35
+ spec.add_development_dependency 'faker'
36
+ spec.add_development_dependency 'pry'
37
+ spec.add_development_dependency 'pry-byebug'
38
+ spec.add_development_dependency 'pry-rails'
39
+ spec.add_development_dependency 'rails', '~> 7.0'
40
+ spec.add_development_dependency 'rake', '~> 12.0'
41
+ spec.add_development_dependency 'rspec', '~> 3.0'
42
+ spec.add_development_dependency 'rspec-rails'
43
+ spec.add_development_dependency 'simplecov'
44
+ spec.add_development_dependency 'sqlite3'
45
+ spec.add_development_dependency 'webmock'
46
+
47
+ spec.add_dependency 'bundler'
48
+ spec.add_dependency 'devise'
49
+ spec.add_dependency 'dry-configurable'
50
+ spec.add_dependency 'http'
51
+ spec.add_dependency 'omniauth-infinum_azure', '>= 0.1.6', '< 2.0'
52
+ spec.add_dependency 'responders'
53
+ end
@@ -0,0 +1,6 @@
1
+ # frozen_string_literal: true
2
+
3
+ module InfinumAzure
4
+ class Engine < ::Rails::Engine
5
+ end
6
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module InfinumAzure
4
+ VERSION = '0.1.0'
5
+ end
@@ -0,0 +1,35 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'omniauth/infinum_azure'
4
+ require 'infinum_azure/version'
5
+ require 'infinum_azure/engine'
6
+ require 'dry-configurable'
7
+ require 'devise'
8
+ require 'http'
9
+
10
+ module InfinumAzure
11
+ extend Dry::Configurable
12
+
13
+ setting :service_name, reader: true
14
+ setting :resource_name, default: 'User', reader: true
15
+
16
+ def self.resource_class
17
+ resource_name.constantize
18
+ end
19
+
20
+ def self.client_id
21
+ dig_secret(:client_id)
22
+ end
23
+
24
+ def self.client_secret
25
+ dig_secret(:client_secret)
26
+ end
27
+
28
+ def self.tenant
29
+ dig_secret(:tenant)
30
+ end
31
+
32
+ def self.dig_secret(key)
33
+ Rails.application.secrets.dig(:infinum_azure, key)
34
+ end
35
+ end
metadata ADDED
@@ -0,0 +1,340 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: infinum_azure
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Marko Ćilimković
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2023-03-15 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: factory_bot_rails
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: faker
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: pry
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: pry-byebug
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: pry-rails
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: rails
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: '7.0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: '7.0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: rake
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - "~>"
116
+ - !ruby/object:Gem::Version
117
+ version: '12.0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - "~>"
123
+ - !ruby/object:Gem::Version
124
+ version: '12.0'
125
+ - !ruby/object:Gem::Dependency
126
+ name: rspec
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - "~>"
130
+ - !ruby/object:Gem::Version
131
+ version: '3.0'
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - "~>"
137
+ - !ruby/object:Gem::Version
138
+ version: '3.0'
139
+ - !ruby/object:Gem::Dependency
140
+ name: rspec-rails
141
+ requirement: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - ">="
144
+ - !ruby/object:Gem::Version
145
+ version: '0'
146
+ type: :development
147
+ prerelease: false
148
+ version_requirements: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - ">="
151
+ - !ruby/object:Gem::Version
152
+ version: '0'
153
+ - !ruby/object:Gem::Dependency
154
+ name: simplecov
155
+ requirement: !ruby/object:Gem::Requirement
156
+ requirements:
157
+ - - ">="
158
+ - !ruby/object:Gem::Version
159
+ version: '0'
160
+ type: :development
161
+ prerelease: false
162
+ version_requirements: !ruby/object:Gem::Requirement
163
+ requirements:
164
+ - - ">="
165
+ - !ruby/object:Gem::Version
166
+ version: '0'
167
+ - !ruby/object:Gem::Dependency
168
+ name: sqlite3
169
+ requirement: !ruby/object:Gem::Requirement
170
+ requirements:
171
+ - - ">="
172
+ - !ruby/object:Gem::Version
173
+ version: '0'
174
+ type: :development
175
+ prerelease: false
176
+ version_requirements: !ruby/object:Gem::Requirement
177
+ requirements:
178
+ - - ">="
179
+ - !ruby/object:Gem::Version
180
+ version: '0'
181
+ - !ruby/object:Gem::Dependency
182
+ name: webmock
183
+ requirement: !ruby/object:Gem::Requirement
184
+ requirements:
185
+ - - ">="
186
+ - !ruby/object:Gem::Version
187
+ version: '0'
188
+ type: :development
189
+ prerelease: false
190
+ version_requirements: !ruby/object:Gem::Requirement
191
+ requirements:
192
+ - - ">="
193
+ - !ruby/object:Gem::Version
194
+ version: '0'
195
+ - !ruby/object:Gem::Dependency
196
+ name: bundler
197
+ requirement: !ruby/object:Gem::Requirement
198
+ requirements:
199
+ - - ">="
200
+ - !ruby/object:Gem::Version
201
+ version: '0'
202
+ type: :runtime
203
+ prerelease: false
204
+ version_requirements: !ruby/object:Gem::Requirement
205
+ requirements:
206
+ - - ">="
207
+ - !ruby/object:Gem::Version
208
+ version: '0'
209
+ - !ruby/object:Gem::Dependency
210
+ name: devise
211
+ requirement: !ruby/object:Gem::Requirement
212
+ requirements:
213
+ - - ">="
214
+ - !ruby/object:Gem::Version
215
+ version: '0'
216
+ type: :runtime
217
+ prerelease: false
218
+ version_requirements: !ruby/object:Gem::Requirement
219
+ requirements:
220
+ - - ">="
221
+ - !ruby/object:Gem::Version
222
+ version: '0'
223
+ - !ruby/object:Gem::Dependency
224
+ name: dry-configurable
225
+ requirement: !ruby/object:Gem::Requirement
226
+ requirements:
227
+ - - ">="
228
+ - !ruby/object:Gem::Version
229
+ version: '0'
230
+ type: :runtime
231
+ prerelease: false
232
+ version_requirements: !ruby/object:Gem::Requirement
233
+ requirements:
234
+ - - ">="
235
+ - !ruby/object:Gem::Version
236
+ version: '0'
237
+ - !ruby/object:Gem::Dependency
238
+ name: http
239
+ requirement: !ruby/object:Gem::Requirement
240
+ requirements:
241
+ - - ">="
242
+ - !ruby/object:Gem::Version
243
+ version: '0'
244
+ type: :runtime
245
+ prerelease: false
246
+ version_requirements: !ruby/object:Gem::Requirement
247
+ requirements:
248
+ - - ">="
249
+ - !ruby/object:Gem::Version
250
+ version: '0'
251
+ - !ruby/object:Gem::Dependency
252
+ name: omniauth-infinum_azure
253
+ requirement: !ruby/object:Gem::Requirement
254
+ requirements:
255
+ - - ">="
256
+ - !ruby/object:Gem::Version
257
+ version: 0.1.6
258
+ - - "<"
259
+ - !ruby/object:Gem::Version
260
+ version: '2.0'
261
+ type: :runtime
262
+ prerelease: false
263
+ version_requirements: !ruby/object:Gem::Requirement
264
+ requirements:
265
+ - - ">="
266
+ - !ruby/object:Gem::Version
267
+ version: 0.1.6
268
+ - - "<"
269
+ - !ruby/object:Gem::Version
270
+ version: '2.0'
271
+ - !ruby/object:Gem::Dependency
272
+ name: responders
273
+ requirement: !ruby/object:Gem::Requirement
274
+ requirements:
275
+ - - ">="
276
+ - !ruby/object:Gem::Version
277
+ version: '0'
278
+ type: :runtime
279
+ prerelease: false
280
+ version_requirements: !ruby/object:Gem::Requirement
281
+ requirements:
282
+ - - ">="
283
+ - !ruby/object:Gem::Version
284
+ version: '0'
285
+ description:
286
+ email:
287
+ - marko.cilimkovic@infinum.hr
288
+ executables: []
289
+ extensions: []
290
+ extra_rdoc_files: []
291
+ files:
292
+ - ".rspec"
293
+ - ".rubocop.yml"
294
+ - CHANGELOG.md
295
+ - CODE_OF_CONDUCT.md
296
+ - Gemfile
297
+ - Gemfile.lock
298
+ - LICENSE
299
+ - README.md
300
+ - Rakefile
301
+ - app/controllers/infinum_azure/api/base_controller.rb
302
+ - app/controllers/infinum_azure/application_controller.rb
303
+ - app/controllers/infinum_azure/resources/omniauth_callbacks_controller.rb
304
+ - app/controllers/infinum_azure/resources_controller.rb
305
+ - app/models/infinum_azure/application_record.rb
306
+ - app/services/infinum_azure/resources/finder.rb
307
+ - config/initializers/devise.rb
308
+ - config/routes.rb
309
+ - infinum_azure.gemspec
310
+ - lib/infinum_azure.rb
311
+ - lib/infinum_azure/engine.rb
312
+ - lib/infinum_azure/version.rb
313
+ homepage: https://github.com/infinum/rails-infinum-azure-engine
314
+ licenses:
315
+ - MIT
316
+ metadata:
317
+ allowed_push_host: https://rubygems.org
318
+ homepage_uri: https://github.com/infinum/rails-infinum-azure-engine
319
+ source_code_uri: https://github.com/infinum/rails-infinum-azure-engine
320
+ changelog_uri: https://github.com/infinum/rails-infinum-azure-engine/blob/master/CHANGELOG.md
321
+ post_install_message:
322
+ rdoc_options: []
323
+ require_paths:
324
+ - lib
325
+ required_ruby_version: !ruby/object:Gem::Requirement
326
+ requirements:
327
+ - - ">="
328
+ - !ruby/object:Gem::Version
329
+ version: 2.7.0
330
+ required_rubygems_version: !ruby/object:Gem::Requirement
331
+ requirements:
332
+ - - ">="
333
+ - !ruby/object:Gem::Version
334
+ version: '0'
335
+ requirements: []
336
+ rubygems_version: 3.3.7
337
+ signing_key:
338
+ specification_version: 4
339
+ summary: Authentication mechanism for Rails apps with devise via OAuth2
340
+ test_files: []