eclipse-vertx / eclipse-vertx/vertx-auth

Return full user information on authentication query

Open
#694 1 comment 0 reactions 1 assignee Claimed by @tsegismont View on GitHub
enhancement help wanted
Dominant language
Java
Stars
175
Forks
159
Avg merge
3d 4h
Merged PRs (30d)
3

Description

#### 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 `User`object 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 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.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.