rodauth-omniauth 0.1.0 → 0.2.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: 99f2cd5c47082f18ff2b0feeea0106c104edf6454e354fb04f8c74044b7796b2
4
- data.tar.gz: 58c096a1176cce8c2aa1ef0741c35e0ec81a36fb1d3d7bf9350b01c143daffdb
3
+ metadata.gz: '09378dc7c637faa7d96d3945b5e0bb32fe9327b8e2c78ea86eb345b768ee5f25'
4
+ data.tar.gz: dd2f61b20ee67a9355cd94a81ccac34839550a6f3b41256a36d6d9af7f686188
5
5
  SHA512:
6
- metadata.gz: 3ee9f500a18535a215d74d6cbc250561a7d0b61cc5818166e7bf481b74bf67dedf2547228ffbec177273715d1001cce2178e7590cadc8c21b102ef1b9585f9c5
7
- data.tar.gz: fe0337fdc2ef82ea53c5b8514383df10d60433900deaa35fa519ffe0e846c3a5e79deead46b1e790e29a35ffac0a00a2301c6437376d8fd91832d8ee1cb49a8e
6
+ metadata.gz: bdd33ddd3adf2afd16bc0b91a46817368cfa6c66c7f3ad75b085af82f1b78901b0d06892397cbe2e30dbf0799de655e4066da58448a948005d1e1702ae1f25f4
7
+ data.tar.gz: f7adbf2ebc5d1bd922b65b4cb015d768744121b83ad60dc107f9545ea427f434b5815722dfbb5280a4bacb94c42a26dfccc4f5a9d0aa2efafc8a863af0e5887a
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # rodauth-omniauth
2
2
 
3
- [Rodauth] feature that offers login and registration via multiple external providers using [OmniAuth]. The external identities are automatically stored in the database, and associated to the main account record.
3
+ [Rodauth] feature that offers login and registration via multiple external providers using [OmniAuth], together with the persistence of external identities.
4
4
 
5
5
  ## Installation
6
6
 
@@ -15,16 +15,28 @@ $ bundle add rodauth-omniauth
15
15
  You'll first need to create the table for storing external identities:
16
16
 
17
17
  ```rb
18
- Sequel.migration do # class CreateAccountIdentities < ActiveRecord::Migration
19
- change do # def change
20
- create_table :account_identities do # create_table :account_identities do |t|
21
- primary_key :id # t.references :account, null: false, foreign_key: { on_delete: :cascade }
22
- foreign_key :account_id, :accounts # t.string :provider, null: false
23
- String :provider, null: false # t.string :uid, null: false
24
- String :uid, null: false # t.index [:provider, :uid], unique: true
25
- unique [:provider, :uid] # end
26
- end # end
27
- end # end
18
+ Sequel.migration do
19
+ change do
20
+ create_table :account_identities do
21
+ primary_key :id
22
+ foreign_key :account_id, :accounts
23
+ String :provider, null: false
24
+ String :uid, null: false
25
+ unique [:provider, :uid]
26
+ end
27
+ end
28
+ end
29
+ ```
30
+ ```rb
31
+ class CreateAccountIdentities < ActiveRecord::Migration
32
+ def change
33
+ create_table :account_identities do |t|
34
+ t.references :account, null: false, foreign_key: { on_delete: :cascade }
35
+ t.string :provider, null: false
36
+ t.string :uid, null: false
37
+ t.index [:provider, :uid], unique: true
38
+ end
39
+ end
28
40
  end
29
41
  ```
30
42
 
@@ -47,16 +59,11 @@ You can now add authentication links to your login form:
47
59
 
48
60
  ```erb
49
61
  <!-- app/views/rodauth/_login_form_footer.html.erb -->
50
- <%== rodauth.login_form_footer_links_heading %>
51
-
52
- <ul>
62
+ <!-- ... -->
53
63
  <li><%= button_to "Login via Facebook", rodauth.omniauth_request_path(:facebook), method: :post, data: { turbo: false }, class: "btn btn-link p-0" %></li>
54
64
  <li><%= button_to "Login via Twitter", rodauth.omniauth_request_path(:twitter), method: :post, data: { turbo: false }, class: "btn btn-link p-0" %></li>
55
65
  <li><%= button_to "Login via Google", rodauth.omniauth_request_path(:google), method: :post, data: { turbo: false }, class: "btn btn-link p-0" %></li>
56
- <% rodauth.login_form_footer_links.each do |_, link, text| %>
57
- <li><%= link_to text, link %></li>
58
- <% end %>
59
- </ul>
66
+ <!-- ... -->
60
67
  ```
61
68
 
62
69
  Assuming you configured the providers correctly, you should now be able to authenticate via an external provider. The `omniauth` feature handles the callback request, automatically creating new identities and verified accounts from those identities as needed.
@@ -73,6 +80,8 @@ Currently, provider login is required to return the user's email address, and ac
73
80
 
74
81
  ### Login
75
82
 
83
+ After provider login, if the external identity doesn't already exist, and there is an account with email matching the identity's, the new identity will be assigned to that account.
84
+
76
85
  If the local account associated to the external identity exists and is unverified (e.g. it was created through normal registration), the external login will abort during the callback phase. You can change the default error flash and redirect location in this case:
77
86
 
78
87
  ```rb
@@ -205,13 +214,13 @@ URL helpers are provided as well:
205
214
  rodauth.prefix #=> "/user"
206
215
  rodauth.omniauth_prefix #=> "/auth"
207
216
 
208
- rodauth.omniauth_request_route #=> "auth/facebook"
209
- rodauth.omniauth_request_path #=> "/user/auth/facebook"
210
- rodauth.omniauth_request_url #=> "https://example.com/user/auth/facebook"
217
+ rodauth.omniauth_request_route(:facebook) #=> "auth/facebook"
218
+ rodauth.omniauth_request_path(:facebook) #=> "/user/auth/facebook"
219
+ rodauth.omniauth_request_url(:facebook) #=> "https://example.com/user/auth/facebook"
211
220
 
212
- rodauth.omniauth_callback_route #=> "auth/facebook/callback"
213
- rodauth.omniauth_callback_path #=> "/user/auth/facebook/callback"
214
- rodauth.omniauth_callback_url #=> "https://example.com/user/auth/facebook/callback"
221
+ rodauth.omniauth_callback_route(:facebook) #=> "auth/facebook/callback"
222
+ rodauth.omniauth_callback_path(:facebook) #=> "/user/auth/facebook/callback"
223
+ rodauth.omniauth_callback_url(:facebook) #=> "https://example.com/user/auth/facebook/callback"
215
224
  ```
216
225
 
217
226
  The prefix for the OmniAuth app can be changed:
@@ -257,9 +266,9 @@ Or provide your own implementation:
257
266
  ```rb
258
267
  omniauth_on_failure do
259
268
  case omniauth_error_type
260
- when :no_authorization_code then ...
261
- when :uknown_signature_algorithm then ...
262
- else ...
269
+ when :no_authorization_code then # ...
270
+ when :uknown_signature_algorithm then # ...
271
+ else # ...
263
272
  end
264
273
  end
265
274
  ```
@@ -314,9 +323,11 @@ JSON requests are supported for the request and callback phases. The request pha
314
323
  POST /auth/facebook
315
324
  Accept: application/json
316
325
  Content-Type: application/json
317
-
326
+ ```
327
+ ```http
318
328
  200 OK
319
329
  Content-Type: application/json
330
+
320
331
  { "authorize_url": "https://external.com/login" }
321
332
  ```
322
333
 
@@ -326,9 +337,11 @@ If there was a login failure, the error type will be included in the response:
326
337
  POST /auth/facebook/callback
327
338
  Accept: application/json
328
339
  Content-Type: application/json
329
-
340
+ ```
341
+ ```http
330
342
  500 Internal Server Error
331
343
  Content-Type: application/json
344
+
332
345
  { "error_type": "some_error", "error": "There was an error logging in with the external provider" }
333
346
  ```
334
347
 
@@ -351,6 +364,10 @@ Run tests with Rake:
351
364
  $ bundle exec rake test
352
365
  ```
353
366
 
367
+ ## Credits
368
+
369
+ The implementation of this gem was inspired by [this OmniAuth guide](https://github.com/omniauth/omniauth/wiki/Managing-Multiple-Providers).
370
+
354
371
  ## License
355
372
 
356
373
  The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
@@ -0,0 +1,8 @@
1
+ # Used by the omniauth feature
2
+ create_table :account_identities do
3
+ primary_key :id
4
+ foreign_key :account_id, :accounts
5
+ String :provider, null: false
6
+ String :uid, null: false
7
+ unique [:provider, :uid]
8
+ end
@@ -112,6 +112,11 @@ module Rodauth
112
112
 
113
113
  private
114
114
 
115
+ def before_confirm_password
116
+ authenticated_by.delete("omniauth")
117
+ super if defined?(super)
118
+ end
119
+
115
120
  def allow_email_auth?
116
121
  (defined?(super) ? super : true) && omniauth_account_identities_ds.empty?
117
122
  end
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |spec|
2
2
  spec.name = "rodauth-omniauth"
3
- spec.version = "0.1.0"
3
+ spec.version = "0.2.0"
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.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Janko Marohnić
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-11-03 00:00:00.000000000 Z
11
+ date: 2022-11-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rodauth
@@ -159,6 +159,8 @@ extra_rdoc_files: []
159
159
  files:
160
160
  - LICENSE.txt
161
161
  - README.md
162
+ - lib/generators/rodauth/migration/active_record/omniauth.erb
163
+ - lib/generators/rodauth/migration/sequel/omniauth.erb
162
164
  - lib/rodauth/features/omniauth.rb
163
165
  - lib/rodauth/features/omniauth_base.rb
164
166
  - rodauth-omniauth.gemspec