You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nifi.apache.org by jo...@apache.org on 2022/05/09 17:58:48 UTC

[nifi] 06/16: NIFI-9977 In StandardOauth2AccessTokenProvider add new property to be able to set "scope".

This is an automated email from the ASF dual-hosted git repository.

joewitt pushed a commit to branch support/nifi-1.16
in repository https://gitbox.apache.org/repos/asf/nifi.git

commit 25031dd8192e81d0157e2b6aed18f26362599dd7
Author: Tamas Palfy <ta...@gmail.com>
AuthorDate: Fri Apr 29 17:18:29 2022 +0200

    NIFI-9977 In StandardOauth2AccessTokenProvider add new property to be able to set "scope".
    
    Signed-off-by: Pierre Villard <pi...@gmail.com>
    
    This closes #6006.
---
 .../oauth2/StandardOauth2AccessTokenProvider.java     | 19 +++++++++++++++++++
 1 file changed, 19 insertions(+)

diff --git a/nifi-nar-bundles/nifi-standard-services/nifi-oauth2-provider-bundle/nifi-oauth2-provider-service/src/main/java/org/apache/nifi/oauth2/StandardOauth2AccessTokenProvider.java b/nifi-nar-bundles/nifi-standard-services/nifi-oauth2-provider-bundle/nifi-oauth2-provider-service/src/main/java/org/apache/nifi/oauth2/StandardOauth2AccessTokenProvider.java
index 48e47ff19a..c09ecc9e96 100644
--- a/nifi-nar-bundles/nifi-standard-services/nifi-oauth2-provider-bundle/nifi-oauth2-provider-service/src/main/java/org/apache/nifi/oauth2/StandardOauth2AccessTokenProvider.java
+++ b/nifi-nar-bundles/nifi-standard-services/nifi-oauth2-provider-bundle/nifi-oauth2-provider-service/src/main/java/org/apache/nifi/oauth2/StandardOauth2AccessTokenProvider.java
@@ -122,6 +122,14 @@ public class StandardOauth2AccessTokenProvider extends AbstractControllerService
         .addValidator(StandardValidators.NON_BLANK_VALIDATOR)
         .build();
 
+    public static final PropertyDescriptor SCOPE = new PropertyDescriptor.Builder()
+        .name("scope")
+        .displayName("Scope")
+        .description("Space-delimited, case-sensitive list of scopes of the access request (as per the OAuth 2.0 specification)")
+        .required(false)
+        .addValidator(StandardValidators.NON_EMPTY_VALIDATOR)
+        .build();
+
     public static final PropertyDescriptor REFRESH_WINDOW = new PropertyDescriptor.Builder()
             .name("refresh-window")
             .displayName("Refresh Window")
@@ -146,6 +154,7 @@ public class StandardOauth2AccessTokenProvider extends AbstractControllerService
         PASSWORD,
         CLIENT_ID,
         CLIENT_SECRET,
+        SCOPE,
         REFRESH_WINDOW,
         SSL_CONTEXT
     ));
@@ -162,6 +171,7 @@ public class StandardOauth2AccessTokenProvider extends AbstractControllerService
     private volatile String password;
     private volatile String clientId;
     private volatile String clientSecret;
+    private volatile String scope;
     private volatile long refreshWindowSeconds;
 
     private volatile AccessToken accessDetails;
@@ -182,6 +192,7 @@ public class StandardOauth2AccessTokenProvider extends AbstractControllerService
         password = context.getProperty(PASSWORD).getValue();
         clientId = context.getProperty(CLIENT_ID).evaluateAttributeExpressions().getValue();
         clientSecret = context.getProperty(CLIENT_SECRET).getValue();
+        scope = context.getProperty(SCOPE).getValue();
 
         refreshWindowSeconds = context.getProperty(REFRESH_WINDOW).asTimePeriod(TimeUnit.SECONDS);
     }
@@ -264,6 +275,10 @@ public class StandardOauth2AccessTokenProvider extends AbstractControllerService
             acquireTokenBuilder.add("client_secret", clientSecret);
         }
 
+        if (scope != null) {
+            acquireTokenBuilder.add("scope", scope);
+        }
+
         RequestBody acquireTokenRequestBody = acquireTokenBuilder.build();
 
         Request acquireTokenRequest = new Request.Builder()
@@ -286,6 +301,10 @@ public class StandardOauth2AccessTokenProvider extends AbstractControllerService
             refreshTokenBuilder.add("client_secret", clientSecret);
         }
 
+        if (scope != null) {
+            refreshTokenBuilder.add("scope", scope);
+        }
+
         RequestBody refreshTokenRequestBody = refreshTokenBuilder.build();
 
         Request refreshRequest = new Request.Builder()