-
Notifications
You must be signed in to change notification settings - Fork 2
Add user identity list NATS subject #31
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||
|---|---|---|---|---|---|---|---|---|
|
|
@@ -226,6 +226,92 @@ func (m *messageHandlerOrchestrator) GetUserEmails(ctx context.Context, msg port | |||||||
| return responseJSON, nil | ||||||||
| } | ||||||||
|
|
||||||||
| // identityListRequest represents the input for listing user identities | ||||||||
| type identityListRequest struct { | ||||||||
| User struct { | ||||||||
| AuthToken string `json:"auth_token"` | ||||||||
| } `json:"user"` | ||||||||
| } | ||||||||
|
|
||||||||
| // identityResponse is the response DTO matching the UI's expected format | ||||||||
| type identityResponse struct { | ||||||||
| Provider string `json:"provider"` | ||||||||
| UserID string `json:"user_id"` | ||||||||
| IsSocial bool `json:"isSocial"` | ||||||||
| ProfileData *identityProfileData `json:"profileData,omitempty"` | ||||||||
| } | ||||||||
|
|
||||||||
| type identityProfileData struct { | ||||||||
| Email string `json:"email,omitempty"` | ||||||||
| EmailVerified bool `json:"email_verified,omitempty"` | ||||||||
| } | ||||||||
|
|
||||||||
| // ListIdentities retrieves the user's linked identities | ||||||||
| func (m *messageHandlerOrchestrator) ListIdentities(ctx context.Context, msg port.TransportMessenger) ([]byte, error) { | ||||||||
|
|
||||||||
| if m.userReader == nil { | ||||||||
| return m.errorResponse("auth service unavailable"), nil | ||||||||
| } | ||||||||
|
|
||||||||
| var request identityListRequest | ||||||||
| if err := json.Unmarshal(msg.Data(), &request); err != nil { | ||||||||
| return m.errorResponse("failed to unmarshal request"), nil | ||||||||
| } | ||||||||
|
|
||||||||
| authToken := strings.TrimSpace(request.User.AuthToken) | ||||||||
| if authToken == "" { | ||||||||
| return m.errorResponse("auth_token is required"), nil | ||||||||
| } | ||||||||
|
|
||||||||
| slog.DebugContext(ctx, "list identities", | ||||||||
| "input", redaction.Redact(authToken), | ||||||||
| ) | ||||||||
|
|
||||||||
| user, err := m.userReader.MetadataLookup(ctx, authToken) | ||||||||
| if err != nil { | ||||||||
| slog.ErrorContext(ctx, "error looking up user for identity list", | ||||||||
| "error", err, | ||||||||
| ) | ||||||||
| return m.errorResponse(err.Error()), nil | ||||||||
| } | ||||||||
|
|
||||||||
| fullUser, err := m.userReader.GetUser(ctx, user) | ||||||||
| if err != nil { | ||||||||
| slog.ErrorContext(ctx, "error getting user for identity list", | ||||||||
| "error", err, | ||||||||
| ) | ||||||||
| return m.errorResponse(err.Error()), nil | ||||||||
| } | ||||||||
|
|
||||||||
| identities := make([]identityResponse, 0, len(fullUser.Identities)) | ||||||||
| for _, id := range fullUser.Identities { | ||||||||
| resp := identityResponse{ | ||||||||
| Provider: id.Provider, | ||||||||
| UserID: id.IdentityID, | ||||||||
| IsSocial: id.IsSocial, | ||||||||
| } | ||||||||
| if id.Email != "" { | ||||||||
| resp.ProfileData = &identityProfileData{ | ||||||||
| Email: id.Email, | ||||||||
| EmailVerified: true, | ||||||||
|
Comment on lines
+295
to
+296
|
||||||||
| Email: id.Email, | |
| EmailVerified: true, | |
| Email: id.Email, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🧩 Analysis chain
🏁 Script executed:
#!/bin/bash
# Check if email_verified is used elsewhere in identity-related code
rg -n "email_verified|EmailVerified" --type=go -C2Repository: linuxfoundation/lfx-v2-auth-service
Length of output: 8651
🏁 Script executed:
# Find the model.Identity structure definition
fd -n "models\|identity" --type=go | grep -E "model|pkg" | head -20Repository: linuxfoundation/lfx-v2-auth-service
Length of output: 309
🏁 Script executed:
# Get full context around the problematic lines in message_handler.go
cat -n internal/service/message_handler.go | sed -n '280,310p'Repository: linuxfoundation/lfx-v2-auth-service
Length of output: 1024
🏁 Script executed:
# Search for model.Identity definition
rg -n "type Identity struct" --type=go -A 15Repository: linuxfoundation/lfx-v2-auth-service
Length of output: 1476
🏁 Script executed:
# Find where fullUser.Identities is populated
rg -n "Identities\s*=" --type=go -B 5 -A 5 | head -80Repository: linuxfoundation/lfx-v2-auth-service
Length of output: 4356
🏁 Script executed:
# Check how Auth0 identities are mapped to model.Identity
rg -n "model\.Identity|Identity{" --type=go -B 3 -A 3 | grep -A 8 -B 8 "Email"Repository: linuxfoundation/lfx-v2-auth-service
Length of output: 192
🏁 Script executed:
# Look at Auth0 integration to understand when emails are unverified
rg -n "EmailVerified.*false" --type=go -B 3 -A 3Repository: linuxfoundation/lfx-v2-auth-service
Length of output: 1739
🏁 Script executed:
# Check API endpoint that returns this data
rg -n "GetIdentities|identities\|email_verified" --type=go | head -40Repository: linuxfoundation/lfx-v2-auth-service
Length of output: 61
🏁 Script executed:
# Search for tests that verify the email_verified response field
rg -n "email_verified.*true|email_verified.*false" --type=go -B 3 -A 3Repository: linuxfoundation/lfx-v2-auth-service
Length of output: 519
EmailVerified hardcoded as true due to missing field in model.Identity.
The issue is real: Auth0ProfileData includes EmailVerified (which can be false for passwordless flows), but model.Identity lacks this field entirely. When identities are constructed in authelia/user.go and mock/user.go, the EmailVerified status is discarded. The response then hardcodes true for any identity with an email, misrepresenting unverified emails as verified.
Consider extending model.Identity to include EmailVerified and propagating it from Auth0, or omit email_verified from the response if accurate status cannot be provided.
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.
In `@internal/service/message_handler.go` around lines 293 - 298, The code
currently hardcodes EmailVerified=true in identityProfileData inside
message_handler.go because model.Identity lacks an EmailVerified field; update
model.Identity to include EmailVerified bool, propagate that value when building
identities from Auth0 (use Auth0ProfileData.EmailVerified in authelia/user.go)
and in mock identities (mock/user.go), and then change the message_handler.go
block that sets resp.ProfileData to use id.EmailVerified instead of true (or
omit the field when unknown). Ensure constructors and tests are updated to set
or default EmailVerified appropriately.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The new
ToUser()mapping now includesIdentities, but there’s no unit test covering this conversion (including edge cases like non-stringAuth0Identity.UserIDand presence/absence ofprofileData). Since this is a regression-prone mapping that impacts the newuser_identity.listbehavior, add a focused test aroundAuth0User.ToUser()to assert identities are populated and correctly converted.