KEYCLOAK-16947 add error parameters to access token response & improve logging

This commit is contained in:
Benjamin Weimer 2021-01-28 08:54:19 +01:00 committed by Marek Posolda
parent 95bf912dc9
commit f66354a80e
3 changed files with 37 additions and 2 deletions

View file

@ -61,6 +61,15 @@ public class AccessTokenResponse {
@JsonProperty("scope") @JsonProperty("scope")
protected String scope; protected String scope;
@JsonProperty("error")
protected String error;
@JsonProperty("error_description")
protected String errorDescription;
@JsonProperty("error_uri")
protected String errorUri;
public String getScope() { public String getScope() {
return scope; return scope;
} }
@ -143,4 +152,28 @@ public class AccessTokenResponse {
otherClaims.put(name, value); otherClaims.put(name, value);
} }
public String getError() {
return error;
}
public void setError(String error) {
this.error = error;
}
public String getErrorDescription() {
return errorDescription;
}
public void setErrorDescription(String errorDescription) {
this.errorDescription = errorDescription;
}
public String getErrorUri() {
return errorUri;
}
public void setErrorUri(String errorUri) {
this.errorUri = errorUri;
}
} }

View file

@ -518,7 +518,9 @@ public class OIDCIdentityProvider extends AbstractOAuth2IdentityProvider<OIDCIde
String accessToken = tokenResponse.getToken(); String accessToken = tokenResponse.getToken();
if (accessToken == null) { if (accessToken == null) {
throw new IdentityBrokerException("No access_token from server."); throw new IdentityBrokerException("No access_token from server. error='" + tokenResponse.getError() +
"', error_description='" + tokenResponse.getErrorDescription() +
"', error_uri='" + tokenResponse.getErrorUri() + "'");
} }
return accessToken; return accessToken;
} }

View file

@ -118,7 +118,7 @@ public class LinkAndExchangeServlet extends HttpServlet {
String linkUrl = null; String linkUrl = null;
try { try {
AccessTokenResponse response = doTokenExchange(realm, tokenString, provider, clientId, "password"); AccessTokenResponse response = doTokenExchange(realm, tokenString, provider, clientId, "password");
String error = (String)response.getOtherClaims().get("error"); String error = response.getError();
if (error != null) { if (error != null) {
System.out.println("*** error : " + error); System.out.println("*** error : " + error);
System.out.println("*** link-url: " + response.getOtherClaims().get("account-link-url")); System.out.println("*** link-url: " + response.getOtherClaims().get("account-link-url"));