NIFI-9977 In StandardOauth2AccessTokenProvider add new property to be able to set "scope".

Signed-off-by: Pierre Villard <pierre.villard.fr@gmail.com>

This closes #6006.
This commit is contained in:
Tamas Palfy 2022-04-29 17:18:29 +02:00 committed by Pierre Villard
parent 7271e8cea7
commit 5aa71570ff
No known key found for this signature in database
GPG Key ID: F92A93B30C07C6D5
1 changed files with 19 additions and 0 deletions

View File

@ -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()