diff --git a/forms/common-themes/src/main/resources/theme/login/base/login.ftl b/forms/common-themes/src/main/resources/theme/login/base/login.ftl
index e514b9ee6c..0dea114358 100755
--- a/forms/common-themes/src/main/resources/theme/login/base/login.ftl
+++ b/forms/common-themes/src/main/resources/theme/login/base/login.ftl
@@ -63,14 +63,6 @@
- <#elseif realm.social>
-
-
- <#list social.providers as p>
- - ${p.name}
- #list>
-
-
#if>
<#elseif section = "info" >
<#if realm.password && realm.registrationAllowed>
@@ -83,7 +75,7 @@
diff --git a/forms/login-freemarker/src/main/java/org/keycloak/login/freemarker/model/IdentityProviderBean.java b/forms/login-freemarker/src/main/java/org/keycloak/login/freemarker/model/IdentityProviderBean.java
index edb1f0756b..9cbf469b8d 100755
--- a/forms/login-freemarker/src/main/java/org/keycloak/login/freemarker/model/IdentityProviderBean.java
+++ b/forms/login-freemarker/src/main/java/org/keycloak/login/freemarker/model/IdentityProviderBean.java
@@ -65,7 +65,7 @@ public class IdentityProviderBean {
private void addIdentityProvider(RealmModel realm, URI baseURI, IdentityProviderModel identityProvider) {
String loginUrl = Urls.identityProviderAuthnRequest(baseURI, identityProvider.getId(), realm.getName()).toString();
- providers.add(new IdentityProvider(identityProvider.getId(), identityProvider.getName(), loginUrl));
+ providers.add(new IdentityProvider(identityProvider.getId(), identityProvider.getProviderId(), identityProvider.getName(), loginUrl));
}
public List getProviders() {
@@ -79,11 +79,13 @@ public class IdentityProviderBean {
public static class IdentityProvider {
private final String id;
+ private final String providerId; // This refer to providerType (facebook, google, etc.)
private final String name;
private final String loginUrl;
- public IdentityProvider(String id, String name, String loginUrl) {
+ public IdentityProvider(String id, String providerId, String name, String loginUrl) {
this.id = id;
+ this.providerId = providerId;
if (name == null) {
name = id;
@@ -105,5 +107,8 @@ public class IdentityProviderBean {
return loginUrl;
}
+ public String getProviderId() {
+ return providerId;
+ }
}
}
diff --git a/testsuite/integration/src/test/java/org/keycloak/testsuite/broker/AbstractIdentityProviderTest.java b/testsuite/integration/src/test/java/org/keycloak/testsuite/broker/AbstractIdentityProviderTest.java
index 83da549645..d20309aac6 100644
--- a/testsuite/integration/src/test/java/org/keycloak/testsuite/broker/AbstractIdentityProviderTest.java
+++ b/testsuite/integration/src/test/java/org/keycloak/testsuite/broker/AbstractIdentityProviderTest.java
@@ -239,7 +239,7 @@ public abstract class AbstractIdentityProviderTest {
// Provider button is available on login page
this.driver.navigate().to("http://localhost:8081/test-app/");
assertTrue(this.driver.getCurrentUrl().startsWith("http://localhost:8081/auth/realms/realm-with-broker/protocol/openid-connect/auth"));
- this.driver.findElement(By.className(getProviderId()));
+ loginPage.findSocialButton(getProviderId());
// Add identityProvider to client model
List appIdentityProviders = new ArrayList();
@@ -251,7 +251,7 @@ public abstract class AbstractIdentityProviderTest {
// Provider button still available on login page
this.driver.navigate().to("http://localhost:8081/test-app/");
- this.driver.findElement(By.className(getProviderId()));
+ loginPage.findSocialButton(getProviderId());
}
@Test
@@ -389,17 +389,7 @@ public abstract class AbstractIdentityProviderTest {
assertNotNull(identityModel.getToken());
- ClientModel clientModel = realm.findClient("test-app");
- ClientIdentityProviderMappingModel providerMappingModel = null;
-
- for (ClientIdentityProviderMappingModel identityProviderMappingModel : clientModel.getIdentityProviders()) {
- if (identityProviderMappingModel.getIdentityProvider().equals(getProviderId())) {
- providerMappingModel = identityProviderMappingModel;
- break;
- }
- }
-
- providerMappingModel.setRetrieveToken(false);
+ configureRetrieveToken(realm.findClient("test-app"), getProviderId(), false);
UserSessionStatus userSessionStatus = retrieveSessionStatus();
String accessToken = userSessionStatus.getAccessTokenString();
@@ -417,7 +407,7 @@ public abstract class AbstractIdentityProviderTest {
assertEquals(Status.BAD_REQUEST.getStatusCode(), response.getStatus());
- providerMappingModel.setRetrieveToken(true);
+ configureRetrieveToken(getRealm().findClient("test-app"), getProviderId(), true);
client = ClientBuilder.newBuilder().register(authFilter).build();
tokenEndpoint = client.target(tokenEndpointUrl);
@@ -470,14 +460,7 @@ public abstract class AbstractIdentityProviderTest {
ClientModel clientModel = getRealm().findClient("third-party");
assertEquals(0, clientModel.getIdentityProviders().size());
- ClientIdentityProviderMappingModel providerMappingModel = new ClientIdentityProviderMappingModel();
- providerMappingModel.setIdentityProvider(getProviderId());
- providerMappingModel.setRetrieveToken(true);
- List providerMappingModels = new ArrayList();
- providerMappingModels.add(providerMappingModel);
- clientModel.updateIdentityProviders(providerMappingModels);
- brokerServerRule.stopSession(session, true);
- session = brokerServerRule.startSession();
+ configureRetrieveToken(clientModel, getProviderId(), true);
AccessTokenResponse accessToken = oauth.doAccessTokenRequest(oauth.getCurrentQuery().get(OAuth2Constants.CODE), "password");
URI tokenEndpointUrl = Urls.identityProviderRetrieveToken(BASE_URI, getProviderId(), getRealm().getName());
@@ -496,6 +479,33 @@ public abstract class AbstractIdentityProviderTest {
doAssertTokenRetrieval(driver.getPageSource());
}
+ private void configureRetrieveToken(ClientModel clientModel, String providerId, boolean retrieveToken) {
+ List providerMappingModels = clientModel.getIdentityProviders();
+ ClientIdentityProviderMappingModel providerMappingModel = null;
+
+ // Check if provider is already linked with this client
+ for (ClientIdentityProviderMappingModel current : providerMappingModels) {
+ if (current.getIdentityProvider().equals(providerId)) {
+ providerMappingModel = current;
+ break;
+ }
+ }
+
+ // Link provider with client if not linked yet
+ if (providerMappingModel == null) {
+ providerMappingModel = new ClientIdentityProviderMappingModel();
+ providerMappingModel.setIdentityProvider(providerId);
+ providerMappingModels.add(providerMappingModel);
+ }
+
+ providerMappingModel.setRetrieveToken(retrieveToken);
+
+ clientModel.updateIdentityProviders(providerMappingModels);
+
+ brokerServerRule.stopSession(session, true);
+ session = brokerServerRule.startSession();
+ }
+
protected abstract void doAssertTokenRetrieval(String pageSource);
private void assertSuccessfulAuthentication(IdentityProviderModel identityProviderModel, String username) {
diff --git a/testsuite/integration/src/test/java/org/keycloak/testsuite/pages/LoginPage.java b/testsuite/integration/src/test/java/org/keycloak/testsuite/pages/LoginPage.java
index fc83347637..7d83b0cb14 100644
--- a/testsuite/integration/src/test/java/org/keycloak/testsuite/pages/LoginPage.java
+++ b/testsuite/integration/src/test/java/org/keycloak/testsuite/pages/LoginPage.java
@@ -110,8 +110,14 @@ public class LoginPage extends AbstractPage {
registerLink.click();
}
- public void clickSocial(String id) {
- driver.findElement(By.className(id)).click();
+ public void clickSocial(String providerId) {
+ WebElement socialButton = findSocialButton(providerId);
+ socialButton.click();
+ }
+
+ public WebElement findSocialButton(String providerId) {
+ String id = "zocial-" + providerId;
+ return this.driver.findElement(By.id(id));
}
public void resetPassword() {