TNG / keycloak-mock

A Java library to test REST endpoints secured by Keycloak via OpenID connect.
Apache License 2.0
122 stars 27 forks source link

Can now supply email as login username and names will be derived. #121

Closed essiembre closed 1 year ago

essiembre commented 2 years ago

Thanks for this great testing library. A real time saver for local development/testing.

I have a case where I use the mock server for local development and I need the user email. Since there is no way to set it via login (where it would be the most convenient), I figured we could add the ability to provide email as username.

The current behavior will remain unchanged, except when an email is provided, then we set it as the user email, and derive the username, given/family names from it.

For example, let's assume one provides an email in the username field of the login form with the following format:

firstname.lastname@somewhere.com

Then it will result in the following claims being set:

subject:           firstname.lastname
preferredUsername: firstname.lastname
givenName:         Firstname             // Capitalized
familyName:        Lastname              // Capitalized
email:             firstname.lastname@somewhere.com

If the login user name is not an email, the provided value will be stored as is everywhere, except for email and given name, which won't be set (current behavior).

If you like the idea, feel free to adapt to your liking.

ostrya commented 1 year ago

I'll close this now that #140 is merged.