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

Support custom saml provider idp #656

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
1 change: 1 addition & 0 deletions docs/resources/saml_identity_provider.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ resource "keycloak_saml_identity_provider" "realm_saml_identity_provider" {
- `single_sign_on_service_url` - (Required) The Url that must be used to send authentication requests (SAML AuthnRequest).
- `single_logout_service_url` - (Optional) The Url that must be used to send logout requests.
- `backchannel_supported` - (Optional) Does the external IDP support back-channel logout ?.
- `provider_id` - (Optional) The ID of the identity provider to use. Defaults to `saml`, which should be used unless you have extended Keycloak and provided your own implementation.
- `name_id_policy_format` - (Optional) Specifies the URI reference corresponding to a name identifier format. Defaults to empty.
- `post_binding_response` - (Optional) Indicates whether to respond to requests using HTTP-POST binding. If false, HTTP-REDIRECT binding will be used..
- `post_binding_authn_request` - (Optional) Indicates whether the AuthnRequest must be sent using HTTP-POST binding. If false, HTTP-REDIRECT binding will be used.
Expand Down
15 changes: 14 additions & 1 deletion example/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ resource "keycloak_openid_client" "test_client" {
backchannel_logout_revoke_offline_sessions = true

extra_config = {
customAttribute = "a test custom value"
customAttribute = "a test custom value"
}
}

Expand Down Expand Up @@ -787,6 +787,19 @@ resource keycloak_hardcoded_attribute_identity_provider_mapper saml {
}
}

resource keycloak_saml_identity_provider saml_custom {
realm = keycloak_realm.test.id
alias = "custom_saml"
provider_id = "saml"
entity_id = "https://example.com/entity_id"
single_sign_on_service_url = "https://example.com/auth"
sync_mode = "FORCE"
gui_order = 4
extra_config = {
mycustomAttribute = "aValue"
}
}

data "keycloak_openid_client" "broker" {
realm_id = keycloak_realm.test.id
client_id = "broker"
Expand Down
8 changes: 7 additions & 1 deletion provider/resource_keycloak_saml_identity_provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,12 @@ var principalTypes = []string{

func resourceKeycloakSamlIdentityProvider() *schema.Resource {
samlSchema := map[string]*schema.Schema{
"provider_id": {
Type: schema.TypeString,
Optional: true,
Default: "saml",
Description: "provider id, is always saml, unless you have a custom implementation",
},
"backchannel_supported": {
Type: schema.TypeBool,
Optional: true,
Expand Down Expand Up @@ -150,7 +156,7 @@ func resourceKeycloakSamlIdentityProvider() *schema.Resource {

func getSamlIdentityProviderFromData(data *schema.ResourceData) (*keycloak.IdentityProvider, error) {
rec, defaultConfig := getIdentityProviderFromData(data)
rec.ProviderId = "saml"
rec.ProviderId = data.Get("provider_id").(string)

samlIdentityProviderConfig := &keycloak.IdentityProviderConfig{
ValidateSignature: keycloak.KeycloakBoolQuoted(data.Get("validate_signature").(bool)),
Expand Down
34 changes: 34 additions & 0 deletions provider/resource_keycloak_saml_identity_provider_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,24 @@ func TestAccKeycloakSamlIdentityProvider_basic(t *testing.T) {
})
}

func TestAccKeycloakSamlIdentityProvider_customProviderId(t *testing.T) {
t.Parallel()

samlName := acctest.RandomWithPrefix("tf-acc")

resource.Test(t, resource.TestCase{
ProviderFactories: testAccProviderFactories,
PreCheck: func() { testAccPreCheck(t) },
CheckDestroy: testAccCheckKeycloakSamlIdentityProviderDestroy(),
Steps: []resource.TestStep{
{
Config: testKeycloakSamlIdentityProvider_customProviderId(samlName, "saml"), //actually needs to be something that exists
Check: testAccCheckKeycloakSamlIdentityProviderExists("keycloak_saml_identity_provider.saml"),
},
},
})
}

func TestAccKeycloakSamlIdentityProvider_extraConfig(t *testing.T) {
t.Parallel()

Expand Down Expand Up @@ -274,6 +292,22 @@ resource "keycloak_saml_identity_provider" "saml" {
`, testAccRealm.Realm, saml)
}

func testKeycloakSamlIdentityProvider_customProviderId(saml, providerId string) string {
return fmt.Sprintf(`
data "keycloak_realm" "realm" {
realm = "%s"
}

resource "keycloak_saml_identity_provider" "saml" {
realm = data.keycloak_realm.realm.id
alias = "%s"
provider_id = "%s"
entity_id = "https://example.com/entity_id"
single_sign_on_service_url = "https://example.com/auth"
}
`, testAccRealm.Realm, saml, providerId)
}

func testKeycloakSamlIdentityProvider_extra_config(alias, configKey, configValue string) string {
return fmt.Sprintf(`
data "keycloak_realm" "realm" {
Expand Down