You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@nifi.apache.org by "pvillard31 (via GitHub)" <gi...@apache.org> on 2025/03/25 17:42:58 UTC
[PR] NIFI-14389 - Provide the option to force refresh Access Token in OAuth2AccessTokenProvider [nifi]
pvillard31 opened a new pull request, #9822:
URL: https://github.com/apache/nifi/pull/9822
# Summary
[NIFI-14389](https://issues.apache.org/jira/browse/NIFI-14389) - Provide the option to force refresh Access Token in OAuth2AccessTokenProvider
# Tracking
Please complete the following tracking steps prior to pull request creation.
### Issue Tracking
- [ ] [Apache NiFi Jira](https://issues.apache.org/jira/browse/NIFI) issue created
### Pull Request Tracking
- [ ] Pull Request title starts with Apache NiFi Jira issue number, such as `NIFI-00000`
- [ ] Pull Request commit message starts with Apache NiFi Jira issue number, as such `NIFI-00000`
### Pull Request Formatting
- [ ] Pull Request based on current revision of the `main` branch
- [ ] Pull Request refers to a feature branch with one commit containing changes
# Verification
Please indicate the verification steps performed prior to pull request creation.
### Build
- [ ] Build completed using `mvn clean install -P contrib-check`
- [ ] JDK 21
### Licensing
- [ ] New dependencies are compatible with the [Apache License 2.0](https://apache.org/licenses/LICENSE-2.0) according to the [License Policy](https://www.apache.org/legal/resolved.html)
- [ ] New dependencies are documented in applicable `LICENSE` and `NOTICE` files
### Documentation
- [ ] Documentation formatting appears as expected in rendered files
--
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: issues-unsubscribe@nifi.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] NIFI-14389 - Provide the option to force refresh Access Token in OAuth2AccessTokenProvider [nifi]
Posted by "exceptionfactory (via GitHub)" <gi...@apache.org>.
exceptionfactory merged PR #9822:
URL: https://github.com/apache/nifi/pull/9822
--
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: issues-unsubscribe@nifi.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] NIFI-14389 - Provide the option to force refresh Access Token in OAuth2AccessTokenProvider [nifi]
Posted by "pvillard31 (via GitHub)" <gi...@apache.org>.
pvillard31 commented on code in PR #9822:
URL: https://github.com/apache/nifi/pull/9822#discussion_r2016199934
##########
nifi-extension-bundles/nifi-standard-services/nifi-oauth2-provider-api/src/main/java/org/apache/nifi/oauth2/OAuth2AccessTokenProvider.java:
##########
@@ -27,4 +27,14 @@ 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();
+
+ /**
+ * @param forceAccessTokenRefresh true if the access token should be refreshed
+ * even if it is not expired
+ * @return A valid access token (refreshed automatically if needed) and
+ * additional metadata (provided by the OAuth2 access server)
+ */
+ default AccessToken getAccessDetails(final boolean forceAccessTokenRefresh) {
Review Comment:
Thinking a bit more about it... `refreshAccessDetails()`, as of now, assumes that the refresh token is not null. Some services do not send a refresh token with the access token. So I'll have to adjust the logic just a bit.
--
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: issues-unsubscribe@nifi.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] NIFI-14389 - Provide the option to force refresh Access Token in OAuth2AccessTokenProvider [nifi]
Posted by "exceptionfactory (via GitHub)" <gi...@apache.org>.
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: issues-unsubscribe@nifi.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] NIFI-14389 - Provide the option to force refresh Access Token in OAuth2AccessTokenProvider [nifi]
Posted by "exceptionfactory (via GitHub)" <gi...@apache.org>.
exceptionfactory commented on code in PR #9822:
URL: https://github.com/apache/nifi/pull/9822#discussion_r2015322174
##########
nifi-extension-bundles/nifi-standard-services/nifi-oauth2-provider-api/src/main/java/org/apache/nifi/oauth2/OAuth2AccessTokenProvider.java:
##########
@@ -27,4 +27,14 @@ 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();
+
+ /**
+ * @param forceAccessTokenRefresh true if the access token should be refreshed
+ * even if it is not expired
+ * @return A valid access token (refreshed automatically if needed) and
+ * additional metadata (provided by the OAuth2 access server)
+ */
+ default AccessToken getAccessDetails(final boolean forceAccessTokenRefresh) {
Review Comment:
Instead of adding this new method and option, what do you think about promoting `refreshAccessDetails()` as an interface method? This would require calling both `refreshAccessDetails()` and then `getAccessDetails()`, but it would clarify that these are separate actions, the first of which could fail, allowing the caller to determine the desired behavior. The default implementation could be nothing, making it easier for third-party implementations to implement when desired, aligning with the optional usage of the new Token Refresh Strategy.
--
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: issues-unsubscribe@nifi.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] NIFI-14389 - Provide the option to force refresh Access Token in OAuth2AccessTokenProvider [nifi]
Posted by "pvillard31 (via GitHub)" <gi...@apache.org>.
pvillard31 commented on PR #9822:
URL: https://github.com/apache/nifi/pull/9822#issuecomment-2752098479
Yep, good point @exceptionfactory, it will be cleaner
--
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: issues-unsubscribe@nifi.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] NIFI-14389 - Provide the option to force refresh Access Token in OAuth2AccessTokenProvider [nifi]
Posted by "pvillard31 (via GitHub)" <gi...@apache.org>.
pvillard31 commented on code in PR #9822:
URL: https://github.com/apache/nifi/pull/9822#discussion_r2016175252
##########
nifi-extension-bundles/nifi-standard-services/nifi-oauth2-provider-api/src/main/java/org/apache/nifi/oauth2/OAuth2AccessTokenProvider.java:
##########
@@ -27,4 +27,14 @@ 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();
+
+ /**
+ * @param forceAccessTokenRefresh true if the access token should be refreshed
+ * even if it is not expired
+ * @return A valid access token (refreshed automatically if needed) and
+ * additional metadata (provided by the OAuth2 access server)
+ */
+ default AccessToken getAccessDetails(final boolean forceAccessTokenRefresh) {
Review Comment:
Yeah, you're right, I think it makes it easier from a caller perspective to understand the expected usage of those methods.
--
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: issues-unsubscribe@nifi.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] NIFI-14389 - Provide the option to force refresh Access Token in OAuth2AccessTokenProvider [nifi]
Posted by "exceptionfactory (via GitHub)" <gi...@apache.org>.
exceptionfactory commented on code in PR #9822:
URL: https://github.com/apache/nifi/pull/9822#discussion_r2012720635
##########
nifi-extension-bundles/nifi-standard-services/nifi-oauth2-provider-api/src/main/java/org/apache/nifi/oauth2/TokenRefreshStrategy.java:
##########
@@ -0,0 +1,48 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.nifi.oauth2;
+
+import org.apache.nifi.components.DescribedValue;
+
+public enum TokenRefreshStrategy implements DescribedValue {
+
+ ON_TOKEN_EXPIRATION("The token will be refreshed based on its expiration time and the configured refresh window"),
+
+ ON_NON_AUTHORIZED_REQUEST("A new token will be requested in case of a non-authorized request (HTTP 401) even if the current token has not expired");
Review Comment:
I recommend `ON_UNAUTHORIZED_STATUS` or `ON_UNAUTHORIZED_RESPONSE` to align with the standard name for [HTTP 401](https://http.dev/401) status.
--
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: issues-unsubscribe@nifi.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org