ombu_labs-auth 0.1.0 → 1.0.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: 41111c90c5534ea459e316cb3aa05922216d164d85c9726ff1f9deec1d87fdc9
4
- data.tar.gz: 6deac429d78449c2387338ae00fc1001404806b9fa7eede8183c1200258aa844
3
+ metadata.gz: fd15cf3b179c9a7abe894d8af2417865d1d6fc6d89186d27998e896af8de29d3
4
+ data.tar.gz: b460c2994bf236aba93e5252a5cebfac2082a3106a4c1f38d39c12f0bfa38c6c
5
5
  SHA512:
6
- metadata.gz: f50cf42b5d6eeeb19a990c24e0285cf6c43c1aa9a98b4c05edc54c6052e443b97a32bd0527a53cff1a0fde886425e4a71c5d7e854f30271cafdbdb55f6980538
7
- data.tar.gz: 8354b5a402310f61029233b32810f3635771ff541247386a47a7b399b857b39e7ee2e743411b0fb7f84b3537357ce1bd6de8ebd9bf1203d410d4709e7498eee0
6
+ metadata.gz: daecab37fcbd7f1e0062e763b3a5d33d3f16f832fd55d2211fa69e3e0c2e63471ef7ab2f2a67f96075fc02477098a43fd656e09420773eeb12265ef5a6e72696
7
+ data.tar.gz: e28b862544edff1671dc671b1cf7c630568768c7a934734cffc0c7361093d526869a88cfedee622fd2fd916f619bc4ff2971cc93ea28fdd95871e000e50f32ef
data/README.md CHANGED
@@ -5,6 +5,9 @@ This gem provides an easy way to generate new (Devise) sessions for members of a
5
5
  If a user is signing in with GitHub and they are a (public) member of the configured GitHub organization, they will be allowed in.
6
6
 
7
7
  ## Environment Variables
8
+
9
+ ### GitHub Login
10
+
8
11
  Make sure you configure your ENV variables to use Github authentication.
9
12
 
10
13
  ```
@@ -33,16 +36,39 @@ Once you create the app and generate credentials for it, make sure you add them
33
36
  GITHUB_APP_ID=xxxxxxxxxxxxxxxxxxxx
34
37
  GITHUB_APP_SECRET=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
35
38
  ```
39
+
40
+ ### Developer Login
41
+
42
+ To avoid the need of a GitHub application setup (useful for local development or Heroku Review Apps), the `developer` strategy can be enabled using setting a `SHOW_DEVELOPER_AUTH` variable with any non-blank value (`SHOW_DEVELOPER_AUTH=1` or `SHOW_DEVELOPER_AUTH=true` for example).
43
+
36
44
  ## Getting Started
37
45
 
38
- - Add these lines to your application's Gemfile:
46
+ ### Requirements
47
+
48
+ A `User`-like model that will be used for the authentication (`User`, `Admin`, `Client`, etc).
49
+
50
+ The database table for that model must have, at least, these fields:
51
+
52
+ ```rb
53
+ create_table :clients do |t|
54
+ t.string :email, unique: true
55
+ t.string :provider
56
+ t.string :uid, unique: true
57
+ t.string :name
58
+ t.string :encrypted_password
59
+ end
60
+ ```
61
+
62
+ ### Installation
63
+
64
+ - Add this line to your application's Gemfile:
39
65
 
40
66
  ```ruby
41
67
  gem 'ombu_labs-auth'
42
- gem 'omniauth-github', '~> 2.0.0'
43
68
  ```
44
69
 
45
70
  - And then execute:
71
+
46
72
  ```bash
47
73
  $ bundle
48
74
  ```
@@ -62,12 +88,67 @@ mount OmbuLabs::Auth::Engine, at: '/', as: 'ombu_labs_auth'
62
88
  </div>
63
89
  ```
64
90
 
91
+ > This will default to a basic HTML page included in this gem. To customize this view, check [this section](#customizing-sign-in-page)
92
+
65
93
  - Add the Devise authentication helper to your private objects controllers
66
94
 
67
- ```
95
+ ```rb
68
96
  before_action :authenticate_user!
69
97
  ```
70
98
 
99
+ - Include the `OmbuLabsAuthenticable` concern in the authenticable model
100
+
101
+ ```rb
102
+ class Admin < ApplicationRecord
103
+ include OmbuLabsAuthenticable
104
+ ...
105
+ end
106
+ ```
107
+
108
+ - Tell `OmbuLabs::Auth` the user class name and table for the authenticable model
109
+
110
+ ```rb
111
+ # config/initializers/ombu_labs-auth.rb
112
+ OmbuLabs::Auth.user_class_name = "Admin" # defaults to "User" if not set
113
+ OmbuLabs::Auth.users_table_name = :admins # defaults to :users if not set
114
+ ```
115
+
116
+ > You can skip this step if the table is called `users` and the model is called `User`
117
+
118
+ - Log Out action
119
+
120
+ A link to `ombu_labs_auth.destroy_user_session_path` with method `DELETE` can be used. If rails-ujs is not available, a `button_to` can be used.
121
+
122
+ ```
123
+ <%= link_to "Sign out", ombu_labs_auth.destroy_user_session_path, method: :delete, class: "button magenta" %>
124
+ ```
125
+
126
+ ### TODO: create a rails template to do all the previous steps automatically
127
+
128
+ ## Customizing sign in page
129
+
130
+ The gem provides a basic html template to select the authentication method. To customize it, create a view at `views/devise/session/new.html.erb` and a layout at `views/layouts/devise.html.erb`.
131
+
132
+ Include this snippet in the `new` view:
133
+
134
+ ```
135
+ <%- Devise.omniauth_providers.each do |provider| %>
136
+ <%= button_to "Sign in with #{OmniAuth::Utils.camelize(provider)}", omniauth_authorize_path(OmbuLabs::Auth.user_class, provider), method: :post %><br />
137
+ <% end -%>
138
+ ```
139
+
140
+ To use a `link_to` helper instead of a `button_to` helper to, rails-ujs is needed to support making a `POST` request with link tags. Then, replace with:
141
+
142
+ ```
143
+ <%= link_to "Sign in with #{OmniAuth::Utils.camelize(provider)}", omniauth_authorize_path(OmbuLabs::Auth.user_class, provider), method: :post, data: { 'turbo-method' => :post } %><br />
144
+ ```
145
+
146
+ > If this intermediate page is not needed, the button/link to `omniauth_authorize_path` can be used directly.
147
+
148
+ ## Running tests
149
+
150
+ Run `rake app:test:all` to run all tests and `rake app:test` to skip system tests.
151
+
71
152
  ## Caveats
72
153
 
73
154
  Please be aware this gem is a mountable engine which depends on Devise, and it's not possible to mount it multiple times. Refer to their Wiki for more on the issue - https://github.com/heartcombo/devise/wiki/How-To:-Use-devise-inside-a-mountable-engine
@@ -78,5 +159,22 @@ Have a fix for a problem you've been running into or an idea for a new feature y
78
159
 
79
160
  Take a look at the [Contributing document](https://github.com/fastruby/ombu_labs-auth/blob/main/CONTRIBUTING.md) for instructions to set up the repo on your machine and create a good Pull Request.
80
161
 
162
+ ## Release
163
+
164
+ If you are looking to contribute in the gem you need to be aware that we are using the [Conventional Commits](https://www.conventionalcommits.org/en/v1.0.0/#summary) specification to release versions in this gem.
165
+
166
+ which means, when doing a contribution your commit message must have the following structure
167
+
168
+ ```git
169
+ <type>[optional scope]: <description>
170
+
171
+ [optional body]
172
+
173
+ [optional footer(s)]
174
+ ```
175
+
176
+ [here](https://www.conventionalcommits.org/en/v1.0.0/#examples) you can find some commit's examples.
177
+
81
178
  ## License
179
+
82
180
  The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
@@ -12,7 +12,7 @@ module OmbuLabs
12
12
  member_logins = organization_members.map { |member| member["login"] }
13
13
 
14
14
  if username.in?(member_logins)
15
- @user = User.from_omniauth(request.env["omniauth.auth"])
15
+ @user = OmbuLabs::Auth.user_class.from_omniauth(request.env["omniauth.auth"])
16
16
  sign_in_and_redirect @user
17
17
  else
18
18
  flash[:error] = "This application is only available to members of #{organization_name}."
@@ -21,7 +21,7 @@ module OmbuLabs
21
21
  end
22
22
 
23
23
  def developer
24
- @user = User.from_omniauth(request.env["omniauth.auth"])
24
+ @user = OmbuLabs::Auth.user_class.from_omniauth(request.env["omniauth.auth"])
25
25
  sign_in_and_redirect @user
26
26
  end
27
27
 
@@ -0,0 +1,22 @@
1
+ require "active_support/concern"
2
+
3
+ module OmbuLabsAuthenticable
4
+ extend ActiveSupport::Concern
5
+
6
+ included do
7
+ # Include default devise modules. Others available are:
8
+ # :confirmable, :lockable, :timeoutable
9
+ devise :database_authenticatable, :omniauthable
10
+ end
11
+
12
+ class_methods do
13
+ def from_omniauth(auth)
14
+ user_attributes = {
15
+ email: auth["info"]["email"],
16
+ name: auth["info"]["name"],
17
+ password: Devise.friendly_token[0, 20]
18
+ }
19
+ where(provider: auth["provider"], uid: auth["uid"]).first_or_create.tap { |user| user.update(user_attributes) }
20
+ end
21
+ end
22
+ end
@@ -1,14 +1,8 @@
1
- <div class="fluid-container center floor signin">
2
1
  <h2 class="new-edit-title">Sign in</h2>
3
2
 
4
3
  <% if flash[:error] %>
5
4
  <div class="alert alert-danger" role="alert"><%= flash[:error] %></div>
6
5
  <% end %>
7
-
8
- <%- if devise_mapping.omniauthable? %>
9
- <%- resource_class.omniauth_providers.each do |provider| %>
10
- <%= link_to "Sign in with #{OmniAuth::Utils.camelize(provider)}", omniauth_authorize_path(resource_name, provider), class: "button", id:"back", method: :post, data: { 'turbo-method' => :post } %><br />
11
- <%= button_to "Sign in with #{OmniAuth::Utils.camelize(provider)}", omniauth_authorize_path(resource_name, provider), class: "button", method: :post %><br />
12
- <% end -%>
6
+ <%- Devise.omniauth_providers.each do |provider| %>
7
+ <%= button_to "Sign in with #{OmniAuth::Utils.camelize(provider)}", omniauth_authorize_path(OmbuLabs::Auth.user_class, provider), method: :post %><br />
13
8
  <% end -%>
14
- </div>
@@ -1,311 +1,16 @@
1
1
  # frozen_string_literal: true
2
-
3
- # Assuming you have not yet modified this file, each configuration option below
4
- # is set to its default value. Note that some are commented out while others
5
- # are not: uncommented lines are intended to protect your configuration from
6
- # breaking changes in upgrades (i.e., in the event that future versions of
7
- # Devise change the default values for those options).
8
- #
9
- # Use this hook to configure devise mailer, warden hooks and so forth.
10
- # Many of these configuration options can be set straight in your model.
11
2
  Devise.setup do |config|
12
- # The secret key used by Devise. Devise uses this key to generate
13
- # random tokens. Changing this key will render invalid all existing
14
- # confirmation, reset password and unlock tokens in the database.
15
- # Devise will use the `secret_key_base` as its `secret_key`
16
- # by default. You can change it below and use your own secret key.
17
- # config.secret_key = '4de034614c8dc2c925a677c848c46cefe588af1a7d1516a4f25feb985eb9959d529d2863e5dd379e17999583fc1b3e96e458cff41012c3643f0b7e47a7a66939'
18
-
19
- # ==> Controller configuration
20
- # Configure the parent class to the devise controllers.
21
3
  config.parent_controller = 'OmbuLabs::Auth::ApplicationController'
22
4
 
23
- # ==> Mailer Configuration
24
- # Configure the e-mail address which will be shown in Devise::Mailer,
25
- # note that it will be overwritten if you use your own mailer class
26
- # with default "from" parameter.
27
- config.mailer_sender = 'please-change-me-at-config-initializers-devise@example.com'
28
-
29
- # Configure the class responsible to send e-mails.
30
- # config.mailer = 'Devise::Mailer'
31
-
32
- # Configure the parent class responsible to send e-mails.
33
- # config.parent_mailer = 'ActionMailer::Base'
34
-
35
- # ==> ORM configuration
36
- # Load and configure the ORM. Supports :active_record (default) and
37
- # :mongoid (bson_ext recommended) by default. Other ORMs may be
38
- # available as additional gems.
39
- require 'devise/orm/active_record'
40
-
41
- # ==> Configuration for any authentication mechanism
42
- # Configure which keys are used when authenticating a user. The default is
43
- # just :email. You can configure it to use [:username, :subdomain], so for
44
- # authenticating a user, both parameters are required. Remember that those
45
- # parameters are used only when authenticating and not when retrieving from
46
- # session. If you need permissions, you should implement that in a before filter.
47
- # You can also supply a hash where the value is a boolean determining whether
48
- # or not authentication should be aborted when the value is not present.
49
- # config.authentication_keys = [:email]
50
-
51
- # Configure parameters from the request object used for authentication. Each entry
52
- # given should be a request method and it will automatically be passed to the
53
- # find_for_authentication method and considered in your model lookup. For instance,
54
- # if you set :request_keys to [:subdomain], :subdomain will be used on authentication.
55
- # The same considerations mentioned for authentication_keys also apply to request_keys.
56
- # config.request_keys = []
57
-
58
- # Configure which authentication keys should be case-insensitive.
59
- # These keys will be downcased upon creating or modifying a user and when used
60
- # to authenticate or find a user. Default is :email.
61
- config.case_insensitive_keys = [:email]
62
-
63
- # Configure which authentication keys should have whitespace stripped.
64
- # These keys will have whitespace before and after removed upon creating or
65
- # modifying a user and when used to authenticate or find a user. Default is :email.
66
- config.strip_whitespace_keys = [:email]
67
-
68
- # Tell if authentication through request.params is enabled. True by default.
69
- # It can be set to an array that will enable params authentication only for the
70
- # given strategies, for example, `config.params_authenticatable = [:database]` will
71
- # enable it only for database (email + password) authentication.
72
- # config.params_authenticatable = true
73
-
74
- # Tell if authentication through HTTP Auth is enabled. False by default.
75
- # It can be set to an array that will enable http authentication only for the
76
- # given strategies, for example, `config.http_authenticatable = [:database]` will
77
- # enable it only for database authentication.
78
- # For API-only applications to support authentication "out-of-the-box", you will likely want to
79
- # enable this with :database unless you are using a custom strategy.
80
- # The supported strategies are:
81
- # :database = Support basic authentication with authentication key + password
82
- # config.http_authenticatable = false
83
-
84
- # If 401 status code should be returned for AJAX requests. True by default.
85
- # config.http_authenticatable_on_xhr = true
86
-
87
- # The realm used in Http Basic Authentication. 'Application' by default.
88
- # config.http_authentication_realm = 'Application'
89
-
90
- # It will change confirmation, password recovery and other workflows
91
- # to behave the same regardless if the e-mail provided was right or wrong.
92
- # Does not affect registerable.
93
- # config.paranoid = true
94
-
95
- # By default Devise will store the user in session. You can skip storage for
96
- # particular strategies by setting this option.
97
- # Notice that if you are skipping storage for all authentication paths, you
98
- # may want to disable generating routes to Devise's sessions controller by
99
- # passing skip: :sessions to `devise_for` in your config/routes.rb
100
- config.skip_session_storage = [:http_auth]
101
-
102
- # By default, Devise cleans up the CSRF token on authentication to
103
- # avoid CSRF token fixation attacks. This means that, when using AJAX
104
- # requests for sign in and sign up, you need to get a new CSRF token
105
- # from the server. You can disable this option at your own risk.
106
- # config.clean_up_csrf_token_on_authentication = true
107
-
108
- # When false, Devise will not attempt to reload routes on eager load.
109
- # This can reduce the time taken to boot the app but if your application
110
- # requires the Devise mappings to be loaded during boot time the application
111
- # won't boot properly.
112
- # config.reload_routes = true
113
-
114
- # ==> Configuration for :database_authenticatable
115
- # For bcrypt, this is the cost for hashing the password and defaults to 12. If
116
- # using other algorithms, it sets how many times you want the password to be hashed.
117
- # The number of stretches used for generating the hashed password are stored
118
- # with the hashed password. This allows you to change the stretches without
119
- # invalidating existing passwords.
120
- #
121
- # Limiting the stretches to just one in testing will increase the performance of
122
- # your test suite dramatically. However, it is STRONGLY RECOMMENDED to not use
123
- # a value less than 10 in other environments. Note that, for bcrypt (the default
124
- # algorithm), the cost increases exponentially with the number of stretches (e.g.
125
- # a value of 20 is already extremely slow: approx. 60 seconds for 1 calculation).
126
- config.stretches = Rails.env.test? ? 1 : 12
127
-
128
- # Set up a pepper to generate the hashed password.
129
- # config.pepper = '7fe15ab9313b3144e5cfc0d754b334b1e1351590a0213d1e27da4ee982a9e56a39f5eb4799119bee7c47fae463ce7c510221042dbbde9ee93e1a9ab1354a9aeb'
130
-
131
- # Send a notification to the original email when the user's email is changed.
132
- # config.send_email_changed_notification = false
133
-
134
- # Send a notification email when the user's password is changed.
135
- # config.send_password_change_notification = false
136
-
137
- # ==> Configuration for :confirmable
138
- # A period that the user is allowed to access the website even without
139
- # confirming their account. For instance, if set to 2.days, the user will be
140
- # able to access the website for two days without confirming their account,
141
- # access will be blocked just in the third day.
142
- # You can also set it to nil, which will allow the user to access the website
143
- # without confirming their account.
144
- # Default is 0.days, meaning the user cannot access the website without
145
- # confirming their account.
146
- # config.allow_unconfirmed_access_for = 2.days
147
-
148
- # A period that the user is allowed to confirm their account before their
149
- # token becomes invalid. For example, if set to 3.days, the user can confirm
150
- # their account within 3 days after the mail was sent, but on the fourth day
151
- # their account can't be confirmed with the token any more.
152
- # Default is nil, meaning there is no restriction on how long a user can take
153
- # before confirming their account.
154
- # config.confirm_within = 3.days
155
-
156
- # If true, requires any email changes to be confirmed (exactly the same way as
157
- # initial account confirmation) to be applied. Requires additional unconfirmed_email
158
- # db field (see migrations). Until confirmed, new email is stored in
159
- # unconfirmed_email column, and copied to email column on successful confirmation.
160
- config.reconfirmable = true
161
-
162
- # Defines which key will be used when confirming an account
163
- # config.confirmation_keys = [:email]
5
+ if ENV["GITHUB_APP_ID"].present? && ENV["GITHUB_APP_SECRET"]
6
+ config.omniauth :github, ENV["GITHUB_APP_ID"], ENV["GITHUB_APP_SECRET"], scope: "user:email"
7
+ end
164
8
 
165
- # ==> Configuration for :rememberable
166
- # The time the user will be remembered without asking for credentials again.
167
- # config.remember_for = 2.weeks
9
+ if ENV["SHOW_DEVELOPER_AUTH"].present?
10
+ config.omniauth :developer, scope: "user:email"
11
+ end
168
12
 
169
- # Invalidates all the remember me tokens when the user signs out.
170
- config.expire_all_remember_me_on_sign_out = true
171
-
172
- # If true, extends the user's remember period when remembered via cookie.
173
- # config.extend_remember_period = false
174
-
175
- # Options to be passed to the created cookie. For instance, you can set
176
- # secure: true in order to force SSL only cookies.
177
- # config.rememberable_options = {}
178
-
179
- # ==> Configuration for :validatable
180
- # Range for password length.
181
- config.password_length = 6..128
182
-
183
- # Email regex used to validate email formats. It simply asserts that
184
- # one (and only one) @ exists in the given string. This is mainly
185
- # to give user feedback and not to assert the e-mail validity.
186
- config.email_regexp = /\A[^@\s]+@[^@\s]+\z/
187
-
188
- # ==> Configuration for :timeoutable
189
- # The time you want to timeout the user session without activity. After this
190
- # time the user will be asked for credentials again. Default is 30 minutes.
191
- # config.timeout_in = 30.minutes
192
-
193
- # ==> Configuration for :lockable
194
- # Defines which strategy will be used to lock an account.
195
- # :failed_attempts = Locks an account after a number of failed attempts to sign in.
196
- # :none = No lock strategy. You should handle locking by yourself.
197
- # config.lock_strategy = :failed_attempts
198
-
199
- # Defines which key will be used when locking and unlocking an account
200
- # config.unlock_keys = [:email]
201
-
202
- # Defines which strategy will be used to unlock an account.
203
- # :email = Sends an unlock link to the user email
204
- # :time = Re-enables login after a certain amount of time (see :unlock_in below)
205
- # :both = Enables both strategies
206
- # :none = No unlock strategy. You should handle unlocking by yourself.
207
- # config.unlock_strategy = :both
208
-
209
- # Number of authentication tries before locking an account if lock_strategy
210
- # is failed attempts.
211
- # config.maximum_attempts = 20
212
-
213
- # Time interval to unlock the account if :time is enabled as unlock_strategy.
214
- # config.unlock_in = 1.hour
215
-
216
- # Warn on the last attempt before the account is locked.
217
- # config.last_attempt_warning = true
218
-
219
- # ==> Configuration for :recoverable
220
- #
221
- # Defines which key will be used when recovering the password for an account
222
- # config.reset_password_keys = [:email]
223
-
224
- # Time interval you can reset your password with a reset password key.
225
- # Don't put a too small interval or your users won't have the time to
226
- # change their passwords.
227
- config.reset_password_within = 6.hours
228
-
229
- # When set to false, does not sign a user in automatically after their password is
230
- # reset. Defaults to true, so a user is signed in automatically after a reset.
231
- # config.sign_in_after_reset_password = true
232
-
233
- # ==> Configuration for :encryptable
234
- # Allow you to use another hashing or encryption algorithm besides bcrypt (default).
235
- # You can use :sha1, :sha512 or algorithms from others authentication tools as
236
- # :clearance_sha1, :authlogic_sha512 (then you should set stretches above to 20
237
- # for default behavior) and :restful_authentication_sha1 (then you should set
238
- # stretches to 10, and copy REST_AUTH_SITE_KEY to pepper).
239
- #
240
- # Require the `devise-encryptable` gem when using anything other than bcrypt
241
- # config.encryptor = :sha512
242
-
243
- # ==> Scopes configuration
244
- # Turn scoped views on. Before rendering "sessions/new", it will first check for
245
- # "users/sessions/new". It's turned off by default because it's slower if you
246
- # are using only default views.
247
- # config.scoped_views = false
248
-
249
- # Configure the default scope given to Warden. By default it's the first
250
- # devise role declared in your routes (usually :user).
251
- # config.default_scope = :user
252
-
253
- # Set this configuration to false if you want /users/sign_out to sign out
254
- # only the current scope. By default, Devise signs out all scopes.
255
- # config.sign_out_all_scopes = true
256
-
257
- # ==> Navigation configuration
258
- # Lists the formats that should be treated as navigational. Formats like
259
- # :html, should redirect to the sign in page when the user does not have
260
- # access, but formats like :xml or :json, should return 401.
261
- #
262
- # If you have any extra navigational formats, like :iphone or :mobile, you
263
- # should add them to the navigational formats lists.
264
- #
265
- # The "*/*" below is required to match Internet Explorer requests.
266
- # config.navigational_formats = ['*/*', :html]
267
-
268
- # The default HTTP method used to sign out a resource. Default is :delete.
269
- config.sign_out_via = :delete
270
-
271
- # ==> OmniAuth
272
- # Add a new OmniAuth provider. Check the wiki for more information on setting
273
- # up on your models and hooks.
274
- config.omniauth :github, ENV["GITHUB_APP_ID"], ENV["GITHUB_APP_SECRET"], scope: "user:email"
275
-
276
- # ==> Warden configuration
277
- # If you want to use other strategies, that are not supported by Devise, or
278
- # change the failure app, you can configure them inside the config.warden block.
279
- #
280
- # config.warden do |manager|
281
- # manager.intercept_401 = false
282
- # manager.default_strategies(scope: :user).unshift :some_external_strategy
283
- # end
284
-
285
- # ==> Mountable engine configurations
286
- # When using Devise inside an engine, let's call it `MyEngine`, and this engine
287
- # is mountable, there are some extra configurations to be taken into account.
288
- # The following options are available, assuming the engine is mounted as:
289
- #
290
- # mount MyEngine, at: '/my_engine'
291
- #
292
- # The router that invoked `devise_for`, in the example above, would be:
293
13
  config.router_name = :ombu_labs_auth
294
- #
295
- # When using OmniAuth, Devise cannot automatically set OmniAuth path,
296
- # so you need to do it manually. For the users scope, it would be:
297
- # config.omniauth_path_prefix = '/my_engine/users/auth'
298
-
299
- # ==> Turbolinks configuration
300
- # If your app is using Turbolinks, Turbolinks::Controller needs to be included to make redirection work correctly:
301
- #
302
- # ActiveSupport.on_load(:devise_failure_app) do
303
- # include Turbolinks::Controller
304
- # end
305
-
306
- # ==> Configuration for :registerable
307
14
 
308
- # When set to false, does not sign a user in automatically after their password is
309
- # changed. Defaults to true, so a user is signed in automatically after changing a password.
310
- # config.sign_in_after_change_password = true
15
+ require "devise/orm/active_record"
311
16
  end
data/config/routes.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  OmbuLabs::Auth::Engine.routes.draw do
2
- devise_for :users, class_name: OmbuLabs::Auth::User, module: :devise, controllers: { omniauth_callbacks: 'ombu_labs/auth/callbacks' }
2
+ devise_for OmbuLabs::Auth.users_table_name, class_name: OmbuLabs::Auth.user_class_name, module: :devise, controllers: { omniauth_callbacks: 'ombu_labs/auth/callbacks' }
3
3
  end
@@ -1,5 +1,5 @@
1
1
  module OmbuLabs
2
2
  module Auth
3
- VERSION = "0.1.0"
3
+ VERSION = "1.0.0"
4
4
  end
5
5
  end
@@ -1,9 +1,25 @@
1
+ # due to boot time configs, these need to be required BEFORE the engine
1
2
  require "devise"
2
- require "ombu_labs/auth/version"
3
+ require "omniauth-github"
3
4
  require "ombu_labs/auth/engine"
5
+ require "ombu_labs/auth/version"
6
+ require "omniauth/rails_csrf_protection"
4
7
 
5
8
  module OmbuLabs
6
9
  module Auth
7
- # Your code goes here...
10
+ mattr_accessor :user_class_name
11
+ mattr_accessor :users_table_name
12
+
13
+ def self.user_class_name
14
+ @@user_class_name || 'User'
15
+ end
16
+
17
+ def self.user_class
18
+ @@user_class ||= user_class_name.constantize
19
+ end
20
+
21
+ def self.users_table_name
22
+ @@users_table_name || :users
23
+ end
8
24
  end
9
25
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ombu_labs-auth
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
- - Ombulabs
7
+ - OmbuLabs
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-10-20 00:00:00.000000000 Z
11
+ date: 2023-06-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -66,6 +66,62 @@ dependencies:
66
66
  - - "~>"
67
67
  - !ruby/object:Gem::Version
68
68
  version: 2.0.0
69
+ - !ruby/object:Gem::Dependency
70
+ name: omniauth-rails_csrf_protection
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: capybara
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: webdrivers
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: puma
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
69
125
  description: Helps us authenticate teammates using GitHub Oauth and Devise
70
126
  email:
71
127
  - tiago@ombulabs.com
@@ -77,23 +133,13 @@ files:
77
133
  - MIT-LICENSE
78
134
  - README.md
79
135
  - Rakefile
80
- - app/assets/config/ombu_labs_auth_manifest.js
81
- - app/assets/stylesheets/ombu_labs/auth/application.css
82
136
  - app/controllers/ombu_labs/auth/application_controller.rb
83
137
  - app/controllers/ombu_labs/auth/callbacks_controller.rb
84
- - app/helpers/ombu_labs/auth/application_helper.rb
85
- - app/jobs/ombu_labs/auth/application_job.rb
86
- - app/mailers/ombu_labs/auth/application_mailer.rb
87
- - app/models/ombu_labs/auth/application_record.rb
88
- - app/models/ombu_labs/auth/user.rb
138
+ - app/models/concerns/ombu_labs_authenticable.rb
89
139
  - app/views/devise/sessions/new.html.erb
90
- - app/views/devise/shared/_links.html.erb
91
- - app/views/layouts/ombu_labs/auth/application.html.erb
92
- - config/environments/development.rb
93
140
  - config/initializers/devise.rb
94
141
  - config/locales/devise.en.yml
95
142
  - config/routes.rb
96
- - db/migrate/20221014183623_devise_create_ombu_labs_auth_users.rb
97
143
  - lib/ombu_labs/auth.rb
98
144
  - lib/ombu_labs/auth/engine.rb
99
145
  - lib/ombu_labs/auth/version.rb
@@ -120,8 +166,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
120
166
  - !ruby/object:Gem::Version
121
167
  version: '0'
122
168
  requirements: []
123
- rubygems_version: 3.3.7
169
+ rubygems_version: 3.3.26
124
170
  signing_key:
125
171
  specification_version: 4
126
- summary: Ombulabs internal authentication gem
172
+ summary: OmbuLabs internal authentication gem
127
173
  test_files: []
@@ -1 +0,0 @@
1
- //= link_directory ../stylesheets/ombu_labs/auth .css
@@ -1,15 +0,0 @@
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
- */
@@ -1,6 +0,0 @@
1
- module OmbuLabs
2
- module Auth
3
- module ApplicationHelper
4
- end
5
- end
6
- end
@@ -1,6 +0,0 @@
1
- module OmbuLabs
2
- module Auth
3
- class ApplicationJob < ActiveJob::Base
4
- end
5
- end
6
- end
@@ -1,8 +0,0 @@
1
- module OmbuLabs
2
- module Auth
3
- class ApplicationMailer < ActionMailer::Base
4
- default from: "from@example.com"
5
- layout "mailer"
6
- end
7
- end
8
- end
@@ -1,7 +0,0 @@
1
- module OmbuLabs
2
- module Auth
3
- class ApplicationRecord < ActiveRecord::Base
4
- self.abstract_class = true
5
- end
6
- end
7
- end
@@ -1,20 +0,0 @@
1
- module OmbuLabs::Auth
2
- class User < ApplicationRecord
3
- self.table_name = "users"
4
-
5
- # Include default devise modules. Others available are:
6
- # :confirmable, :lockable, :timeoutable
7
- devise :database_authenticatable, :registerable,
8
- :recoverable, :rememberable, :trackable,
9
- :validatable, :omniauthable
10
-
11
- def self.from_omniauth(auth)
12
- user_attributes = {
13
- email: auth.info.email,
14
- name: auth.info.name,
15
- password: Devise.friendly_token[0, 20]
16
- }
17
- where(provider: auth.provider, uid: auth.uid).first_or_create.tap { |user| user.update(user_attributes) }
18
- end
19
- end
20
- end
@@ -1,5 +0,0 @@
1
- <%- if devise_mapping.omniauthable? %>
2
- <%- resource_class.omniauth_providers.each do |provider| %>
3
- <%= link_to "Sign in with #{OmniAuth::Utils.camelize(provider)}", omniauth_authorize_path(resource_name, provider), class: "button", id:"back" %><br />
4
- <% end -%>
5
- <% end -%>
@@ -1,17 +0,0 @@
1
- <!DOCTYPE html>
2
- <html>
3
- <head>
4
- <title>Ombu labs auth</title>
5
- <%= csrf_meta_tags %>
6
- <%= csp_meta_tag %>
7
-
8
- <%= stylesheet_link_tag "ombu_labs/auth/application", media: "all" %>
9
- </head>
10
- <body>
11
-
12
- <p class="notice"><%= notice %></p>
13
- <p class="alert"><%= alert %></p>
14
- <%= yield %>
15
-
16
- </body>
17
- </html>
@@ -1,5 +0,0 @@
1
- require "active_support/core_ext/integer/time"
2
-
3
- Rails.application.configure do
4
- config.action_mailer.default_url_options = { host: 'localhost', port: 3000 }
5
- end
@@ -1,44 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- class DeviseCreateOmbuLabsAuthUsers < ActiveRecord::Migration[7.0]
4
- def change
5
- create_table :users do |t|
6
- ## Database authenticatable
7
- t.string :email, null: false, default: ""
8
- t.string :encrypted_password, null: false, default: ""
9
-
10
- ## Recoverable
11
- t.string :reset_password_token
12
- t.datetime :reset_password_sent_at
13
-
14
- ## Rememberable
15
- t.datetime :remember_created_at
16
-
17
- ## Trackable
18
- t.integer :sign_in_count, default: 0, null: false
19
- t.datetime :current_sign_in_at
20
- t.datetime :last_sign_in_at
21
- t.string :current_sign_in_ip
22
- t.string :last_sign_in_ip
23
-
24
- ## Confirmable
25
- # t.string :confirmation_token
26
- # t.datetime :confirmed_at
27
- # t.datetime :confirmation_sent_at
28
- # t.string :unconfirmed_email # Only if using reconfirmable
29
-
30
- ## Lockable
31
- # t.integer :failed_attempts, default: 0, null: false # Only if lock strategy is :failed_attempts
32
- # t.string :unlock_token # Only if unlock strategy is :email or :both
33
- # t.datetime :locked_at
34
-
35
-
36
- t.timestamps null: false
37
- end
38
-
39
- add_index :users, :email, unique: true
40
- add_index :users, :reset_password_token, unique: true
41
- # add_index :users, :confirmation_token, unique: true
42
- # add_index :users, :unlock_token, unique: true
43
- end
44
- end