mirror of
https://github.com/we-promise/sure.git
synced 2026-04-19 03:54:08 +00:00
Eliminate code duplication in OIDC identity creation (#230)
* Eliminate duplication by using create_from_omniauth method - Updated OidcIdentity.create_from_omniauth to set last_authenticated_at - Refactored OidcAccountsController to use create_from_omniauth instead of direct create! calls - Updated test to verify last_authenticated_at is set by create_from_omniauth Co-authored-by: jjmata <187772+jjmata@users.noreply.github.com> * Extract auth hash building into private helper method - Added build_auth_hash helper method to eliminate OpenStruct creation duplication - Both create_link and create_user actions now use the same helper Co-authored-by: jjmata <187772+jjmata@users.noreply.github.com> * Linter fix * Fix button style on OIDC link step * Fix dark mode styles --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: jjmata <187772+jjmata@users.noreply.github.com> Co-authored-by: Juan José Mata <juanjo.mata@gmail.com>
This commit is contained in:
@@ -28,16 +28,9 @@ class OidcAccountsController < ApplicationController
|
||||
|
||||
if user
|
||||
# Create the OIDC identity link
|
||||
oidc_identity = user.oidc_identities.create!(
|
||||
provider: @pending_auth["provider"],
|
||||
uid: @pending_auth["uid"],
|
||||
info: {
|
||||
email: @pending_auth["email"],
|
||||
name: @pending_auth["name"],
|
||||
first_name: @pending_auth["first_name"],
|
||||
last_name: @pending_auth["last_name"]
|
||||
},
|
||||
last_authenticated_at: Time.current
|
||||
oidc_identity = OidcIdentity.create_from_omniauth(
|
||||
build_auth_hash(@pending_auth),
|
||||
user
|
||||
)
|
||||
|
||||
# Clear pending auth from session
|
||||
@@ -100,16 +93,9 @@ class OidcAccountsController < ApplicationController
|
||||
|
||||
if @user.save
|
||||
# Create the OIDC identity
|
||||
@user.oidc_identities.create!(
|
||||
provider: @pending_auth["provider"],
|
||||
uid: @pending_auth["uid"],
|
||||
info: {
|
||||
email: @pending_auth["email"],
|
||||
name: @pending_auth["name"],
|
||||
first_name: @pending_auth["first_name"],
|
||||
last_name: @pending_auth["last_name"]
|
||||
},
|
||||
last_authenticated_at: Time.current
|
||||
OidcIdentity.create_from_omniauth(
|
||||
build_auth_hash(@pending_auth),
|
||||
@user
|
||||
)
|
||||
|
||||
# Clear pending auth from session
|
||||
@@ -122,4 +108,15 @@ class OidcAccountsController < ApplicationController
|
||||
render :new_user, status: :unprocessable_entity
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
# Convert pending auth hash to OmniAuth-like structure
|
||||
def build_auth_hash(pending_auth)
|
||||
OpenStruct.new(
|
||||
provider: pending_auth["provider"],
|
||||
uid: pending_auth["uid"],
|
||||
info: OpenStruct.new(pending_auth.slice("email", "name", "first_name", "last_name"))
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user