exceptionfactory commented on code in PR #9822:
URL: https://github.com/apache/nifi/pull/9822#discussion_r2016764469
##########
nifi-extension-bundles/nifi-standard-services/nifi-oauth2-provider-api/src/main/java/org/apache/nifi/oauth2/OAuth2AccessTokenProvider.java:
##########
@@ -27,4 +27,11 @@ public interface OAuth2AccessTokenProvider extends
ControllerService {
* @return A valid access token (refreshed automatically if needed) and
additional metadata (provided by the OAuth2 access server)
*/
AccessToken getAccessDetails();
+
+ /**
+ * Refreshes the access token even if it has not expired yet
+ */
+ default void refreshAccessDetails() {
+ // no default implementation
Review Comment:
Recommend removing this comment and incorporating in the method comments.
```suggestion
```
##########
nifi-extension-bundles/nifi-standard-services/nifi-oauth2-provider-api/src/main/java/org/apache/nifi/oauth2/OAuth2AccessTokenProvider.java:
##########
@@ -27,4 +27,11 @@ public interface OAuth2AccessTokenProvider extends
ControllerService {
* @return A valid access token (refreshed automatically if needed) and
additional metadata (provided by the OAuth2 access server)
*/
AccessToken getAccessDetails();
+
+ /**
+ * Refreshes the access token even if it has not expired yet
Review Comment:
```suggestion
* Request a new Access Token based on configured properties regardless
of current expiration status. The default implementation does not perform any
action.
```
##########
nifi-extension-bundles/nifi-standard-services/nifi-oauth2-provider-bundle/nifi-oauth2-provider-service/src/main/java/org/apache/nifi/oauth2/StandardOauth2AccessTokenProvider.java:
##########
@@ -339,6 +340,31 @@ public AccessToken getAccessDetails() {
return accessDetails;
}
+ @Override
+ public void refreshAccessDetails() {
+
+ if (this.accessDetails == null || this.accessDetails.getRefreshToken()
== null) {
+ acquireAccessDetails();
+ return;
+ }
+
+ getLogger().debug("Refresh Access Token request started [{}]",
authorizationServerUrl);
+
+ FormBody.Builder refreshTokenBuilder = new FormBody.Builder()
+ .add("grant_type", "refresh_token")
+ .add("refresh_token", this.accessDetails.getRefreshToken());
+
+ addFormData(refreshTokenBuilder);
+
+ AccessToken newAccessDetails = requestToken(refreshTokenBuilder);
+
+ if (newAccessDetails.getRefreshToken() == null) {
+
newAccessDetails.setRefreshToken(this.accessDetails.getRefreshToken());
+ }
+
+ this.accessDetails = newAccessDetails;
Review Comment:
Minor, but I recommend placing the logic in an `else` condition instead of
the short-circuit return.
##########
nifi-extension-bundles/nifi-standard-services/nifi-oauth2-provider-bundle/nifi-oauth2-provider-service/src/main/java/org/apache/nifi/oauth2/StandardOauth2AccessTokenProvider.java:
##########
@@ -339,6 +340,31 @@ public AccessToken getAccessDetails() {
return accessDetails;
}
+ @Override
+ public void refreshAccessDetails() {
+
Review Comment:
Unnecessary newline can be removed:
```suggestion
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]