Skip to content
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

Fix/verify sso bug #14253

Merged
merged 15 commits into from
Jul 29, 2024
Merged

Fix/verify sso bug #14253

merged 15 commits into from
Jul 29, 2024

Conversation

melohagan
Copy link
Collaborator

@melohagan melohagan commented Jul 26, 2024

Description

Niche bug with Microsoft SSO and password accounts.

When verifying an MS SSO email account, if this same email address had been used to create a password account by an admin, you would be unable to verify the email again if the user was deleted and re-added.

This is because the SSO user profile CouchDB doc was not being removed on deletion of the user.

Screenshots

two user docs
When a Microsoft user is added with a password account, but signs in with SSO, you get multiple documents in Couch.

Screenshot 2024-07-26 at 13 32 13
Deletion of the user in this screen was not removing the SSO user profile, which prevents subsequent email verification if that user is re-added.

Also updated the password reset screen:
https://linear.app/budibase/issue/GRO-560/make-the-reset-your-password-support-the-enter-key

password.screen.mov

Launchcontrol

Minor bug fix relating to Microsoft SSO

@melohagan melohagan marked this pull request as ready for review July 26, 2024 12:44
@melohagan melohagan requested a review from a team as a code owner July 26, 2024 12:44
@melohagan melohagan requested review from adrinr and removed request for a team July 26, 2024 12:44
packages/backend-core/src/platform/users.ts Outdated Show resolved Hide resolved
@@ -36,7 +36,7 @@ export async function searchExistingEmails(emails: string[]) {
// lookup, could be email or userId, either will return a doc
export async function getPlatformUser(
identifier: string
): Promise<PlatformUser | null> {
): Promise<PlatformUser[] | PlatformUser | null> {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In which case it can return an array? We are casting the result to a single user, and we are passing a single id

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It returns an array if the following Couch view finds more than one document:

const viewJs = `function(doc) {
    if (doc.tenantId) {
      emit(doc._id.toLowerCase(), doc._id)
    }

    if (doc.ssoId) {
      emit(doc.ssoId, doc._id)
    }
  }`

In this case it is these two documents:

Screenshot 2024-07-26 at 15 41 23

The document has the property ssoId, so emit that property as the key

Screenshot 2024-07-26 at 15 41 46

The document has the property tenantId, so emit the _id property as the key

This will result in two documents matching the SSO ID.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If this is the case, we might have all the usages wrong. You are casting the results as PlatformUser, so if it returns an array we will have issues. Should we handle the possible arrays on the usages? (fe. packages/backend-core/src/users/db.ts, line 454)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Update the types to just return the array, or call getFirstPlatformUser where appropriate

@github-actions github-actions bot added size/m and removed size/s labels Jul 26, 2024
@melohagan melohagan merged commit 60f7c03 into master Jul 29, 2024
12 checks passed
@melohagan melohagan deleted the fix/verify-sso-bug branch July 29, 2024 12:25
@github-actions github-actions bot locked and limited conversation to collaborators Jul 29, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants