Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ public String oauth2ServerUri() {

@Value.Lazy
public Map<String, String> optionalOAuthParams() {
return OAuth2Util.buildOptionalParam(properties());
return OAuth2Util.buildOptionalParam(properties(), SCOPE);
}

/** A Bearer token supplier which will be used for interaction with the server. */
Expand Down Expand Up @@ -166,10 +166,10 @@ AuthSession authSession() {
ImmutableMap.Builder<String, String> properties =
ImmutableMap.<String, String>builder()
.putAll(properties())
.putAll(optionalOAuthParams())
.put(OAuth2Properties.OAUTH2_SERVER_URI, oauth2ServerUri())
.put(OAuth2Properties.TOKEN_REFRESH_ENABLED, String.valueOf(keepTokenRefreshed()))
.put(OAuth2Properties.SCOPE, SCOPE);
.put(OAuth2Properties.SCOPE, SCOPE)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The call to .put(OAuth2Properties.SCOPE, SCOPE) here is imo useless since the scope will be overridden by .putAll(optionalOAuthParams()) – but it doesn't hurt to keep it.

.putAll(optionalOAuthParams());
String token = token().get();
if (null != token) {
properties.put(OAuth2Properties.TOKEN, token);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,23 @@ static void beforeAll() {
Mockito.any()))
.thenReturn(
OAuthTokenResponse.builder().withToken("token").withTokenType("Bearer").build());
when(S3V4RestSignerClient.httpClient.postForm(
Mockito.anyString(),
Mockito.eq(
Map.of(
"grant_type",
"client_credentials",
"client_id",
"user",
"client_secret",
"12345",
"scope",
"custom")),
Mockito.eq(OAuthTokenResponse.class),
Mockito.anyMap(),
Mockito.any()))
.thenReturn(
OAuthTokenResponse.builder().withToken("token").withTokenType("Bearer").build());
}

@AfterAll
Expand Down Expand Up @@ -133,6 +150,18 @@ public static Stream<Arguments> validOAuth2Properties() {
"token",
OAuth2Properties.CREDENTIAL,
"user:12345"),
"token"),
// Custom scope
Arguments.of(
Map.of(
S3_SIGNER_URI,
"https://signer.com",
AuthProperties.AUTH_TYPE,
AuthProperties.AUTH_TYPE_OAUTH2,
OAuth2Properties.CREDENTIAL,
"user:12345",
OAuth2Properties.SCOPE,
"custom"),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we have a test that verifies that the default scope is sign when no custom scope is defined?

"token"));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -132,15 +132,19 @@ public static String toScope(Iterable<String> scopes) {
}

public static Map<String, String> buildOptionalParam(Map<String, String> properties) {
return buildOptionalParam(properties, OAuth2Properties.CATALOG_SCOPE);
}

public static Map<String, String> buildOptionalParam(
Map<String, String> properties, String defaultScope) {
// these are some options oauth params based on specification
// for any new optional oauth param, define the constant and add the constant to this list
Set<String> optionalParamKeys =
ImmutableSet.of(OAuth2Properties.AUDIENCE, OAuth2Properties.RESOURCE);
ImmutableMap.Builder<String, String> optionalParamBuilder = ImmutableMap.builder();
// add scope too,
optionalParamBuilder.put(
OAuth2Properties.SCOPE,
properties.getOrDefault(OAuth2Properties.SCOPE, OAuth2Properties.CATALOG_SCOPE));
OAuth2Properties.SCOPE, properties.getOrDefault(OAuth2Properties.SCOPE, defaultScope));
// add all other parameters
for (String key : optionalParamKeys) {
String value = properties.get(key);
Expand Down