feat: add DisplayIconClasses to IdentityProviderModel for third-party IDPs https://github.com/klausbetz/apple-identity-provider-keycloak/issues/10 (#14826)

Closes #14974
This commit is contained in:
Klaus Betz 2022-10-18 15:54:06 +02:00 committed by GitHub
parent 97ae90de88
commit 76d9125c3f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 4 deletions

View file

@ -205,6 +205,10 @@ public class IdentityProviderModel implements Serializable {
this.displayName = displayName; this.displayName = displayName;
} }
public String getDisplayIconClasses() {
return null;
}
/** /**
* <p>Validates this configuration. * <p>Validates this configuration.
* *

View file

@ -73,18 +73,21 @@ public class IdentityProviderBean {
if (!hideOnLoginPage) { if (!hideOnLoginPage) {
orderedSet.add(new IdentityProvider(identityProvider.getAlias(), orderedSet.add(new IdentityProvider(identityProvider.getAlias(),
displayName, identityProvider.getProviderId(), loginUrl, displayName, identityProvider.getProviderId(), loginUrl,
config != null ? config.get("guiOrder") : null, getLoginIconClasses(identityProvider.getAlias()))); config != null ? config.get("guiOrder") : null, getLoginIconClasses(identityProvider)));
} }
} }
// Get icon classes defined in properties of current theme with key 'kcLogoIdP-{alias}' // Get icon classes defined in properties of current theme with key 'kcLogoIdP-{alias}'
// OR from IdentityProviderModel.getDisplayIconClasses if not defined in theme (for third-party IDPs like Sign-In-With-Apple)
// f.e. kcLogoIdP-github = fa fa-github // f.e. kcLogoIdP-github = fa fa-github
private String getLoginIconClasses(String alias) { private String getLoginIconClasses(IdentityProviderModel identityProvider) {
final String ICON_THEME_PREFIX = "kcLogoIdP-"; final String ICON_THEME_PREFIX = "kcLogoIdP-";
try { try {
Theme theme = session.theme().getTheme(Theme.Type.LOGIN); Theme theme = session.theme().getTheme(Theme.Type.LOGIN);
return Optional.ofNullable(theme.getProperties().getProperty(ICON_THEME_PREFIX + alias)).orElse(""); Optional<String> classesFromTheme = Optional.ofNullable(theme.getProperties().getProperty(ICON_THEME_PREFIX + identityProvider.getAlias()));
Optional<String> classesFromModel = Optional.ofNullable(identityProvider.getDisplayIconClasses());
return classesFromTheme.orElse(classesFromModel.orElse(""));
} catch (IOException e) { } catch (IOException e) {
//NOP //NOP
} }
@ -102,7 +105,7 @@ public class IdentityProviderBean {
public static class IdentityProvider implements OrderedModel { public static class IdentityProvider implements OrderedModel {
private final String alias; private final String alias;
private final String providerId; // This refer to providerType (facebook, google, etc.) private final String providerId; // This refers to providerType (facebook, google, etc.)
private final String loginUrl; private final String loginUrl;
private final String guiOrder; private final String guiOrder;
private final String displayName; private final String displayName;