rodauth-omniauth 0.4.0 → 0.5.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: 21b889e9c675d3fd02f65444f581e44965cb84982dd136fb912a5c9e6fb67c8c
4
- data.tar.gz: 12a5f50598b671065998b012b9c54997dffa225d5d208d0a25ea90a48bfe3e8b
3
+ metadata.gz: bcd1857e0bfd2329c4df0476d8f5091bac5f45c9bd47de6c8c3ef53a99bf0a64
4
+ data.tar.gz: 57ddd4e9b6e8baf00b66da1f580b01762a0c118f7c962f520a026f6ef94bbfc3
5
5
  SHA512:
6
- metadata.gz: f54a94233c789532139f2e07173e5162209674cf8f90c441df0e603b49b5840b4edad89a0b2e7f9a48c25856ba2d64c9dfed31ff6e61ad219d1ee2725a0d8c03
7
- data.tar.gz: c7d3c6db0088e544890cf7be482038d6c9f52c42a95082a5cc5d5bc1ba2dcf92ec7614d6c23b793f1814ac4ffb1272d280d67c527d023d1d437705a5383b608d
6
+ metadata.gz: 9bebec705884e246bd20bee55771711d3fff5d82c9c7f711099e09ac1196e2af8ce0c5d9e1456035da429e33c7439d7ae8c2350b6b33c6081c54f74a93992b74
7
+ data.tar.gz: 53be14c4e20dff0c17e988b46cc7e0c700b810c6fc7a4440eb94a63abeee9659f9ad880427ce7205dd0fe9c6757b6e48a6e1e99411b1304dba8f011327936246
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
 
@@ -126,7 +127,7 @@ omniauth_login_failure_redirect { require_login_redirect }
126
127
 
127
128
  ### Account creation
128
129
 
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:
130
+ 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
131
 
131
132
  ```rb
132
133
  before_omniauth_create_account { account[:name] = omniauth_name }
@@ -136,7 +137,16 @@ after_omniauth_create_account do
136
137
  end
137
138
  ```
138
139
 
139
- When the account is closed, its external identities are automatically deleted from the database.
140
+ 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:
141
+
142
+ ```rb
143
+ # somewhere in your view template:
144
+ rodauth.omniauth_request_path(:google, action: "login") #=> "/auth/github?action=login"
145
+ ```
146
+ ```rb
147
+ # in your Rodauth configuration:
148
+ omniauth_create_account? { omniauth_params["action"] != "login" }
149
+ ```
140
150
 
141
151
  ### Identity data
142
152
 
@@ -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
@@ -152,6 +159,10 @@ module Rodauth
152
159
  end
153
160
  end
154
161
 
162
+ def omniauth_create_account?
163
+ true
164
+ end
165
+
155
166
  def _omniauth_new_account(login)
156
167
  acc = { login_column => login }
157
168
  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.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.4.0
4
+ version: 0.5.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: 2024-09-02 00:00:00.000000000 Z
11
+ date: 2024-10-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rodauth