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

Return full user information on authentication query #694

Open
thokari opened this issue Oct 19, 2024 · 1 comment
Open

Return full user information on authentication query #694

thokari opened this issue Oct 19, 2024 · 1 comment

Comments

@thokari
Copy link

thokari commented Oct 19, 2024

Describe the feature

I have a specific improvement regarding this part:
https://github.com/eclipse-vertx/vertx-auth/blob/master/vertx-auth-sql-client/src/main/java/io/vertx/ext/auth/sqlclient/impl/SqlAuthenticationImpl.java#L76-L82

The documentation states, that this library requires a table with a username column, and while this column name is hardcoded in the default query (https://github.com/eclipse-vertx/vertx-auth/blob/master/vertx-auth-sql-client/src/main/java/io/vertx/ext/auth/sqlclient/SqlAuthenticationOptions.java#L35) which one can set, but in the code the column name is not mentioned, instead it it assumed that the password is the first string in a single database row.

The Userobject already accomodates for some more information to be put to it, as well as the SqlAuthenticationOptions hint at the idea of making this aspect at least somewhat configurable.

(By the way, I have to use this feature anyways, because Postgres expects the query placeholder to be $1.)

What I would like to have is that if one sets a different authentication query, one that returns more than a single value, for example SELECT * ..., and then including additional attributes could be implemented like this:

   // on SqlAuthenticationOptions
    public void addUserAttribute(String attributeName, Function<Row, Object> extractor) {
        userAttributeExtractors.put(attributeName, extractor);
    }

and usage:

SqlAuthenticationOptions().addUserAttribute("user_id", { row -> row.getUUID("user_id") } )

Maybe even this is possible:

SqlAuthenticationOptions().addUserAttribute("user_id", Row::.getUUID)

Use cases

Simply, when getting this User object from authentication, for the purpose of storing it in a token, or session, one saves haveing to query more information afterwards. Specifically, a user_id field might be something that users of this library would like to be returned as part of the User.

Contribution

I could possibly make a contribution, if the feature is deemed worth implementing.

@tsegismont
Copy link
Contributor

Thanks for this report @thokari This sounds like a nice improvement to me.

About implementation, in Vert.x 5 we want option classes to be data only. So if you add Row/User mapping functions, they should be added on the SqlAuth type, not the options.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants