strongmind-auth 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/README.md +18 -0
- data/Rakefile +8 -0
- data/app/assets/config/strongmind_auth_manifest.js +0 -0
- data/app/assets/stylesheets/strongmind/auth/application.css +15 -0
- data/app/controllers/logins_controller.rb +7 -0
- data/app/controllers/users/omniauth_callbacks_controller.rb +28 -0
- data/app/helpers/strongmind/auth/application_helper.rb +6 -0
- data/app/jobs/rails/auth/application_job.rb +6 -0
- data/app/mailers/rails/auth/application_mailer.rb +8 -0
- data/app/models/user_base.rb +31 -0
- data/app/views/layouts/strongmind/auth/application.html.erb +15 -0
- data/app/views/logins/index.html.erb +38 -0
- data/config/initializers/devise.rb +330 -0
- data/config/routes.rb +18 -0
- data/lib/generators/strongmind/USAGE +6 -0
- data/lib/generators/strongmind/install_generator.rb +56 -0
- data/lib/generators/strongmind/templates/add_uid_to_user.rb +8 -0
- data/lib/generators/strongmind/templates/user.rb +2 -0
- data/lib/strongmind/auth/engine.rb +6 -0
- data/lib/strongmind/auth/version.rb +5 -0
- data/lib/strongmind/auth.rb +8 -0
- data/lib/tasks/rails/auth_tasks.rake +4 -0
- data/lib/tasks/strongmind/auth_tasks.rake +4 -0
- metadata +152 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 9bfec369dd5d286f52bf4d92ceb70f98c982e48f285f4a4aec6dd70b692d9cfe
|
4
|
+
data.tar.gz: 63e592b1ea89f506d2b08a67abf796c9ba1d9330128ea2b08a4d3207d1da2fb7
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: de89b183da5f424ea38523f36753fd8ee828031b714426e58df4b58da1c72adcd4d6ed0185da57168d49160a063cce0da56be5dccd33858af29083d921778b2a
|
7
|
+
data.tar.gz: 7f6eb8fb6151a463fa98138200ae5a53ecc08a2a16328b724d6246cbbf2e13e590b9062294a347ea475ab654c9a075357d887ebf2ca081539a326e9e815720a1
|
data/README.md
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
# Rails Authentication
|
2
|
+
|
3
|
+
Ruby gem for authentication in a rails app
|
4
|
+
|
5
|
+
## Usage
|
6
|
+
|
7
|
+
How to use my plugin.
|
8
|
+
|
9
|
+
## Installation
|
10
|
+
|
11
|
+
1. `rails new app_name --tailwind`
|
12
|
+
1. Add strongmind-auth to gem file and bundle
|
13
|
+
1. `rails g strongmind:install`
|
14
|
+
1. Move app root to authenticated root in routes
|
15
|
+
1. Add IDENTITY_CLIENT_ID and IDENTITY_CLIENT_SECRET values to .env
|
16
|
+
1. `bundle`
|
17
|
+
1. `rails dev:cache`
|
18
|
+
1. `bin/dev`
|
data/Rakefile
ADDED
File without changes
|
@@ -0,0 +1,15 @@
|
|
1
|
+
/*
|
2
|
+
* This is a manifest file that'll be compiled into application.css, which will include all the files
|
3
|
+
* listed below.
|
4
|
+
*
|
5
|
+
* Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
|
6
|
+
* or any plugin's vendor/assets/stylesheets directory can be referenced here using a relative path.
|
7
|
+
*
|
8
|
+
* You're free to add application-wide styles to this file and they'll appear at the bottom of the
|
9
|
+
* compiled file so the styles you add here take precedence over styles defined in any other CSS/SCSS
|
10
|
+
* files in this directory. Styles in this file should be added after the last require_* statement.
|
11
|
+
* It is generally better to create a new file per style scope.
|
12
|
+
*
|
13
|
+
*= require_tree .
|
14
|
+
*= require_self
|
15
|
+
*/
|
@@ -0,0 +1,28 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Users
|
4
|
+
|
5
|
+
class OmniauthCallbacksController < Devise::OmniauthCallbacksController
|
6
|
+
|
7
|
+
def strongmind
|
8
|
+
auth = request.env['omniauth.auth']
|
9
|
+
User.auth_token_cache = auth
|
10
|
+
@user = User.from_omniauth(auth)
|
11
|
+
|
12
|
+
session[:refresh_token] = request.env['omniauth.auth'].credentials['refresh_token']
|
13
|
+
flash.delete(:notice)
|
14
|
+
|
15
|
+
if @user.persisted?
|
16
|
+
sign_in_and_redirect @user, event: :authentication # this will throw if @user is not activated
|
17
|
+
else
|
18
|
+
session['devise.openid_connect_data'] = { uid: @user.identity_id } # Removing extra as it can overflow some session stores
|
19
|
+
sign_in_and_redirect @user
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
def failure
|
24
|
+
redirect_to root_url
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
class UserBase < ApplicationRecord
|
2
|
+
devise :database_authenticatable, :registerable,
|
3
|
+
:recoverable, :rememberable, :validatable,
|
4
|
+
:omniauthable, :omniauth_providers => %i[strongmind]
|
5
|
+
|
6
|
+
self.table_name = 'users'
|
7
|
+
|
8
|
+
def self.from_omniauth(auth)
|
9
|
+
|
10
|
+
email = auth.extra.raw_info['http://schemas.xmlsoap.org/ws/2005/05/identity/claims/emailaddress']
|
11
|
+
user = User.where(uid: auth.uid).first
|
12
|
+
if user.nil?
|
13
|
+
user ||= User.create!(uid: auth.uid, email: email, password: Devise.friendly_token[0, 20])
|
14
|
+
end
|
15
|
+
user
|
16
|
+
end
|
17
|
+
|
18
|
+
def self.auth_token_cache=(auth)
|
19
|
+
Rails.cache.write(auth.uid,
|
20
|
+
{
|
21
|
+
id_token: auth.credentials.id_token,
|
22
|
+
access_token: auth.credentials.token,
|
23
|
+
refresh_token: auth.credentials.refresh_token
|
24
|
+
}
|
25
|
+
)
|
26
|
+
end
|
27
|
+
|
28
|
+
def auth_token_cache
|
29
|
+
Rails.cache.read(uid)
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
<style>
|
2
|
+
/* Hide login error */
|
3
|
+
.sm-alert-error {
|
4
|
+
display: none;
|
5
|
+
}
|
6
|
+
|
7
|
+
#header .sm-loader img {
|
8
|
+
visibility: hidden;
|
9
|
+
}
|
10
|
+
|
11
|
+
#loading .sm-navbar-container {
|
12
|
+
top: 30vh;
|
13
|
+
}
|
14
|
+
|
15
|
+
#loading .sm-navbar-container .sm-loader {
|
16
|
+
background: rgb(244, 244, 244);
|
17
|
+
height: 120px;
|
18
|
+
}
|
19
|
+
</style>
|
20
|
+
<%= button_to 'Sign in with StrongMind', '/users/auth/strongmind', style: 'display:none' %>
|
21
|
+
<script type="text/javascript">
|
22
|
+
function submitForm() {
|
23
|
+
document.forms[0].submit();
|
24
|
+
}
|
25
|
+
|
26
|
+
// Submit the form on load
|
27
|
+
window.addEventListener("load", (event) => {
|
28
|
+
submitForm();
|
29
|
+
});
|
30
|
+
|
31
|
+
</script>
|
32
|
+
<div id="loading" class="w-full items-center justify-center">
|
33
|
+
<div class="sm-navbar-container">
|
34
|
+
<div class="sm-loader bg-[#151515] h-[62px] p-4">
|
35
|
+
<img src="https://prod-backpack-ui.strongmind.com/assets/images/strongmind-loader.svg">
|
36
|
+
</div>
|
37
|
+
</div>
|
38
|
+
</div>
|
@@ -0,0 +1,330 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
return if defined? Rails::Generators
|
4
|
+
|
5
|
+
# Assuming you have not yet modified this file, each configuration option below
|
6
|
+
# is set to its default value. Note that some are commented out while others
|
7
|
+
# are not: uncommented lines are intended to protect your configuration from
|
8
|
+
# breaking changes in upgrades (i.e., in the event that future versions of
|
9
|
+
# Devise change the default values for those options).
|
10
|
+
#
|
11
|
+
# Use this hook to configure devise mailer, warden hooks and so forth.
|
12
|
+
# Many of these configuration options can be set straight in your model.
|
13
|
+
Devise.setup do |config|
|
14
|
+
# The secret key used by Devise. Devise uses this key to generate
|
15
|
+
# random tokens. Changing this key will render invalid all existing
|
16
|
+
# confirmation, reset password and unlock tokens in the database.
|
17
|
+
# Devise will use the `secret_key_base` as its `secret_key`
|
18
|
+
# by default. You can change it below and use your own secret key.
|
19
|
+
config.secret_key = ENV['DEVISE_SECRET_KEY'] || '<%= SecureRandom.hex(64) %>'
|
20
|
+
|
21
|
+
# ==> Controller configuration
|
22
|
+
# Configure the parent class to the devise controllers.
|
23
|
+
# config.parent_controller = 'DeviseController'
|
24
|
+
|
25
|
+
# ==> Mailer Configuration
|
26
|
+
# Configure the e-mail address which will be shown in Devise::Mailer,
|
27
|
+
# note that it will be overwritten if you use your own mailer class
|
28
|
+
# with default "from" parameter.
|
29
|
+
config.mailer_sender = 'please-change-me-at-config-initializers-devise@example.com'
|
30
|
+
|
31
|
+
# Configure the class responsible to send e-mails.
|
32
|
+
# config.mailer = 'Devise::Mailer'
|
33
|
+
|
34
|
+
# Configure the parent class responsible to send e-mails.
|
35
|
+
# config.parent_mailer = 'ActionMailer::Base'
|
36
|
+
|
37
|
+
# ==> ORM configuration
|
38
|
+
# Load and configure the ORM. Supports :active_record (default) and
|
39
|
+
# :mongoid (bson_ext recommended) by default. Other ORMs may be
|
40
|
+
# available as additional gems.
|
41
|
+
require 'devise/orm/active_record'
|
42
|
+
|
43
|
+
# ==> Configuration for any authentication mechanism
|
44
|
+
# Configure which keys are used when authenticating a user. The default is
|
45
|
+
# just :email. You can configure it to use [:username, :subdomain], so for
|
46
|
+
# authenticating a user, both parameters are required. Remember that those
|
47
|
+
# parameters are used only when authenticating and not when retrieving from
|
48
|
+
# session. If you need permissions, you should implement that in a before filter.
|
49
|
+
# You can also supply a hash where the value is a boolean determining whether
|
50
|
+
# or not authentication should be aborted when the value is not present.
|
51
|
+
# config.authentication_keys = [:email]
|
52
|
+
|
53
|
+
# Configure parameters from the request object used for authentication. Each entry
|
54
|
+
# given should be a request method and it will automatically be passed to the
|
55
|
+
# find_for_authentication method and considered in your model lookup. For instance,
|
56
|
+
# if you set :request_keys to [:subdomain], :subdomain will be used on authentication.
|
57
|
+
# The same considerations mentioned for authentication_keys also apply to request_keys.
|
58
|
+
# config.request_keys = []
|
59
|
+
|
60
|
+
# Configure which authentication keys should be case-insensitive.
|
61
|
+
# These keys will be downcased upon creating or modifying a user and when used
|
62
|
+
# to authenticate or find a user. Default is :email.
|
63
|
+
config.case_insensitive_keys = [:email]
|
64
|
+
|
65
|
+
# Configure which authentication keys should have whitespace stripped.
|
66
|
+
# These keys will have whitespace before and after removed upon creating or
|
67
|
+
# modifying a user and when used to authenticate or find a user. Default is :email.
|
68
|
+
config.strip_whitespace_keys = [:email]
|
69
|
+
|
70
|
+
# Tell if authentication through request.params is enabled. True by default.
|
71
|
+
# It can be set to an array that will enable params authentication only for the
|
72
|
+
# given strategies, for example, `config.params_authenticatable = [:database]` will
|
73
|
+
# enable it only for database (email + password) authentication.
|
74
|
+
# config.params_authenticatable = true
|
75
|
+
|
76
|
+
# Tell if authentication through HTTP Auth is enabled. False by default.
|
77
|
+
# It can be set to an array that will enable http authentication only for the
|
78
|
+
# given strategies, for example, `config.http_authenticatable = [:database]` will
|
79
|
+
# enable it only for database authentication.
|
80
|
+
# For API-only applications to support authentication "out-of-the-box", you will likely want to
|
81
|
+
# enable this with :database unless you are using a custom strategy.
|
82
|
+
# The supported strategies are:
|
83
|
+
# :database = Support basic authentication with authentication key + password
|
84
|
+
# config.http_authenticatable = false
|
85
|
+
|
86
|
+
# If 401 status code should be returned for AJAX requests. True by default.
|
87
|
+
# config.http_authenticatable_on_xhr = true
|
88
|
+
|
89
|
+
# The realm used in Http Basic Authentication. 'Application' by default.
|
90
|
+
# config.http_authentication_realm = 'Application'
|
91
|
+
|
92
|
+
# It will change confirmation, password recovery and other workflows
|
93
|
+
# to behave the same regardless if the e-mail provided was right or wrong.
|
94
|
+
# Does not affect registerable.
|
95
|
+
# config.paranoid = true
|
96
|
+
|
97
|
+
# By default Devise will store the user in session. You can skip storage for
|
98
|
+
# particular strategies by setting this option.
|
99
|
+
# Notice that if you are skipping storage for all authentication paths, you
|
100
|
+
# may want to disable generating routes to Devise's sessions controller by
|
101
|
+
# passing skip: :sessions to `devise_for` in your config/routes.rb
|
102
|
+
config.skip_session_storage = [:http_auth]
|
103
|
+
|
104
|
+
# By default, Devise cleans up the CSRF token on authentication to
|
105
|
+
# avoid CSRF token fixation attacks. This means that, when using AJAX
|
106
|
+
# requests for sign in and sign up, you need to get a new CSRF token
|
107
|
+
# from the server. You can disable this option at your own risk.
|
108
|
+
# config.clean_up_csrf_token_on_authentication = true
|
109
|
+
|
110
|
+
# When false, Devise will not attempt to reload routes on eager load.
|
111
|
+
# This can reduce the time taken to boot the app but if your application
|
112
|
+
# requires the Devise mappings to be loaded during boot time the application
|
113
|
+
# won't boot properly.
|
114
|
+
# config.reload_routes = true
|
115
|
+
|
116
|
+
# ==> Configuration for :database_authenticatable
|
117
|
+
# For bcrypt, this is the cost for hashing the password and defaults to 12. If
|
118
|
+
# using other algorithms, it sets how many times you want the password to be hashed.
|
119
|
+
# The number of stretches used for generating the hashed password are stored
|
120
|
+
# with the hashed password. This allows you to change the stretches without
|
121
|
+
# invalidating existing passwords.
|
122
|
+
#
|
123
|
+
# Limiting the stretches to just one in testing will increase the performance of
|
124
|
+
# your test suite dramatically. However, it is STRONGLY RECOMMENDED to not use
|
125
|
+
# a value less than 10 in other environments. Note that, for bcrypt (the default
|
126
|
+
# algorithm), the cost increases exponentially with the number of stretches (e.g.
|
127
|
+
# a value of 20 is already extremely slow: approx. 60 seconds for 1 calculation).
|
128
|
+
config.stretches = Rails.env.test? ? 1 : 12
|
129
|
+
|
130
|
+
# Set up a pepper to generate the hashed password.
|
131
|
+
# config.pepper = '<%= SecureRandom.hex(64) %>'
|
132
|
+
|
133
|
+
# Send a notification to the original email when the user's email is changed.
|
134
|
+
# config.send_email_changed_notification = false
|
135
|
+
|
136
|
+
# Send a notification email when the user's password is changed.
|
137
|
+
# config.send_password_change_notification = false
|
138
|
+
|
139
|
+
# ==> Configuration for :confirmable
|
140
|
+
# A period that the user is allowed to access the website even without
|
141
|
+
# confirming their account. For instance, if set to 2.days, the user will be
|
142
|
+
# able to access the website for two days without confirming their account,
|
143
|
+
# access will be blocked just in the third day.
|
144
|
+
# You can also set it to nil, which will allow the user to access the website
|
145
|
+
# without confirming their account.
|
146
|
+
# Default is 0.days, meaning the user cannot access the website without
|
147
|
+
# confirming their account.
|
148
|
+
# config.allow_unconfirmed_access_for = 2.days
|
149
|
+
|
150
|
+
# A period that the user is allowed to confirm their account before their
|
151
|
+
# token becomes invalid. For example, if set to 3.days, the user can confirm
|
152
|
+
# their account within 3 days after the mail was sent, but on the fourth day
|
153
|
+
# their account can't be confirmed with the token any more.
|
154
|
+
# Default is nil, meaning there is no restriction on how long a user can take
|
155
|
+
# before confirming their account.
|
156
|
+
# config.confirm_within = 3.days
|
157
|
+
|
158
|
+
# If true, requires any email changes to be confirmed (exactly the same way as
|
159
|
+
# initial account confirmation) to be applied. Requires additional unconfirmed_email
|
160
|
+
# db field (see migrations). Until confirmed, new email is stored in
|
161
|
+
# unconfirmed_email column, and copied to email column on successful confirmation.
|
162
|
+
config.reconfirmable = true
|
163
|
+
|
164
|
+
# Defines which key will be used when confirming an account
|
165
|
+
# config.confirmation_keys = [:email]
|
166
|
+
|
167
|
+
# ==> Configuration for :rememberable
|
168
|
+
# The time the user will be remembered without asking for credentials again.
|
169
|
+
# config.remember_for = 2.weeks
|
170
|
+
|
171
|
+
# Invalidates all the remember me tokens when the user signs out.
|
172
|
+
config.expire_all_remember_me_on_sign_out = true
|
173
|
+
|
174
|
+
# If true, extends the user's remember period when remembered via cookie.
|
175
|
+
# config.extend_remember_period = false
|
176
|
+
|
177
|
+
# Options to be passed to the created cookie. For instance, you can set
|
178
|
+
# secure: true in order to force SSL only cookies.
|
179
|
+
# config.rememberable_options = {}
|
180
|
+
|
181
|
+
# ==> Configuration for :validatable
|
182
|
+
# Range for password length.
|
183
|
+
config.password_length = 6..128
|
184
|
+
|
185
|
+
# Email regex used to validate email formats. It simply asserts that
|
186
|
+
# one (and only one) @ exists in the given string. This is mainly
|
187
|
+
# to give user feedback and not to assert the e-mail validity.
|
188
|
+
config.email_regexp = /\A[^@\s]+@[^@\s]+\z/
|
189
|
+
|
190
|
+
# ==> Configuration for :timeoutable
|
191
|
+
# The time you want to timeout the user session without activity. After this
|
192
|
+
# time the user will be asked for credentials again. Default is 30 minutes.
|
193
|
+
# config.timeout_in = 30.minutes
|
194
|
+
|
195
|
+
# ==> Configuration for :lockable
|
196
|
+
# Defines which strategy will be used to lock an account.
|
197
|
+
# :failed_attempts = Locks an account after a number of failed attempts to sign in.
|
198
|
+
# :none = No lock strategy. You should handle locking by yourself.
|
199
|
+
# config.lock_strategy = :failed_attempts
|
200
|
+
|
201
|
+
# Defines which key will be used when locking and unlocking an account
|
202
|
+
# config.unlock_keys = [:email]
|
203
|
+
|
204
|
+
# Defines which strategy will be used to unlock an account.
|
205
|
+
# :email = Sends an unlock link to the user email
|
206
|
+
# :time = Re-enables login after a certain amount of time (see :unlock_in below)
|
207
|
+
# :both = Enables both strategies
|
208
|
+
# :none = No unlock strategy. You should handle unlocking by yourself.
|
209
|
+
# config.unlock_strategy = :both
|
210
|
+
|
211
|
+
# Number of authentication tries before locking an account if lock_strategy
|
212
|
+
# is failed attempts.
|
213
|
+
# config.maximum_attempts = 20
|
214
|
+
|
215
|
+
# Time interval to unlock the account if :time is enabled as unlock_strategy.
|
216
|
+
# config.unlock_in = 1.hour
|
217
|
+
|
218
|
+
# Warn on the last attempt before the account is locked.
|
219
|
+
# config.last_attempt_warning = true
|
220
|
+
|
221
|
+
# ==> Configuration for :recoverable
|
222
|
+
#
|
223
|
+
# Defines which key will be used when recovering the password for an account
|
224
|
+
# config.reset_password_keys = [:email]
|
225
|
+
|
226
|
+
# Time interval you can reset your password with a reset password key.
|
227
|
+
# Don't put a too small interval or your users won't have the time to
|
228
|
+
# change their passwords.
|
229
|
+
config.reset_password_within = 6.hours
|
230
|
+
|
231
|
+
# When set to false, does not sign a user in automatically after their password is
|
232
|
+
# reset. Defaults to true, so a user is signed in automatically after a reset.
|
233
|
+
# config.sign_in_after_reset_password = true
|
234
|
+
|
235
|
+
# ==> Configuration for :encryptable
|
236
|
+
# Allow you to use another hashing or encryption algorithm besides bcrypt (default).
|
237
|
+
# You can use :sha1, :sha512 or algorithms from others authentication tools as
|
238
|
+
# :clearance_sha1, :authlogic_sha512 (then you should set stretches above to 20
|
239
|
+
# for default behavior) and :restful_authentication_sha1 (then you should set
|
240
|
+
# stretches to 10, and copy REST_AUTH_SITE_KEY to pepper).
|
241
|
+
#
|
242
|
+
# Require the `devise-encryptable` gem when using anything other than bcrypt
|
243
|
+
# config.encryptor = :sha512
|
244
|
+
|
245
|
+
# ==> Scopes configuration
|
246
|
+
# Turn scoped views on. Before rendering "sessions/new", it will first check for
|
247
|
+
# "users/sessions/new". It's turned off by default because it's slower if you
|
248
|
+
# are using only default views.
|
249
|
+
# config.scoped_views = false
|
250
|
+
|
251
|
+
# Configure the default scope given to Warden. By default it's the first
|
252
|
+
# devise role declared in your routes (usually :user).
|
253
|
+
# config.default_scope = :user
|
254
|
+
|
255
|
+
# Set this configuration to false if you want /users/sign_out to sign out
|
256
|
+
# only the current scope. By default, Devise signs out all scopes.
|
257
|
+
# config.sign_out_all_scopes = true
|
258
|
+
|
259
|
+
# ==> Navigation configuration
|
260
|
+
# Lists the formats that should be treated as navigational. Formats like
|
261
|
+
# :html should redirect to the sign in page when the user does not have
|
262
|
+
# access, but formats like :xml or :json, should return 401.
|
263
|
+
#
|
264
|
+
# If you have any extra navigational formats, like :iphone or :mobile, you
|
265
|
+
# should add them to the navigational formats lists.
|
266
|
+
#
|
267
|
+
# The "*/*" below is required to match Internet Explorer requests.
|
268
|
+
# config.navigational_formats = ['*/*', :html, :turbo_stream]
|
269
|
+
|
270
|
+
# The default HTTP method used to sign out a resource. Default is :delete.
|
271
|
+
config.sign_out_via = :delete
|
272
|
+
|
273
|
+
# ==> OmniAuth
|
274
|
+
# Add a new OmniAuth provider. Check the wiki for more information on setting
|
275
|
+
# up on your models and hooks.
|
276
|
+
# config.omniauth :github, 'APP_ID', 'APP_SECRET', scope: 'user,public_repo'
|
277
|
+
identity_base_url = ENV['IDENTITY_BASE_URL'] || "https://devlogin.strongmind.com"
|
278
|
+
app_base_url = ENV['APP_BASE_URL'] || "http://localhost:3000"
|
279
|
+
config.omniauth :openid_connect, {
|
280
|
+
name: :strongmind,
|
281
|
+
scope: %i[openid profile],
|
282
|
+
response_type: :code,
|
283
|
+
issuer: identity_base_url,
|
284
|
+
discovery: true,
|
285
|
+
post_logout_redirect_uri: app_base_url,
|
286
|
+
client_options: {
|
287
|
+
identifier: ENV['IDENTITY_CLIENT_ID'],
|
288
|
+
secret: ENV['IDENTITY_CLIENT_SECRET'],
|
289
|
+
redirect_uri: "#{app_base_url}/users/auth/strongmind/callback"
|
290
|
+
}
|
291
|
+
}
|
292
|
+
|
293
|
+
# ==> Warden configuration
|
294
|
+
# If you want to use other strategies, that are not supported by Devise, or
|
295
|
+
# change the failure app, you can configure them inside the config.warden block.
|
296
|
+
#
|
297
|
+
# config.warden do |manager|
|
298
|
+
# manager.intercept_401 = false
|
299
|
+
# manager.default_strategies(scope: :user).unshift :some_external_strategy
|
300
|
+
# end
|
301
|
+
|
302
|
+
# ==> Mountable engine configurations
|
303
|
+
# When using Devise inside an engine, let's call it `MyEngine`, and this engine
|
304
|
+
# is mountable, there are some extra configurations to be taken into account.
|
305
|
+
# The following options are available, assuming the engine is mounted as:
|
306
|
+
#
|
307
|
+
# mount MyEngine, at: '/my_engine'
|
308
|
+
#
|
309
|
+
# The router that invoked `devise_for`, in the example above, would be:
|
310
|
+
# config.router_name = :my_engine
|
311
|
+
#
|
312
|
+
# When using OmniAuth, Devise cannot automatically set OmniAuth path,
|
313
|
+
# so you need to do it manually. For the users scope, it would be:
|
314
|
+
# config.omniauth_path_prefix = '/my_engine/users/auth'
|
315
|
+
|
316
|
+
# ==> Hotwire/Turbo configuration
|
317
|
+
# When using Devise with Hotwire/Turbo, the http status for error responses
|
318
|
+
# and some redirects must match the following. The default in Devise for existing
|
319
|
+
# apps is `200 OK` and `302 Found respectively`, but new apps are generated with
|
320
|
+
# these new defaults that match Hotwire/Turbo behavior.
|
321
|
+
# Note: These might become the new default in future versions of Devise.
|
322
|
+
config.responder.error_status = :unprocessable_entity
|
323
|
+
config.responder.redirect_status = :see_other
|
324
|
+
|
325
|
+
# ==> Configuration for :registerable
|
326
|
+
|
327
|
+
# When set to false, does not sign a user in automatically after their password is
|
328
|
+
# changed. Defaults to true, so a user is signed in automatically after changing a password.
|
329
|
+
# config.sign_in_after_change_password = true
|
330
|
+
end
|
data/config/routes.rb
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
Rails.application.routes.draw do
|
2
|
+
|
3
|
+
return if defined? Rails::Generators
|
4
|
+
|
5
|
+
devise_for :users, controllers: {
|
6
|
+
omniauth_callbacks: "users/omniauth_callbacks"
|
7
|
+
}
|
8
|
+
|
9
|
+
devise_scope :user do
|
10
|
+
post 'users/sign_out', to: 'devise/sessions#destroy'
|
11
|
+
|
12
|
+
unauthenticated do
|
13
|
+
root 'logins#index', as: :unauthenticated_root
|
14
|
+
end
|
15
|
+
|
16
|
+
end
|
17
|
+
|
18
|
+
end
|
@@ -0,0 +1,56 @@
|
|
1
|
+
module Strongmind
|
2
|
+
|
3
|
+
class InstallGenerator < Rails::Generators::Base
|
4
|
+
include Rails::Generators::Migration
|
5
|
+
|
6
|
+
source_root File.expand_path("templates", __dir__)
|
7
|
+
|
8
|
+
def run_devise_user
|
9
|
+
generate "active_record:devise User"
|
10
|
+
# overwrite the user model
|
11
|
+
copy_file "user.rb", "app/models/user.rb", force: true
|
12
|
+
end
|
13
|
+
|
14
|
+
def protect_app_files
|
15
|
+
inject_into_file "app/controllers/application_controller.rb", after: "class ApplicationController < ActionController::Base\n" do
|
16
|
+
" before_action :authenticate_user!\n"
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
def add_devise_routes
|
21
|
+
devise_route = '
|
22
|
+
return if defined? Rails::Generators
|
23
|
+
|
24
|
+
devise_scope :user do
|
25
|
+
authenticated do
|
26
|
+
end
|
27
|
+
end
|
28
|
+
'.dup
|
29
|
+
|
30
|
+
route devise_route
|
31
|
+
end
|
32
|
+
|
33
|
+
def uid_migration
|
34
|
+
migration_template "add_uid_to_user.rb", "db/migrate/add_uid_to_user.rb"
|
35
|
+
end
|
36
|
+
|
37
|
+
def self.next_migration_number(path)
|
38
|
+
# Add 1 to make sure this happens after the devise migration
|
39
|
+
(Time.now.utc.strftime("%Y%m%d%H%M%S").to_i + 1).to_s
|
40
|
+
end
|
41
|
+
|
42
|
+
def add_devise_gems
|
43
|
+
gem 'devise'
|
44
|
+
gem 'omniauth'
|
45
|
+
gem 'omniauth_openid_connect'
|
46
|
+
gem 'omniauth-rails_csrf_protection'
|
47
|
+
gem 'dotenv-rails'
|
48
|
+
|
49
|
+
end
|
50
|
+
|
51
|
+
def add_dotenv_file
|
52
|
+
copy_file ".env", ".env"
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
end
|
metadata
ADDED
@@ -0,0 +1,152 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: strongmind-auth
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Team Belding
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2024-03-12 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rails
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 7.1.3.2
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 7.1.3.2
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: devise
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
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: omniauth
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :runtime
|
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: omniauth-rails_csrf_protection
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :runtime
|
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: omniauth_openid_connect
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :runtime
|
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: strongmind-platform-sdk
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :runtime
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
description: Ruby gem for StrongMind authentication in a strongmind app
|
98
|
+
email:
|
99
|
+
- teambelding@strongmind.com
|
100
|
+
executables: []
|
101
|
+
extensions: []
|
102
|
+
extra_rdoc_files: []
|
103
|
+
files:
|
104
|
+
- README.md
|
105
|
+
- Rakefile
|
106
|
+
- app/assets/config/strongmind_auth_manifest.js
|
107
|
+
- app/assets/stylesheets/strongmind/auth/application.css
|
108
|
+
- app/controllers/logins_controller.rb
|
109
|
+
- app/controllers/users/omniauth_callbacks_controller.rb
|
110
|
+
- app/helpers/strongmind/auth/application_helper.rb
|
111
|
+
- app/jobs/rails/auth/application_job.rb
|
112
|
+
- app/mailers/rails/auth/application_mailer.rb
|
113
|
+
- app/models/user_base.rb
|
114
|
+
- app/views/layouts/strongmind/auth/application.html.erb
|
115
|
+
- app/views/logins/index.html.erb
|
116
|
+
- config/initializers/devise.rb
|
117
|
+
- config/routes.rb
|
118
|
+
- lib/generators/strongmind/USAGE
|
119
|
+
- lib/generators/strongmind/install_generator.rb
|
120
|
+
- lib/generators/strongmind/templates/add_uid_to_user.rb
|
121
|
+
- lib/generators/strongmind/templates/user.rb
|
122
|
+
- lib/strongmind/auth.rb
|
123
|
+
- lib/strongmind/auth/engine.rb
|
124
|
+
- lib/strongmind/auth/version.rb
|
125
|
+
- lib/tasks/rails/auth_tasks.rake
|
126
|
+
- lib/tasks/strongmind/auth_tasks.rake
|
127
|
+
homepage: https://www.strongmind.com
|
128
|
+
licenses:
|
129
|
+
- ''
|
130
|
+
metadata:
|
131
|
+
homepage_uri: https://www.strongmind.com
|
132
|
+
source_code_uri: https://github.com/StrongMind/rails-auth
|
133
|
+
post_install_message:
|
134
|
+
rdoc_options: []
|
135
|
+
require_paths:
|
136
|
+
- lib
|
137
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
138
|
+
requirements:
|
139
|
+
- - ">="
|
140
|
+
- !ruby/object:Gem::Version
|
141
|
+
version: '0'
|
142
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
143
|
+
requirements:
|
144
|
+
- - ">="
|
145
|
+
- !ruby/object:Gem::Version
|
146
|
+
version: '0'
|
147
|
+
requirements: []
|
148
|
+
rubygems_version: 3.4.10
|
149
|
+
signing_key:
|
150
|
+
specification_version: 4
|
151
|
+
summary: Ruby gem for StrongMind authentication in a strongmind app
|
152
|
+
test_files: []
|