rodauth-omniauth 0.6.0 → 0.6.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c91c4429c36390bbede1d97214cdb6a40c5a6f5d9255c379f3b17d026cee88c9
4
- data.tar.gz: 8e09d6d3c5d4d9eb0022dd5696e1370fc82c22bd068ec5b883212f2117ae3c47
3
+ metadata.gz: 0453fcafd04b57e1adf926663a9edb8d1f9f72f25aa952d193cf092fc877327f
4
+ data.tar.gz: 3a3211e64e8558d3fe5aea563498f79763e3ebed62e9bd964020f52f5be36857
5
5
  SHA512:
6
- metadata.gz: 03e77668f1f2c2076f003ac455c1f57dcfd5b60f7096cc77e5fe0918bf6484814ab02304eb9286e5323c42c2115102b262edb55dc41174dc0574c9ae0e6c84cc
7
- data.tar.gz: f90369c94f3d9baf82dda2490ff716e543cd6cd09a6c8b856b2ba41c0594bcce69a489755520e2aea898eaf6907611d31d53c7cbf2a5f3f0fff51a457511012d
6
+ metadata.gz: 005c3b00e023b15f033af4782dba58f0e8372b4573c17822d0d770a980568c691a85a8c16422b8d3193ade0e8bdcfdb5ca54a9cd0244465842ef51efb7a69b37
7
+ data.tar.gz: 282df1dd1951ce51c41af1622e95e486a925280e699e9e0caa438ff5528efea6954d8d1b20f412f620fa5a41f114872c4773aba110010f32cd19936540abc122
data/README.md CHANGED
@@ -2,6 +2,15 @@
2
2
 
3
3
  [Rodauth] feature that offers login and registration via multiple external providers using [OmniAuth], together with the persistence of external identities.
4
4
 
5
+ It comes with many features out of the box:
6
+
7
+ * multiple external providers (with automatic identity linking)
8
+ * automatic account creation (or login-only)
9
+ * email verification on login
10
+ * ability to count as two factors
11
+ * JSON API support (+ JWT)
12
+ * per-configuration strategies with inheritance
13
+
5
14
  ## Installation
6
15
 
7
16
  Add the gem to your project:
@@ -14,7 +23,7 @@ $ bundle add rodauth-omniauth
14
23
  > Rodauth's CSRF protection will be used for the request validation phase, so there is no need for gems like `omniauth-rails_csrf_protection`.
15
24
 
16
25
 
17
- ## Usage
26
+ ## Getting started
18
27
 
19
28
  You'll first need to create the table for storing external identities:
20
29
 
@@ -91,23 +100,47 @@ account.identities #=> [#<Account::Identity ...>, ...]
91
100
 
92
101
  Currently, provider login is required to return the user's email address, and account creation is assumed not to require additional fields that need to be entered manually. There is currently also no built-in functionality for connecting/removing external identities when signed in. Both features are planned for future versions.
93
102
 
94
- ### Timestamps
95
-
96
- If you want to know when an external identity was used first or last, you may want to add timestamp columns to the identities table:
97
-
98
- ```rb
99
- create_table :account_identities do |t|
100
- # ...
101
- t.timestamps
102
- end
103
- ```
104
-
105
- In that case, you'll need to make sure the column values are populated on create/update:
106
-
107
- ```rb
108
- omniauth_identity_insert_hash { super().merge(created_at: Time.now) }
109
- omniauth_identity_update_hash { { updated_at: Time.now } }
110
- ```
103
+ ## Configuration reference
104
+
105
+ ### Auth Value Methods
106
+
107
+ | Method | Description |
108
+ | :---- | :---------- |
109
+ | `omniauth_verify_account?` | Automatically verify unverified accounts on login (defaults to true). |
110
+ | `omniauth_login_unverified_account_error_flash` | Flash message for when existing account is unverified and automatic verification is disabled. |
111
+ | `omniauth_login_failure_redirect` | Redirect location for when OmniAuth login failed. |
112
+ | `omniauth_create_account?` | Automatically create account for new email address on OmniAuth login (defaults to true). |
113
+ | `omniauth_login_no_matching_account_error_flash` | Flash message for when no existing account was found and automatic creation is disabled. |
114
+ | `omniauth_two_factors?` | Treat OmniAuth login as two factors when using MFA (defaults to false). |
115
+ | `omniauth_identities_table` | Table name for external identities (defaults to `account_identities`). |
116
+ | `omniauth_identities_id_column` | Primary key column for identities table (defaults to `id`). |
117
+ | `omniauth_identities_account_id_column` | Foreign key column for identities table (defaults to `account_id`). |
118
+ | `omniauth_identities_provider_column` | Provider column for identities table (defaults to `provider`). |
119
+ | `omniauth_identities_uid_column` | UID column for identities table (defaults to `uid`). |
120
+ | `omniauth_prefix` | Path prefix to use for OmniAuth routes (defaults to `/auth`). |
121
+ | `omniauth_failure_error_flash` | Flash message for failed OmniAuth login. |
122
+ | `omniauth_failure_redirect` | Redirect location for failed OmniAuth login. |
123
+ | `omniauth_failure_error_status` | Response status for failed OmniAuth login (defaults to 500). |
124
+ | `omniauth_authorize_url_key` | Field name for authorization URL in JSON mode. |
125
+ | `omniauth_error_type_key` | Field name for error type in JSON mode. |
126
+
127
+ ### Auth Methods
128
+
129
+ | Method | Description |
130
+ | :---- | :---------- |
131
+ | `account_from_omniauth` | Find an existing account from OmniAuth login data (by default matches by email). |
132
+ | `before_omniauth_callback_route` | Run arbitrary code before handling the callback route. |
133
+ | `omniauth_identity_insert_hash` | Hash of column values used for creating a new identity on login. |
134
+ | `omniauth_identity_update_hash` | Hash of column values used fro updating existing identities on login. |
135
+ | `before_omniauth_create_account` | Any actions to take before creating a new account on OmniAuth login. |
136
+ | `after_omniauth_create_account` | Any actions to take after creating a new account on OmniAuth login. |
137
+ | `omniauth_setup` | Hook for OmniAuth setup phase |
138
+ | `omniauth_request_validation_phase` | Hook for OmniAuth request validation phase (defaults to CSRF protection). |
139
+ | `omniauth_before_request_phase` | Hook for OmniAuth before request phase. |
140
+ | `omniauth_before_callback_phase` | Hook for OmniAuth before callback phase. |
141
+ | `omniauth_on_failure` | Hook for OmniAuth login failure. |
142
+
143
+ ## Customizing
111
144
 
112
145
  ### Login
113
146
 
@@ -196,7 +229,7 @@ end
196
229
 
197
230
  ### Identity data
198
231
 
199
- You can also store extra data on the external identities. For example, we could override the update hash to store `info`, `credentials`, and `extra` data from the auth hash into separate columns:
232
+ You can also store extra data on the external identities. The most common use case is storing [timestamps](https://github.com/janko/rodauth-omniauth/wiki/Timestamps). You could also persist data about external identities, for example:
200
233
 
201
234
  ```rb
202
235
  alter_table :account_identities do
@@ -229,6 +262,8 @@ omniauth_identity_insert_hash do
229
262
  end
230
263
  ```
231
264
 
265
+ ### Identity schema
266
+
232
267
  You can change the table name or any of the column names:
233
268
 
234
269
  ```rb
@@ -239,18 +274,6 @@ omniauth_identities_provider_column :provider
239
274
  omniauth_identities_uid_column :uid
240
275
  ```
241
276
 
242
- ### Audit logging
243
-
244
- If you're using the [audit_logging] feature, it can be useful to include the external provider name in the `login` audit logs:
245
-
246
- ```rb
247
- enable :audit_logging
248
-
249
- audit_log_metadata_for :login do
250
- { "provider" => omniauth_provider } if authenticated_by.include?("omniauth")
251
- end
252
- ```
253
-
254
277
  ## Base
255
278
 
256
279
  The `omniauth` feature builds on top of the `omniauth_base` feature, which sets up OmniAuth and routes its requests, but has no interaction with the database. So, if you would prefer to handle external logins differently, you can load just the `omniauth_base` feature, and implement your own callback phase.
@@ -483,4 +506,3 @@ Everyone interacting in the rodauth-omniauth project's codebases, issue trackers
483
506
  [rodauth-model]: https://github.com/janko/rodauth-model
484
507
  [rodauth-rails]: https://github.com/janko/rodauth-rails
485
508
  [omniauth-oauth2]: https://github.com/omniauth/omniauth-oauth2
486
- [audit_logging]: https://rodauth.jeremyevans.net/rdoc/files/doc/audit_logging_rdoc.html
@@ -58,14 +58,12 @@ module Rodauth
58
58
  def _handle_omniauth_callback
59
59
  before_omniauth_callback_route
60
60
 
61
- retrieve_omniauth_identity
62
-
63
- if !account && omniauth_identity
64
- account_from_omniauth_identity
65
- end
66
-
67
61
  unless account
68
- account_from_omniauth
62
+ if omniauth_identity
63
+ account_from_omniauth_identity
64
+ else
65
+ account_from_omniauth
66
+ end
69
67
  end
70
68
 
71
69
  if account && !open_account?
@@ -81,10 +79,7 @@ module Rodauth
81
79
  transaction do
82
80
  if !account
83
81
  if omniauth_create_account?
84
- omniauth_new_account
85
- before_omniauth_create_account
86
- omniauth_save_account
87
- after_omniauth_create_account
82
+ omniauth_create_account
88
83
  else
89
84
  set_redirect_error_flash omniauth_login_no_matching_account_error_flash
90
85
  redirect omniauth_login_failure_redirect
@@ -103,8 +98,12 @@ module Rodauth
103
98
  end
104
99
  end
105
100
 
101
+ def omniauth_identity
102
+ @omniauth_identity ||= retrieve_omniauth_identity
103
+ end
104
+
106
105
  def retrieve_omniauth_identity
107
- @omniauth_identity = _retrieve_omniauth_identity(omniauth_provider, omniauth_uid)
106
+ _retrieve_omniauth_identity(omniauth_provider, omniauth_uid)
108
107
  end
109
108
 
110
109
  def account_from_omniauth_identity
@@ -145,8 +144,6 @@ module Rodauth
145
144
  remove_omniauth_identities
146
145
  end
147
146
 
148
- attr_reader :omniauth_identity
149
-
150
147
  def omniauth_second_factor?
151
148
  features.include?(:two_factor_base) && uses_two_factor_authentication? && omniauth_two_factors?
152
149
  end
@@ -166,6 +163,13 @@ module Rodauth
166
163
  true
167
164
  end
168
165
 
166
+ def omniauth_create_account
167
+ omniauth_new_account
168
+ before_omniauth_create_account
169
+ omniauth_save_account
170
+ after_omniauth_create_account
171
+ end
172
+
169
173
  def _omniauth_new_account(login)
170
174
  acc = { login_column => login }
171
175
  unless skip_status_checks?
@@ -195,10 +195,12 @@ module Rodauth
195
195
  end
196
196
 
197
197
  def self.included(auth)
198
- auth.extend ClassMethods
198
+ auth.extend OmniauthBase::ClassMethods
199
199
  auth.instance_variable_set(:@omniauth_providers, [])
200
200
  end
201
+ end
201
202
 
203
+ module OmniauthBase
202
204
  module ClassMethods
203
205
  def inherited(subclass)
204
206
  super
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |spec|
2
2
  spec.name = "rodauth-omniauth"
3
- spec.version = "0.6.0"
3
+ spec.version = "0.6.1"
4
4
  spec.authors = ["Janko Marohnić"]
5
5
  spec.email = ["janko@hey.com"]
6
6
 
metadata CHANGED
@@ -1,14 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rodauth-omniauth
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.0
4
+ version: 0.6.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Janko Marohnić
8
- autorequire:
9
8
  bindir: bin
10
9
  cert_chain: []
11
- date: 2024-11-29 00:00:00.000000000 Z
10
+ date: 1980-01-02 00:00:00.000000000 Z
12
11
  dependencies:
13
12
  - !ruby/object:Gem::Dependency
14
13
  name: rodauth
@@ -197,7 +196,6 @@ licenses:
197
196
  metadata:
198
197
  homepage_uri: https://github.com/janko/rodauth-omniauth
199
198
  source_code_uri: https://github.com/janko/rodauth-omniauth
200
- post_install_message:
201
199
  rdoc_options: []
202
200
  require_paths:
203
201
  - lib
@@ -212,8 +210,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
212
210
  - !ruby/object:Gem::Version
213
211
  version: '0'
214
212
  requirements: []
215
- rubygems_version: 3.5.23
216
- signing_key:
213
+ rubygems_version: 3.6.9
217
214
  specification_version: 4
218
215
  summary: Rodauth extension for logging in and creating account via OmniAuth authentication.
219
216
  test_files: []