Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Added audience param to oauth request body (optional) #157

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1 +1 @@
version=0.7.0-SNAPSHOT
version=0.7.1-SNAPSHOT
Copy link
Contributor

Choose a reason for hiding this comment

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

maybe not related to this change?

Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ public class HttpSinkConfig extends AbstractConfig {
private static final String OAUTH2_CLIENT_ID_CONFIG = "oauth2.client.id";
private static final String OAUTH2_CLIENT_SECRET_CONFIG = "oauth2.client.secret";
private static final String OAUTH2_CLIENT_AUTHORIZATION_MODE_CONFIG = "oauth2.client.authorization.mode";
private static final String OAUTH2_CLIENT_AUDIENCE_CONFIG = "oauth2.client.audience";
private static final String OAUTH2_CLIENT_SCOPE_CONFIG = "oauth2.client.scope";
private static final String OAUTH2_RESPONSE_TOKEN_PROPERTY_CONFIG = "oauth2.response.token.property";

Expand Down Expand Up @@ -199,8 +200,8 @@ public boolean visible(final String name, final Map<String, Object> parsedConfig
ConfigDef.Width.LONG,
OAUTH2_ACCESS_TOKEN_URL_CONFIG,
List.of(OAUTH2_CLIENT_ID_CONFIG, OAUTH2_CLIENT_SECRET_CONFIG,
OAUTH2_CLIENT_AUTHORIZATION_MODE_CONFIG, OAUTH2_CLIENT_SCOPE_CONFIG,
OAUTH2_RESPONSE_TOKEN_PROPERTY_CONFIG)
OAUTH2_CLIENT_AUTHORIZATION_MODE_CONFIG, OAUTH2_CLIENT_AUDIENCE_CONFIG,
OAUTH2_CLIENT_SCOPE_CONFIG, OAUTH2_RESPONSE_TOKEN_PROPERTY_CONFIG)
);
configDef.define(
OAUTH2_CLIENT_ID_CONFIG,
Expand All @@ -219,7 +220,7 @@ public String toString() {
ConfigDef.Width.LONG,
OAUTH2_CLIENT_ID_CONFIG,
List.of(OAUTH2_ACCESS_TOKEN_URL_CONFIG, OAUTH2_CLIENT_SECRET_CONFIG,
OAUTH2_CLIENT_AUTHORIZATION_MODE_CONFIG,
OAUTH2_CLIENT_AUTHORIZATION_MODE_CONFIG, OAUTH2_CLIENT_AUDIENCE_CONFIG,
OAUTH2_CLIENT_SCOPE_CONFIG, OAUTH2_RESPONSE_TOKEN_PROPERTY_CONFIG)
);
configDef.define(
Expand All @@ -233,7 +234,7 @@ public String toString() {
ConfigDef.Width.LONG,
OAUTH2_CLIENT_SECRET_CONFIG,
List.of(OAUTH2_ACCESS_TOKEN_URL_CONFIG, OAUTH2_CLIENT_ID_CONFIG,
OAUTH2_CLIENT_AUTHORIZATION_MODE_CONFIG,
OAUTH2_CLIENT_AUTHORIZATION_MODE_CONFIG, OAUTH2_CLIENT_AUDIENCE_CONFIG,
OAUTH2_CLIENT_SCOPE_CONFIG, OAUTH2_RESPONSE_TOKEN_PROPERTY_CONFIG)
);
configDef.define(
Expand Down Expand Up @@ -273,7 +274,28 @@ public String toString() {
ConfigDef.Width.LONG,
OAUTH2_CLIENT_AUTHORIZATION_MODE_CONFIG,
List.of(OAUTH2_ACCESS_TOKEN_URL_CONFIG, OAUTH2_CLIENT_ID_CONFIG, OAUTH2_CLIENT_SECRET_CONFIG,
OAUTH2_CLIENT_SCOPE_CONFIG, OAUTH2_RESPONSE_TOKEN_PROPERTY_CONFIG)
OAUTH2_CLIENT_AUDIENCE_CONFIG, OAUTH2_CLIENT_SCOPE_CONFIG,
OAUTH2_RESPONSE_TOKEN_PROPERTY_CONFIG)
);
configDef.define(
OAUTH2_CLIENT_AUDIENCE_CONFIG,
ConfigDef.Type.STRING,
null,
new ConfigDef.NonEmptyStringWithoutControlChars() {
@Override
public String toString() {
return "OAuth2 client audience";
}
},
ConfigDef.Importance.LOW,
"The audience used for fetching an access token.",
CONNECTION_GROUP,
groupCounter++,
ConfigDef.Width.LONG,
OAUTH2_CLIENT_AUDIENCE_CONFIG,
List.of(OAUTH2_ACCESS_TOKEN_URL_CONFIG, OAUTH2_CLIENT_ID_CONFIG,
OAUTH2_CLIENT_SECRET_CONFIG, OAUTH2_CLIENT_SCOPE_CONFIG,
OAUTH2_CLIENT_AUTHORIZATION_MODE_CONFIG, OAUTH2_RESPONSE_TOKEN_PROPERTY_CONFIG)
);
configDef.define(
OAUTH2_CLIENT_SCOPE_CONFIG,
Expand All @@ -291,7 +313,8 @@ public String toString() {
groupCounter++,
ConfigDef.Width.LONG,
OAUTH2_CLIENT_SCOPE_CONFIG,
List.of(OAUTH2_ACCESS_TOKEN_URL_CONFIG, OAUTH2_CLIENT_ID_CONFIG, OAUTH2_CLIENT_SECRET_CONFIG,
List.of(OAUTH2_ACCESS_TOKEN_URL_CONFIG, OAUTH2_CLIENT_ID_CONFIG,
OAUTH2_CLIENT_SECRET_CONFIG, OAUTH2_CLIENT_AUDIENCE_CONFIG,
OAUTH2_CLIENT_AUTHORIZATION_MODE_CONFIG, OAUTH2_RESPONSE_TOKEN_PROPERTY_CONFIG)
);
configDef.define(
Expand All @@ -312,7 +335,8 @@ public String toString() {
ConfigDef.Width.LONG,
OAUTH2_RESPONSE_TOKEN_PROPERTY_CONFIG,
List.of(OAUTH2_ACCESS_TOKEN_URL_CONFIG, OAUTH2_CLIENT_ID_CONFIG, OAUTH2_CLIENT_SECRET_CONFIG,
OAUTH2_CLIENT_AUTHORIZATION_MODE_CONFIG, OAUTH2_CLIENT_SCOPE_CONFIG)
OAUTH2_CLIENT_AUTHORIZATION_MODE_CONFIG, OAUTH2_CLIENT_AUDIENCE_CONFIG,
OAUTH2_CLIENT_SCOPE_CONFIG)
);
}

Expand Down Expand Up @@ -643,6 +667,10 @@ public final OAuth2AuthorizationMode oauth2AuthorizationMode() {
return OAuth2AuthorizationMode.valueOf(getString(OAUTH2_CLIENT_AUTHORIZATION_MODE_CONFIG).toUpperCase());
}

public final String oauth2ClientAudience() {
return getString(OAUTH2_CLIENT_AUDIENCE_CONFIG);
}

public final String oauth2ClientScope() {
return getString(OAUTH2_CLIENT_SCOPE_CONFIG);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@ public HttpRequest.Builder build(final HttpSinkConfig config) {
if (config.oauth2ClientScope() != null) {
accessTokenRequestBodyBuilder.add(encodeNameAndValue("scope", config.oauth2ClientScope()));
}
if (config.oauth2ClientAudience() != null) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Could we add tests covering this new field?

accessTokenRequestBodyBuilder.add(encodeNameAndValue("audience", config
.oauth2ClientAudience()));
}

setClientIdAndSecret(accessTokenRequestBuilder, accessTokenRequestBodyBuilder, config);
return accessTokenRequestBuilder
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ void correctMinimalConfig() throws URISyntaxException {
.returns(null, from(HttpSinkConfig::oauth2AccessTokenUri))
.returns(null, from(HttpSinkConfig::oauth2ClientId))
.returns(null, from(HttpSinkConfig::oauth2ClientSecret))
.returns(null, from(HttpSinkConfig::oauth2ClientAudience))
.returns(null, from(HttpSinkConfig::oauth2ClientScope))
.returns(OAuth2AuthorizationMode.HEADER, from(HttpSinkConfig::oauth2AuthorizationMode))
.returns("access_token", from(HttpSinkConfig::oauth2ResponseTokenProperty))
Expand Down Expand Up @@ -176,6 +177,7 @@ void validOAuth2MinimalConfiguration() throws URISyntaxException {
.returns(new URI("http://localhost:8090/token"), from(HttpSinkConfig::oauth2AccessTokenUri))
.returns("client_id", from(HttpSinkConfig::oauth2ClientId))
.returns("client_secret", from(httpSinkConfig -> httpSinkConfig.oauth2ClientSecret().value()))
.returns(null, from(HttpSinkConfig::oauth2ClientAudience))
.returns(null, from(HttpSinkConfig::oauth2ClientScope))
.returns(OAuth2AuthorizationMode.HEADER, from(HttpSinkConfig::oauth2AuthorizationMode))
.returns("access_token", from(HttpSinkConfig::oauth2ResponseTokenProperty));
Expand All @@ -191,6 +193,7 @@ void validOAuth2FullConfiguration() throws URISyntaxException {
"oauth2.client.id", "client_id",
"oauth2.client.secret", "client_secret",
"oauth2.client.authorization.mode", "url",
"oauth2.client.audience", "http://localhost:8000/api",
"oauth2.client.scope", "scope1,scope2",
"oauth2.response.token.property", "moooooo"
);
Expand All @@ -201,6 +204,7 @@ void validOAuth2FullConfiguration() throws URISyntaxException {
.returns(new URI("http://localhost:8090/token"), from(HttpSinkConfig::oauth2AccessTokenUri))
.returns("client_id", from(HttpSinkConfig::oauth2ClientId))
.returns("client_secret", from(httpSinkConfig -> httpSinkConfig.oauth2ClientSecret().value()))
.returns("http://localhost:8000/api", from(HttpSinkConfig::oauth2ClientAudience))
.returns("scope1,scope2", from(HttpSinkConfig::oauth2ClientScope))
.returns(OAuth2AuthorizationMode.URL, from(HttpSinkConfig::oauth2AuthorizationMode))
.returns("moooooo", from(HttpSinkConfig::oauth2ResponseTokenProperty));
Expand Down