Add extra fields support to oAuth AccessTokenResponse#5355
Add extra fields support to oAuth AccessTokenResponse#5355kaikreuzer merged 8 commits intoopenhab:mainfrom
Conversation
Signed-off-by: Laurent ARNAL <laurent@clae.net>
26292ff to
5cc0f43
Compare
There was a problem hiding this comment.
Pull request overview
This pull request adds support for capturing extra (non-standard) fields from OAuth access token responses. This is necessary because some OAuth implementations, such as Samsung SmartThings, return additional fields beyond the RFC 6749 standard fields (access_token, token_type, expires_in, refresh_token, scope, state).
Changes:
- Added an
extraFieldsMap toAccessTokenResponseto store non-standard fields - Created
AccessTokenResponseExtraFieldsAdapterFactoryto handle custom JSON deserialization via Gson - Registered the new type adapter factory in
OAuthConnectorto enable extra field capture
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 11 comments.
| File | Description |
|---|---|
| AccessTokenResponseExtraFieldsAdapterFactory.java | New Gson TypeAdapterFactory that extracts non-standard fields from OAuth JSON responses into a Map |
| AccessTokenResponse.java | Added extraFields Map field with getter/setter methods to store additional OAuth response fields |
| OAuthConnector.java | Registered the new AccessTokenResponseExtraFieldsAdapterFactory with the Gson builder |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
.../org.openhab.core/src/main/java/org/openhab/core/auth/client/oauth2/AccessTokenResponse.java
Outdated
Show resolved
Hide resolved
...n/java/org/openhab/core/auth/client/oauth2/AccessTokenResponseExtraFieldsAdapterFactory.java
Show resolved
Hide resolved
.../org.openhab.core/src/main/java/org/openhab/core/auth/client/oauth2/AccessTokenResponse.java
Outdated
Show resolved
Hide resolved
...n/java/org/openhab/core/auth/client/oauth2/AccessTokenResponseExtraFieldsAdapterFactory.java
Show resolved
Hide resolved
.../org.openhab.core/src/main/java/org/openhab/core/auth/client/oauth2/AccessTokenResponse.java
Outdated
Show resolved
Hide resolved
...n/java/org/openhab/core/auth/client/oauth2/AccessTokenResponseExtraFieldsAdapterFactory.java
Show resolved
Hide resolved
...n/java/org/openhab/core/auth/client/oauth2/AccessTokenResponseExtraFieldsAdapterFactory.java
Outdated
Show resolved
Hide resolved
.../org.openhab.core/src/main/java/org/openhab/core/auth/client/oauth2/AccessTokenResponse.java
Outdated
Show resolved
Hide resolved
...n/java/org/openhab/core/auth/client/oauth2/AccessTokenResponseExtraFieldsAdapterFactory.java
Show resolved
Hide resolved
.../org.openhab.core/src/main/java/org/openhab/core/auth/client/oauth2/AccessTokenResponse.java
Show resolved
Hide resolved
Signed-off-by: Laurent ARNAL <laurent@clae.net>
Signed-off-by: Laurent ARNAL <laurent@clae.net>
|
Hello @wborn, Thanks for the copilot review. Laurent. |
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 4 out of 4 changed files in this pull request and generated 9 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
.../org.openhab.core/src/main/java/org/openhab/core/auth/client/oauth2/AccessTokenResponse.java
Show resolved
Hide resolved
...h.oauth2client/src/main/java/org/openhab/core/auth/oauth2client/internal/OAuthConnector.java
Outdated
Show resolved
Hide resolved
...test/java/org/openhab/core/auth/oauth2client/internal/AccessTokenResponseExtraFieldTest.java
Outdated
Show resolved
Hide resolved
...n/java/org/openhab/core/auth/client/oauth2/AccessTokenResponseExtraFieldsAdapterFactory.java
Outdated
Show resolved
Hide resolved
...n/java/org/openhab/core/auth/client/oauth2/AccessTokenResponseExtraFieldsAdapterFactory.java
Outdated
Show resolved
Hide resolved
...test/java/org/openhab/core/auth/oauth2client/internal/AccessTokenResponseExtraFieldTest.java
Outdated
Show resolved
Hide resolved
...test/java/org/openhab/core/auth/oauth2client/internal/AccessTokenResponseExtraFieldTest.java
Outdated
Show resolved
Hide resolved
...n/java/org/openhab/core/auth/client/oauth2/AccessTokenResponseExtraFieldsAdapterFactory.java
Outdated
Show resolved
Hide resolved
.../org.openhab.core/src/main/java/org/openhab/core/auth/client/oauth2/AccessTokenResponse.java
Outdated
Show resolved
Hide resolved
Signed-off-by: Laurent Arnal <laurent@clae.net>
Push the fixes this morning about copilot review of 1/03. Laurent |
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
...n/java/org/openhab/core/auth/client/oauth2/AccessTokenResponseExtraFieldsAdapterFactory.java
Show resolved
Hide resolved
.../org.openhab.core/src/main/java/org/openhab/core/auth/client/oauth2/AccessTokenResponse.java
Show resolved
Hide resolved
…nse::toString() Signed-off-by: Laurent Arnal <laurent@clae.net>
|
I think this could now be merged. Thanks, |
kaikreuzer
left a comment
There was a problem hiding this comment.
Thanks @lo92fr!
A few final review comments NOT coming from a bot, but from a person for a change. 😉
| import java.util.Map; | ||
| import java.util.Objects; | ||
|
|
||
| import org.eclipse.jdt.annotation.NonNull; |
There was a problem hiding this comment.
If you want to introduce null annotations with the new fields/method, you should make the whole class consistently use null annotations - and this means you should annotate it with @NonNullByDefault and then rather add @Nullable annotations at the appropriate places.
| * warning : the toString() function may returns sensitive information that should not go into the log. | ||
| * |
There was a problem hiding this comment.
| * warning : the toString() function may returns sensitive information that should not go into the log. | |
| * | |
| * Warning: the toString() function may returns sensitive information that should not go into the log. |
| * specification. All unknown JSON properties are collected into a map and exposed via {@code extraFields} on the | ||
| * {@link AccessTokenResponse}. | ||
| * | ||
| * @author Laurent Arnal |
There was a problem hiding this comment.
| * @author Laurent Arnal | |
| * @author Laurent Arnal - Initial contribution |
Signed-off-by: Laurent ARNAL <laurent@clae.net>
Signed-off-by: Laurent ARNAL <laurent@clae.net>
Signed-off-by: Laurent ARNAL <laurent@clae.net>
|
Hello @kaikreuzer, I've pushed the fixes. Laurent. |
Hello Holger, Sorry for this. private Map<@nonnull String, @nonnull String> extraFields = Collections.emptyMap();
So I add the @NonNullByDefault to the class, and add @nullable on old field to keep compatibility (I was thinking). Laurent |
|
Hi Laurent, this happens from time to time and there is nothing to be sorry for. I worked in on an PR to remove all Null warnings in the past which basically changed |
Ok, I effectively don't see the side effect on other addons, that seems massive. Laurent. |
|
We are just cross-posting at the same time ! Yes I'm agree would be better to add the annotation. So let me know, perhaps more simple to make it a 2 pass process:
Let me know ! |
|
I think it is not too much to fix on add-ons side. I just searched the PR I mentioned above. Automower is the biggest change. A few more bindings need a new null check / exception blocks. On core side, the setters in I can care for the add-ons side in the meantime. |
|
ok, I prepare the change getters/setters |
The PR for AccessTokenResponse is there: |


Add extra fields support to oAuth AccessTokenResponse
Description
This PR is about adding an extraFields maps in the OAuth AccessTokenResponse.
Some oAuth implementation return extra fields beside the accessToken/refreshToken/scope/state standard field.
With this change, this extraFields will be expose in the token response, giving a chance to use them.
The motivation beside this is for the new Smarthings Binding. Samsung oAuth implementation add en extra clientId field in the response, and I need to get this to handle smartthings stuff properly.
The changes are mainly in 3 files: