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

Field always_include_in_token is now editable for all the default claims except sub #790

Merged
merged 1 commit into from
Nov 10, 2021
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
11 changes: 11 additions & 0 deletions examples/okta_auth_server_claim_default/updated.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
resource "okta_auth_server_claim_default" "test" {
name = "address"
auth_server_id = okta_auth_server.test.id
always_include_in_token = true
}

resource "okta_auth_server" "test" {
name = "testAcc_replace_with_uuid"
description = "test"
audiences = ["whatever.rise.zone"]
}
23 changes: 18 additions & 5 deletions okta/resource_okta_auth_server_claim_default.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ func resourceAuthServerClaimDefault() *schema.Resource {
},
"always_include_in_token": {
Type: schema.TypeBool,
Optional: true,
Computed: true,
},
},
Expand Down Expand Up @@ -110,6 +111,13 @@ func resourceAuthServerClaimDefaultUpdate(ctx context.Context, d *schema.Resourc
return diag.FromErr(err)
}
d.SetId(claim.Id)
if d.Get("name").(string) != "sub" && d.Get("always_include_in_token").(bool) != *claim.AlwaysIncludeInToken {
claim.AlwaysIncludeInToken = boolPtr(d.Get("always_include_in_token").(bool))
claim, _, err = getOktaClientFromMetadata(m).AuthorizationServer.UpdateOAuth2Claim(ctx, d.Get("auth_server_id").(string), d.Id(), *claim)
if err != nil {
return diag.Errorf("failed to update auth server default claim: %v", err)
}
}
if claim.Conditions != nil && len(claim.Conditions.Scopes) > 0 {
_ = d.Set("scopes", convertStringSliceToSet(claim.Conditions.Scopes))
}
Expand All @@ -119,15 +127,20 @@ func resourceAuthServerClaimDefaultUpdate(ctx context.Context, d *schema.Resourc
_ = d.Set("claim_type", claim.ClaimType)
_ = d.Set("always_include_in_token", claim.AlwaysIncludeInToken)
if d.Get("name").(string) != "sub" {
_ = d.Set("value", claim.Value)
return nil // all the values are computed, so just stop here
}
}
if d.Get("name").(string) != "sub" {
// all the default claims except "sub" are immutable
if d.Get("name").(string) == "sub" {
if d.Get("value").(string) == "" {
return diag.Errorf("'value' is required parameter for 'sub' claim")
}
if !d.Get("always_include_in_token").(bool) {
return diag.Errorf("'sub' claim can not be excluded from the token")
}
}
if (d.Get("name").(string) != "sub" && !d.HasChange("always_include_in_token")) || // for the default claims except `sub` only `always_include_in_token` field can be updated
(d.Get("name").(string) == "sub" && !d.HasChange("value")) { // for the `sub` claim only `value` field can be updated
return resourceAuthServerClaimDefaultRead(ctx, d, m)
} else if d.Get("value").(string) == "" {
return diag.Errorf("'value' is required parameter for 'sub' claim")
}
claim := buildAuthServerClaimDefault(d)
_, _, err := getOktaClientFromMetadata(m).AuthorizationServer.UpdateOAuth2Claim(ctx, d.Get("auth_server_id").(string), d.Id(), claim)
Expand Down
12 changes: 12 additions & 0 deletions okta/resource_okta_auth_server_claim_default_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ func TestAccOktaAuthServerClaimDefault(t *testing.T) {
resourceName := fmt.Sprintf("%s.test", authServerClaimDefault)
mgr := newFixtureManager(authServerClaimDefault)
config := mgr.GetFixtures("basic.tf", ri, t)
updated := mgr.GetFixtures("updated.tf", ri, t)
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
ProviderFactories: testAccProvidersFactories,
Expand All @@ -25,6 +26,17 @@ func TestAccOktaAuthServerClaimDefault(t *testing.T) {
resource.TestCheckResourceAttr(resourceName, "name", "address"),
resource.TestCheckResourceAttr(resourceName, "value_type", "SYSTEM"),
resource.TestCheckResourceAttr(resourceName, "claim_type", "IDENTITY"),
resource.TestCheckResourceAttr(resourceName, "always_include_in_token", "false"),
),
},
{
Config: updated,
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr(resourceName, "status", statusActive),
resource.TestCheckResourceAttr(resourceName, "name", "address"),
resource.TestCheckResourceAttr(resourceName, "value_type", "SYSTEM"),
resource.TestCheckResourceAttr(resourceName, "claim_type", "IDENTITY"),
resource.TestCheckResourceAttr(resourceName, "always_include_in_token", "true"),
),
},
},
Expand Down