Skip to content

Commit

Permalink
Fix okta app saml cannot assign certificate
Browse files Browse the repository at this point in the history
Signed-off-by: Tien Nguyen <[email protected]>
  • Loading branch information
duytiennguyen-okta committed Jul 3, 2024
1 parent 06d665d commit 38cb63c
Show file tree
Hide file tree
Showing 5 changed files with 1,478 additions and 874 deletions.
17 changes: 11 additions & 6 deletions okta/resource_okta_app_saml.go
Original file line number Diff line number Diff line change
Expand Up @@ -361,19 +361,18 @@ request feature flag 'ADVANCED_SSO' be applied to your org.`,
Type: schema.TypeString,
Optional: true,
Description: "The issuer of the Service Provider that generates the Single Logout request",
RequiredWith: []string{"single_logout_url", "single_logout_certificate"},
RequiredWith: []string{"single_logout_url"},
},
"single_logout_url": {
Type: schema.TypeString,
Optional: true,
Description: "The location where the logout response is sent",
RequiredWith: []string{"single_logout_issuer", "single_logout_certificate"},
RequiredWith: []string{"single_logout_issuer"},
},
"single_logout_certificate": {
Type: schema.TypeString,
Optional: true,
Description: "x509 encoded certificate that the Service Provider uses to sign Single Logout requests. Note: should be provided without `-----BEGIN CERTIFICATE-----` and `-----END CERTIFICATE-----`, see [official documentation](https://developer.okta.com/docs/reference/api/apps/#service-provider-certificate).",
RequiredWith: []string{"single_logout_issuer", "single_logout_url"},
Type: schema.TypeString,
Optional: true,
Description: "x509 encoded certificate that the Service Provider uses to sign Single Logout requests. Note: should be provided without `-----BEGIN CERTIFICATE-----` and `-----END CERTIFICATE-----`, see [official documentation](https://developer.okta.com/docs/reference/api/apps/#service-provider-certificate).",
DiffSuppressFunc: func(k, oldValue, newValue string, d *schema.ResourceData) bool {
oldCert, err := certNormalize(oldValue)
if err != nil {
Expand Down Expand Up @@ -636,6 +635,12 @@ func buildSamlApp(d *schema.ResourceData) (*sdk.SamlApplication, error) {
Slo: &sdk.SingleLogout{Enabled: boolPtr(false)},
SamlSignedRequestEnabled: boolPtr(d.Get("saml_signed_request_enabled").(bool)),
}
x5c, ok := d.GetOk("single_logout_certificate")
if ok && x5c != "" {
app.Settings.SignOn.SpCertificate = &sdk.SpCertificate{
X5c: []string{d.Get("single_logout_certificate").(string)},
}
}
sli := d.Get("single_logout_issuer").(string)
if sli != "" {
app.Settings.SignOn.Slo = &sdk.SingleLogout{
Expand Down
54 changes: 54 additions & 0 deletions okta/resource_okta_app_saml_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -430,3 +430,57 @@ func TestAccResourceOktaAppSaml_certdiff(t *testing.T) {
},
})
}

func TestAccResourceOktaAppSaml_Issue2021(t *testing.T) {
mgr := newFixtureManager("resources", appSaml, t.Name())
resourceName := fmt.Sprintf("%s.test", appSaml)
config := `
resource "okta_app_saml" "test" {
accessibility_self_service = "false"
assertion_signed = "true"
audience = "https://example.com/audience"
authn_context_class_ref = "urn:oasis:names:tc:SAML:2.0:ac:classes:PasswordProtectedTransport"
auto_submit_toolbar = "false"
default_relay_state = "/"
destination = "https://example.com/audience"
digest_algorithm = "SHA256"
hide_ios = "true"
hide_web = "true"
honor_force_authn = "true"
idp_issuer = "http://www.okta.com/$${org.externalKey}"
implicit_assignment = "false"
label = "SAML APP"
recipient = "https://example.com/audience"
response_signed = "true"
saml_signed_request_enabled = "true"
saml_version = "2.0"
signature_algorithm = "RSA_SHA256"
sso_url = "https://example.com/sso"
status = "ACTIVE"
subject_name_id_format = "urn:oasis:names:tc:SAML:2.0:nameid-format:persistent"
subject_name_id_template = "$${user.userName}"
user_name_template = "user.login"
user_name_template_push_status = "PUSH"
user_name_template_type = "CUSTOM"
single_logout_certificate = "MIID2zCCAsOgAwIBAgIUHBaBGrGVVkp2kC+yPrhXc5N2+4swDQYJKoZIhvcNAQEL\r\nBQAwfTELMAkGA1UEBhMCQVUxEzARBgNVBAgMClNvbWUtU3RhdGUxITAfBgNVBAoM\r\nGEludGVybmV0IFdpZGdpdHMgUHR5IEx0ZDEUMBIGA1UEAwwLZXhhbXBsZS5jb20x\r\nIDAeBgkqhkiG9w0BCQEWEWhlbGxvQGV4YW1wbGUuY29tMB4XDTI0MDYxODAzNTU0\r\n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3dfEBfH5U5VoS\r\n1RqP+9+AB4coGpnm7F660PSwfyQwBZo5/a0HLqbZFA=="
}
`
oktaResourceTest(t, resource.TestCase{
PreCheck: testAccPreCheck(t),
ErrorCheck: testAccErrorChecks(t),
ProviderFactories: testAccProvidersFactories,
CheckDestroy: checkResourceDestroy(appSaml, createDoesAppExist(sdk.NewSamlApplication())),
Steps: []resource.TestStep{
{
Config: mgr.ConfigReplace(config),
Check: resource.ComposeTestCheckFunc(
ensureResourceExists(resourceName, createDoesAppExist(sdk.NewSamlApplication())),
resource.TestCheckResourceAttrSet(resourceName, "single_logout_certificate"),
resource.TestCheckNoResourceAttr(resourceName, "single_logout_url"),
resource.TestCheckNoResourceAttr(resourceName, "single_logout_issuer"),
),
},
},
})
}
Loading

0 comments on commit 38cb63c

Please sign in to comment.