Skip to content

Commit

Permalink
minor updates
Browse files Browse the repository at this point in the history
  • Loading branch information
sai-sunder-s committed May 30, 2023
1 parent 9c319c3 commit 9c108f0
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 14 deletions.
2 changes: 0 additions & 2 deletions oauth2_http/java/com/google/auth/oauth2/UserAuthorizer.java
Expand Up @@ -265,8 +265,6 @@ public UserCredentials getCredentials(String userId) throws IOException {
*
* @param code Code returned from OAuth2 consent prompt.
* @param baseUri The URI to resolve the OAuth2 callback URI relative to.
* @param additionalParameters Additional parameters to be added to the post body of token
* endpoint request.
* @return the UserCredentials instance created from the authorization code.
* @throws IOException An error from the server API call to get the tokens.
*/
Expand Down
Expand Up @@ -65,7 +65,7 @@ public class MockTokenServerTransport extends MockHttpTransport {
final Map<String, String> serviceAccounts = new HashMap<String, String>();
final Map<String, String> gdchServiceAccounts = new HashMap<String, String>();
final Map<String, String> codes = new HashMap<String, String>();
final Map<String, Map<String, String>> customParameters =
final Map<String, Map<String, String>> additionalParameters =
new HashMap<String, Map<String, String>>();
URI tokenServerUri = OAuth2Utils.TOKEN_SERVER_URI;
private IOException error;
Expand All @@ -87,13 +87,13 @@ public void addAuthorizationCode(
String refreshToken,
String accessToken,
String grantedScopes,
Map<String, String> customParameters) {
Map<String, String> additionalParameters) {
codes.put(code, refreshToken);
refreshTokens.put(refreshToken, accessToken);
this.grantedScopes.put(refreshToken, grantedScopes);

if (customParameters != null) {
this.customParameters.put(refreshToken, customParameters);
if (additionalParameters != null) {
this.additionalParameters.put(refreshToken, additionalParameters);
}
}

Expand Down Expand Up @@ -231,16 +231,24 @@ public LowLevelHttpResponse execute() throws IOException {
grantedScopesString = grantedScopes.get(refreshToken);
}

if (customParameters.containsKey(refreshToken)) {
Map<String, String> customParametersMap = customParameters.get(refreshToken);
for (Map.Entry<String, String> entry : customParametersMap.entrySet()) {
if (additionalParameters.containsKey(refreshToken)) {
Map<String, String> additionalParametersMap = additionalParameters.get(refreshToken);
for (Map.Entry<String, String> entry : additionalParametersMap.entrySet()) {
String key = entry.getKey();
String value = entry.getValue();
String expectedValue = entry.getValue();
if (!query.containsKey(key)) {
throw new IllegalArgumentException("Missing custom parameter: " + key);
} else if (!query.get(key).equals(value)) {
throw new IllegalArgumentException(
"Custom parameter " + key + " does not match: " + value);
throw new IllegalArgumentException("Missing additional parameter: " + key);
} else {
String actualValue = query.get(key);
if (!expectedValue.equals(actualValue)) {
throw new IllegalArgumentException(
"For additional parameter "
+ key
+ ", Actual value: "
+ actualValue
+ ", Expected value: "
+ expectedValue);
}
}
}
}
Expand Down

0 comments on commit 9c108f0

Please sign in to comment.