vertx-auth icon indicating copy to clipboard operation
vertx-auth copied to clipboard

Return full user information on authentication query

Open thokari opened this issue 4 months ago • 0 comments

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 btw.

(By the way, I have to use this feauture 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 *, 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.

thokari avatar Oct 19 '24 20:10 thokari