Skip to content

Conversation

@tcnichol
Copy link
Contributor

@tcnichol tcnichol commented Jan 8, 2024

ready for review. look at @longshuicy comment below to add the preferred_username

@tcnichol tcnichol requested a review from longshuicy January 8, 2024 18:42
@tcnichol tcnichol linked an issue Jan 8, 2024 that may be closed by this pull request
@tcnichol
Copy link
Contributor Author

tcnichol commented Jan 8, 2024

To replicate this bug, follow the instructions from this link to add a preferred_username field to a user.

https://medium.com/@ramanamuttana/custom-attribute-in-keycloak-access-token-831b4be7384a

Once you do that, and you try to log in as that user, you will see 'error user {preferred_username} not found.' on main. On this branch it should be fixed.

@tcnichol tcnichol marked this pull request as ready for review January 8, 2024 19:56
@tcnichol tcnichol requested a review from max-zilla as a code owner January 8, 2024 19:56
@tcnichol tcnichol requested review from ddey2 and lmarini January 8, 2024 19:56
@lmarini
Copy link
Member

lmarini commented Jan 9, 2024

To replicate this bug, follow the instructions from this link to add a preferred_username field to a user.

https://medium.com/@ramanamuttana/custom-attribute-in-keycloak-access-token-831b4be7384a

Once you do that, and you try to log in as that user, you will see 'error user {preferred_username} not found.' on main. On this branch it should be fixed.

PR looks good, but I am not sure I understand this comment. I think preferred_username is always there

@lmarini lmarini closed this Jan 9, 2024
@lmarini lmarini reopened this Jan 9, 2024
@tcnichol
Copy link
Contributor Author

tcnichol commented Jan 9, 2024

@lmarini

When I created users they didn't have the preferred_username field, so I found a way to add it so I could have the preferred_username not be the email and replicate the bug and test the fix. If you don't need to, then just edit the preferred_username in keycloak to make sure it's not the same as email. On main you'll see an error, but on this branch you won't.

@longshuicy
Copy link
Member

How can I test this PR?

@tcnichol
Copy link
Contributor Author

To test the PR, follow the instructions in the linked article to add "preferred_username" field to a user. Set the preferred username to something aside from the email. For me, users did not have 'preferred_username' field if they were created through clowder.

On main, you'll see an error when logging in with that user, but on this branch the error is fixed.

You can also just add the field for 1 user.

Copy link
Member

@longshuicy longshuicy left a comment

Choose a reason for hiding this comment

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

Code looks good and works.

I think i know how to reproduce the error:

  1. Go to clients --> find clowder2-backend --> select "client scopes"
  2. select clowder2-backend-dedicate
  3. Mapper --> add mapper by configuration
  4. create a user attribute named "preferred_username"
  5. go back to a given user, add the "preferred_username" as a attribute and give it a different name
  6. You should expect failure with "main" branch; but success with this PR fix
image image image image

@alemsh
Copy link
Contributor

alemsh commented Jan 19, 2024

Also confirming that this change work with our keycloak environment as well, thanks!

@lmarini lmarini merged commit c86a9b6 into main Jan 23, 2024
@lmarini lmarini deleted the 861-bug-when-preferred-username-is-not-the-email branch January 23, 2024 14:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bug when preferred username is not the email

5 participants