-
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
Changes from 1 commit
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 { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I tend to avoid models in the |
||
| 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) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👏 Nice work here, because there’s a fallback to use an M2M token in GetUser, but in this case we need to make sure the user is using their own token with the If you want to validate this a bit more, you can also add this here: |
||
| 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, | ||
fayazg marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| } | ||
| } | ||
coderabbitai[bot] marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| identities = append(identities, resp) | ||
| } | ||
|
|
||
| response := UserDataResponse{ | ||
| Success: true, | ||
| Data: identities, | ||
| } | ||
|
|
||
| responseJSON, err := json.Marshal(response) | ||
| if err != nil { | ||
| return m.errorResponse("failed to marshal response"), nil | ||
| } | ||
|
|
||
| return responseJSON, nil | ||
| } | ||
|
|
||
| // UpdateUser updates the user in the identity provider | ||
| func (m *messageHandlerOrchestrator) UpdateUser(ctx context.Context, msg port.TransportMessenger) ([]byte, error) { | ||
|
|
||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.