Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix attribute importer and user template mapper for Facebook/Google #482

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions keycloak/identity_provider_mapper.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (

type IdentityProviderMapperConfig struct {
UserAttribute string `json:"user.attribute,omitempty"`
UserAttributeName string `json:"userAttribute,omitempty"`
Claim string `json:"claim,omitempty"`
ClaimValue string `json:"claim.value,omitempty"`
HardcodedAttribute string `json:"attribute,omitempty"`
Expand All @@ -19,6 +20,7 @@ type IdentityProviderMapperConfig struct {
AttributeFriendlyName string `json:"attribute.friendly.name,omitempty"`
Template string `json:"template,omitempty"`
Role string `json:"role,omitempty"`
JsonField string `json:"jsonField,omitEmpty"`
ExtraConfig map[string]interface{} `json:"-"`
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,12 @@ func getAttributeImporterIdentityProviderMapperFromData(data *schema.ResourceDat
if _, ok := data.GetOk("claim_name"); !ok {
return nil, fmt.Errorf(`provider.keycloak: keycloak_attribute_importer_identity_provider_mapper: %s: "claim_name": should be set for %s identity provider`, data.Get("name").(string), identityProvider.ProviderId)
}

rec.Config.Claim = data.Get("claim_name").(string)
} else if identityProvider.ProviderId == "facebook" || identityProvider.ProviderId == "google" {
rec.IdentityProviderMapper = fmt.Sprintf("%s-user-attribute-mapper", identityProvider.ProviderId)
rec.Config.JsonField = data.Get("claim_name").(string)
rec.Config.UserAttributeName = data.Get("user_attribute").(string)
} else {
return nil, fmt.Errorf(`provider.keycloak: keycloak_attribute_importer_identity_provider_mapper: %s: "%s" identity provider is not supported yet`, data.Get("name").(string), identityProvider.ProviderId)
}
Expand All @@ -79,10 +84,16 @@ func getAttributeImporterIdentityProviderMapperFromData(data *schema.ResourceDat

func setAttributeImporterIdentityProviderMapperData(data *schema.ResourceData, identityProviderMapper *keycloak.IdentityProviderMapper) error {
setIdentityProviderMapperData(data, identityProviderMapper)

claimName := identityProviderMapper.Config.Claim
if claimName == "" {
claimName = identityProviderMapper.Config.JsonField
}

data.Set("attribute_name", identityProviderMapper.Config.Attribute)
data.Set("user_attribute", identityProviderMapper.Config.UserAttribute)
data.Set("attribute_friendly_name", identityProviderMapper.Config.AttributeFriendlyName)
data.Set("claim_name", identityProviderMapper.Config.Claim)
data.Set("claim_name", claimName)
data.Set("extra_config", identityProviderMapper.Config.ExtraConfig)
return nil
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,13 @@ func getUserTemplateImporterIdentityProviderMapperFromData(data *schema.Resource
if err != nil {
return nil, handleNotFoundError(err, data)
}
rec.IdentityProviderMapper = fmt.Sprintf("%s-username-idp-mapper", identityProvider.ProviderId)

if identityProvider.ProviderId == "facebook" || identityProvider.ProviderId == "google" {
rec.IdentityProviderMapper = "oidc-username-idp-mapper"
} else {
rec.IdentityProviderMapper = fmt.Sprintf("%s-username-idp-mapper", identityProvider.ProviderId)
}

rec.Config = &keycloak.IdentityProviderMapperConfig{
Template: data.Get("template").(string),
ExtraConfig: extraConfig,
Expand Down