if (authorizationRequest == null || authorizationRequest.getRedirectUri() == null) {
// we have no redirect for the user. very sad.
throw new UnapprovedClientAuthenticationException("Authorization failure, and no redirect URI.", failure);
}
UriComponentsBuilder template = UriComponentsBuilder.fromUriString(authorizationRequest.getRedirectUri());
Map<String, String> query = new LinkedHashMap<String, String>();
StringBuilder values = new StringBuilder();
values.append("error={error}");
query.put("error", failure.getOAuth2ErrorCode());
values.append("&error_description={error_description}");
query.put("error_description", failure.getMessage());
if (authorizationRequest.getState() != null) {
values.append("&state={state}");
query.put("state", authorizationRequest.getState());
}
if (failure.getAdditionalInformation() != null) {
for (Map.Entry<String, String> additionalInfo : failure.getAdditionalInformation().entrySet()) {
values.append("&" + additionalInfo.getKey() + "={" + additionalInfo.getKey() + "}");
query.put(additionalInfo.getKey(), additionalInfo.getValue());
}
}
if (fragment) {
template.fragment(values.toString());
}
else {
template.query(values.toString());
}
return template.build().expand(query).encode().toUriString();
}