rodauth-omniauth 0.4.0 → 0.5.1

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: 21b889e9c675d3fd02f65444f581e44965cb84982dd136fb912a5c9e6fb67c8c
4
- data.tar.gz: 12a5f50598b671065998b012b9c54997dffa225d5d208d0a25ea90a48bfe3e8b
3
+ metadata.gz: dad995353c13952f65bb35c561c82d755f2319318ac2409adc948b4b95fd6171
4
+ data.tar.gz: 30bdc64ac42ad66ff6003e5d95ffd5123ce9564661157ffb25f0f496e2772a3e
5
5
  SHA512:
6
- metadata.gz: f54a94233c789532139f2e07173e5162209674cf8f90c441df0e603b49b5840b4edad89a0b2e7f9a48c25856ba2d64c9dfed31ff6e61ad219d1ee2725a0d8c03
7
- data.tar.gz: c7d3c6db0088e544890cf7be482038d6c9f52c42a95082a5cc5d5bc1ba2dcf92ec7614d6c23b793f1814ac4ffb1272d280d67c527d023d1d437705a5383b608d
6
+ metadata.gz: '099007ffbf1e055d03625fbe9d90d3b032c27a83803a900e8f3b859dc2b8f350cc10fca07e92668dd49543c1e612a01bc4b0ba582066b633ef147883715a27fa'
7
+ data.tar.gz: 699b0e8890e5b117c69bf6b7a6aa89e140aebea976ec56455feaee688ef260e7dc71bb9cbc7bc05397ffef6a40f6c4d1260ef5f7885958e6213e4adc7541e270
data/README.md CHANGED
@@ -55,7 +55,8 @@ plugin :rodauth do
55
55
  end
56
56
  ```
57
57
 
58
- It is important to note that `rodauth-omniauth` requires OmniAuth 2.x, and as such, is only compatible with omniauth gems that use the same.
58
+ > [!NOTE]
59
+ > It is important to note that `rodauth-omniauth` requires OmniAuth 2.x, so it's only compatible with providers gems that support it.
59
60
 
60
61
  You can now add authentication links to your login form:
61
62
 
@@ -87,6 +88,15 @@ account.identities #=> [#<Account::Identity ...>, ...]
87
88
 
88
89
  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.
89
90
 
91
+ ### Timestamps
92
+
93
+ If you'll be adding created/updated timestamps to the identities table, also add these lines to your Rodauth configuration:
94
+
95
+ ```rb
96
+ omniauth_identity_insert_hash { super().merge(created_at: Time.now) }
97
+ omniauth_identity_update_hash { { updated_at: Time.now } }
98
+ ```
99
+
90
100
  ### Login
91
101
 
92
102
  After provider login, you can perform custom logic at the start of the callback request:
@@ -126,7 +136,7 @@ omniauth_login_failure_redirect { require_login_redirect }
126
136
 
127
137
  ### Account creation
128
138
 
129
- Accounts created via external login are automatically verified, because it's assumed your email address was verified by the external provider. If you want to use extra user information for account creation, you can do so via hooks:
139
+ Accounts created via external login are automatically verified, because it's assumed your email address was verified by the external provider. If you want to add extra user information to created accounts, you can do so via hooks:
130
140
 
131
141
  ```rb
132
142
  before_omniauth_create_account { account[:name] = omniauth_name }
@@ -136,7 +146,22 @@ after_omniauth_create_account do
136
146
  end
137
147
  ```
138
148
 
139
- When the account is closed, its external identities are automatically deleted from the database.
149
+ You might want to disable automatic account creation in certain cases. For example, if you're showing OmniAuth login links on both login and registration pages, you might want OmniAuth login on the login page to only log into existing accounts. You could configure this so that it's controlled via a query parameter:
150
+
151
+ ```rb
152
+ # somewhere in your view template:
153
+ rodauth.omniauth_request_path(:google, action: "login") #=> "/auth/github?action=login"
154
+ ```
155
+ ```rb
156
+ # in your Rodauth configuration:
157
+ omniauth_create_account? { omniauth_params["action"] != "login" }
158
+ ```
159
+
160
+ You can change the default error message for when existing account wasn't found in case automatic account creation is disabled:
161
+
162
+ ```rb
163
+ omniauth_login_no_matching_account_error_flash "No existing account found"
164
+ ```
140
165
 
141
166
  ### Identity data
142
167
 
@@ -183,6 +208,16 @@ omniauth_identities_provider_column :provider
183
208
  omniauth_identities_uid_column :uid
184
209
  ```
185
210
 
211
+ ### Audit logging
212
+
213
+ If you're using the `audit_logging` feature, it can be useful to include the external provider name in the `login` audit logs:
214
+
215
+ ```rb
216
+ audit_log_metadata_for :login do
217
+ { "provider" => omniauth_provider } if authenticated_by.include?("omniauth")
218
+ end
219
+ ```
220
+
186
221
  ## Base
187
222
 
188
223
  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.
@@ -11,6 +11,7 @@ module Rodauth
11
11
  after :omniauth_create_account
12
12
 
13
13
  error_flash "The account matching the external identity is currently awaiting verification", :omniauth_login_unverified_account
14
+ error_flash "There is no existing account matching the external identity", :omniauth_login_no_matching_account
14
15
 
15
16
  redirect(:omniauth_login_failure) { require_login_redirect }
16
17
 
@@ -22,6 +23,7 @@ module Rodauth
22
23
 
23
24
  auth_value_methods(
24
25
  :omniauth_verify_account?,
26
+ :omniauth_create_account?,
25
27
  )
26
28
 
27
29
  auth_methods(
@@ -76,11 +78,16 @@ module Rodauth
76
78
  end
77
79
 
78
80
  transaction do
79
- unless account
80
- omniauth_new_account
81
- before_omniauth_create_account
82
- omniauth_save_account
83
- after_omniauth_create_account
81
+ if !account
82
+ if omniauth_create_account?
83
+ omniauth_new_account
84
+ before_omniauth_create_account
85
+ omniauth_save_account
86
+ after_omniauth_create_account
87
+ else
88
+ set_redirect_error_flash omniauth_login_no_matching_account_error_flash
89
+ redirect omniauth_login_failure_redirect
90
+ end
84
91
  end
85
92
 
86
93
  if omniauth_identity
@@ -119,7 +126,7 @@ module Rodauth
119
126
 
120
127
  def possible_authentication_methods
121
128
  methods = super
122
- methods << "omniauth" unless methods.include?("password") || omniauth_account_identities_ds.empty?
129
+ methods << "omniauth" unless methods.include?("password") || (features.include?(:email_auth) && allow_email_auth?) || omniauth_account_identities_ds.empty?
123
130
  methods
124
131
  end
125
132
 
@@ -135,10 +142,6 @@ module Rodauth
135
142
  remove_omniauth_identities
136
143
  end
137
144
 
138
- def allow_email_auth?
139
- (defined?(super) ? super : true) && omniauth_account_identities_ds.empty?
140
- end
141
-
142
145
  attr_reader :omniauth_identity
143
146
 
144
147
  def omniauth_verify_account?
@@ -152,6 +155,10 @@ module Rodauth
152
155
  end
153
156
  end
154
157
 
158
+ def omniauth_create_account?
159
+ true
160
+ end
161
+
155
162
  def _omniauth_new_account(login)
156
163
  acc = { login_column => login }
157
164
  unless skip_status_checks?
data/locales/en.yml CHANGED
@@ -2,3 +2,4 @@ en:
2
2
  rodauth:
3
3
  omniauth_failure_error_flash: There was an error logging in with the external provider
4
4
  omniauth_login_unverified_account_error_flash: The account matching the external identity is currently awaiting verification
5
+ omniauth_login_no_matching_account_error_flash: There is no existing account matching the external identity
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |spec|
2
2
  spec.name = "rodauth-omniauth"
3
- spec.version = "0.4.0"
3
+ spec.version = "0.5.1"
4
4
  spec.authors = ["Janko Marohnić"]
5
5
  spec.email = ["janko@hey.com"]
6
6
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rodauth-omniauth
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.5.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Janko Marohnić
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-09-02 00:00:00.000000000 Z
11
+ date: 2024-10-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rodauth