diff --git a/server-spi-private/src/main/java/org/keycloak/broker/provider/util/SimpleHttp.java b/server-spi-private/src/main/java/org/keycloak/broker/provider/util/SimpleHttp.java index fe743fef20..d40274c159 100755 --- a/server-spi-private/src/main/java/org/keycloak/broker/provider/util/SimpleHttp.java +++ b/server-spi-private/src/main/java/org/keycloak/broker/provider/util/SimpleHttp.java @@ -248,6 +248,13 @@ public class SimpleHttp { } } + /** + * @return the URL without params + */ + public String getUrl() { + return url; + } + private Response makeRequest() throws IOException { HttpRequestBase httpRequest = createHttpRequest(); diff --git a/services/src/main/java/org/keycloak/broker/oidc/AbstractOAuth2IdentityProvider.java b/services/src/main/java/org/keycloak/broker/oidc/AbstractOAuth2IdentityProvider.java index 1fb4d684df..72242391d4 100755 --- a/services/src/main/java/org/keycloak/broker/oidc/AbstractOAuth2IdentityProvider.java +++ b/services/src/main/java/org/keycloak/broker/oidc/AbstractOAuth2IdentityProvider.java @@ -479,7 +479,10 @@ public abstract class AbstractOAuth2IdentityProvider= 200 && status < 400; + response = simpleResponse.asString(); + + if (!success) { + logger.errorf("Unexpected response from token endpoint %s. status=%s, response=%s", + simpleHttp.getUrl(), status, response); + return errorIdentityProviderLogin(Messages.IDENTITY_PROVIDER_UNEXPECTED_ERROR); + } + } + + BrokeredIdentityContext federatedIdentity = provider.getFederatedIdentity(response); + + if (providerConfig.isStoreToken()) { + // make sure that token wasn't already set by getFederatedIdentity(); + // want to be able to allow provider to set the token itself. + if (federatedIdentity.getToken() == null)federatedIdentity.setToken(response); + } + + federatedIdentity.setIdpConfig(providerConfig); + federatedIdentity.setIdp(provider); + federatedIdentity.setAuthenticationSession(authSession); + + return callback.authenticated(federatedIdentity); } catch (WebApplicationException e) { return e.getResponse(); } catch (IdentityBrokerException e) { @@ -524,10 +541,18 @@ public abstract class AbstractOAuth2IdentityProvider