rails_simple_auth 1.2.0 → 1.2.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: e08c83add50f655ddb8b4a064ea3378fa4f6da3ce0455267e572749221650441
4
- data.tar.gz: 4907167244666a084c8afeb159cb7e1af90bce5ec77992eeb22f2b4e1ac1c4a4
3
+ metadata.gz: 92f4718f32ac9f010bc24be665915952c9dcf5d02340c07e7692b2a053a282ce
4
+ data.tar.gz: 71ba9817ebe4fcefd815aa47e0f99d02261349d78a0532b0a6f3fca22442d6ab
5
5
  SHA512:
6
- metadata.gz: fa89e4d892c0abe0a12fd68ea5dfc7e8d9bd064c57857b3d3ec9102efe9e02ec32a05038e1b7d54465260a06f20c6d8898b7ce774199b30e40ffba01d7c17702
7
- data.tar.gz: 490267496b49a4a1d118c687e0f2944e5ce4452c5287161b14594d926cc1b41021b09d90a8ea22e322aead5fae2e0cc421187d8f8ee8d74dfa54421477160c04
6
+ metadata.gz: 97e9c562f6993c03661ef81eee4e534ad25496b3f36f3f46d1b559a860835a8dde49f190eeed0368a5abc7d0d06e11d2a596873d75af7484983f3afe043397d5
7
+ data.tar.gz: cf069335a5b94f84b163057116730d1feb4d428d43b9c3ccb5da056f73b92a13ef2dbeda7cf8c939c858480243bcf93e47ec7899f63c12864398d21d4fcd43c3
data/CHANGELOG.md CHANGED
@@ -7,6 +7,14 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
7
7
 
8
8
  ## [Unreleased]
9
9
 
10
+ ## [1.2.1] - 2026-09-15
11
+
12
+ ### Fixed
13
+
14
+ - OAuth linking reloads the account under a row lock so concurrent confirmation or pending email changes are preserved; if the matched email changes before linking, sign-in is rejected.
15
+ - Confirm existing accounts when linking by email through a trusted OAuth provider, before calling the host application's `assign_oauth_attributes` hook. Preserve existing confirmation timestamps and pending email changes. Accounts found by provider and UID remain unchanged.
16
+ - Return `nil` when saving an existing OAuth account link fails, preventing authentication with unsaved changes.
17
+
10
18
  ## [1.2.0] - 2026-05-23
11
19
 
12
20
  ### Changed
data/README.md CHANGED
@@ -217,6 +217,12 @@ class User < ApplicationRecord
217
217
  end
218
218
  ```
219
219
 
220
+ Email-based account linking is enabled by default (`config.oauth_link_existing_accounts = true`). Only enable it for providers you trust to supply verified email addresses; the gem does not inspect provider-specific verification claims. Set it to `false` to reject linking by email.
221
+
222
+ New OAuth accounts and existing accounts linked by email are automatically confirmed when they have a `confirmed_at` column. Existing confirmation timestamps and pending email changes are preserved. Confirmation is assigned before `assign_oauth_attributes`, so your hook can use it to update application-specific state. The hook and confirmation changes are saved together; a failed save returns `nil`.
223
+
224
+ Accounts found by provider and UID return unchanged, including their email and confirmation state. Applications with historical unconfirmed OAuth accounts should handle their backfill separately.
225
+
220
226
  ## Temporary Users (Guest Accounts)
221
227
 
222
228
  Temporary users allow visitors to try your app without creating an account. They get a real user record with full functionality, then can convert to a permanent account later by providing email and password.
@@ -41,16 +41,38 @@ module RailsSimpleAuth
41
41
  existing_user = find_by_email(email)
42
42
  if existing_user
43
43
  # Configurable: allow linking OAuth to existing accounts
44
- # Default is true - most OAuth providers (Google, GitHub) verify emails
44
+ # Only enable for providers trusted to supply verified email addresses.
45
45
  if RailsSimpleAuth.configuration.oauth_link_existing_accounts
46
- Rails.logger.info(
47
- "[RailsSimpleAuth] OAuth linked to existing account: #{email}. " \
48
- "Provider: #{provider}."
49
- )
50
- # Call hook to store OAuth credentials on existing user
51
- existing_user.assign_oauth_attributes(auth_hash) if existing_user.respond_to?(:assign_oauth_attributes)
52
- existing_user.save if existing_user.changed?
53
- return existing_user
46
+ matched_email = existing_user.email
47
+ return existing_user.with_lock do
48
+ # Reload under the lock before checking confirmation state.
49
+ next nil if existing_user.email != matched_email
50
+
51
+ # Confirm the current email only; OAuth does not verify a pending replacement.
52
+ pending_email = existing_user.respond_to?(:unconfirmed_email) &&
53
+ existing_user.unconfirmed_email.present?
54
+ if existing_user.respond_to?(:confirmed_at=) && existing_user.confirmed_at.nil? && !pending_email
55
+ existing_user.confirmed_at = Time.current
56
+ end
57
+
58
+ # Call hook to store OAuth credentials on existing user
59
+ if existing_user.respond_to?(:assign_oauth_attributes)
60
+ existing_user.assign_oauth_attributes(auth_hash)
61
+ end
62
+ if existing_user.changed? && !existing_user.save
63
+ Rails.logger.error(
64
+ "[RailsSimpleAuth] OAuth account linking failed for email: #{email}, " \
65
+ "provider: #{provider}, errors: #{existing_user.errors.full_messages.join(', ')}"
66
+ )
67
+ next nil
68
+ end
69
+
70
+ Rails.logger.info(
71
+ "[RailsSimpleAuth] OAuth linked to existing account: #{email}. " \
72
+ "Provider: #{provider}."
73
+ )
74
+ existing_user
75
+ end
54
76
  else
55
77
  Rails.logger.warn(
56
78
  "[RailsSimpleAuth] OAuth login rejected for existing email: #{email}. " \
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module RailsSimpleAuth
4
- VERSION = '1.2.0'
4
+ VERSION = '1.2.1'
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rails_simple_auth
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.0
4
+ version: 1.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ivan Kuznetsov
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2026-05-23 00:00:00.000000000 Z
11
+ date: 2026-09-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bcrypt