Skip to content

feat: Support additional request parameters for 3LO #1070

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

Open
wants to merge 6 commits 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
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,9 @@ public class AuthorizationCodeFlow {
/** Refresh listeners provided by the client. */
private final Collection<CredentialRefreshListener> refreshListeners;

/** Additional parameters to pass to authorization url. */
private final Map<String, String> additionalParameters;

/**
* @param method method of presenting the access token to the resource server (for example {@link
* BearerToken#authorizationHeaderAccessMethod})
Expand Down Expand Up @@ -156,6 +159,7 @@ protected AuthorizationCodeFlow(Builder builder) {
clientId = Preconditions.checkNotNull(builder.clientId);
authorizationServerEncodedUrl =
Preconditions.checkNotNull(builder.authorizationServerEncodedUrl);
additionalParameters = builder.additionalParameters;
requestInitializer = builder.requestInitializer;
credentialStore = builder.credentialStore;
credentialDataStore = builder.credentialDataStore;
Expand Down Expand Up @@ -192,6 +196,11 @@ public AuthorizationCodeRequestUrl newAuthorizationUrl() {
url.setCodeChallenge(pkce.getChallenge());
url.setCodeChallengeMethod(pkce.getChallengeMethod());
}
if (additionalParameters != null) {
for (Map.Entry<String, String> entry : additionalParameters.entrySet()) {
url.put(entry.getKey(), entry.getValue());
}
}
return url;
}

Expand Down Expand Up @@ -549,6 +558,9 @@ public static class Builder {
/** Refresh listeners provided by the client. */
Collection<CredentialRefreshListener> refreshListeners = Lists.newArrayList();

/** Additional authorization url parameters provided by the client * */
Map<String, String> additionalParameters;

/**
* @param method method of presenting the access token to the resource server (for example
* {@link BearerToken#authorizationHeaderAccessMethod})
Expand All @@ -575,6 +587,7 @@ public Builder(
setClientAuthentication(clientAuthentication);
setClientId(clientId);
setAuthorizationServerEncodedUrl(authorizationServerEncodedUrl);
setAdditionalParameters(Collections.<String, String>emptyMap());
}

/** Returns a new instance of an authorization code flow based on this builder. */
Expand Down Expand Up @@ -717,6 +730,19 @@ public Builder setAuthorizationServerEncodedUrl(String authorizationServerEncode
return this;
}

/**
* Sets the additional url parameters.
*
* <p>Overriding is only supported for the purpose of calling the super implementation and
* changing the return type, but nothing else.
*
* @since 1.11
*/
public Builder setAdditionalParameters(Map<String, String> additionalParameters) {
this.additionalParameters = Preconditions.checkNotNull(additionalParameters);
return this;
}

/**
* {@link Beta} <br>
* Returns the credential persistence store or {@code null} for none.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;

/**
Expand Down Expand Up @@ -154,4 +156,24 @@ public void testPKCE() {
assertTrue(methods.contains(url.getCodeChallengeMethod().toLowerCase()));
assertTrue(url.getCodeChallenge().length() > 0);
}

public void testAdditionalParameters() {
Map<String, String> testMap = new HashMap<>();
testMap.put("key", "value");
AuthorizationCodeFlow flow =
new AuthorizationCodeFlow.Builder(
BearerToken.queryParameterAccessMethod(),
new AccessTokenTransport(),
new GsonFactory(),
TOKEN_SERVER_URL,
new BasicAuthentication(CLIENT_ID, CLIENT_SECRET),
CLIENT_ID,
"https://example.com")
.setAdditionalParameters(testMap)
.build();

AuthorizationCodeRequestUrl url = flow.newAuthorizationUrl();
String urlString = url.build();
assertTrue(urlString.contains("key=value"));
}
}