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

allow refresh token removal #1586

Merged
merged 2 commits into from
Jun 9, 2023
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
13 changes: 13 additions & 0 deletions examples/okta_app_oauth/refresh_second_update.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
resource "okta_app_oauth" "test" {
label = "testAcc_replace_with_uuid"
status = "ACTIVE"
type = "browser"
grant_types = ["authorization_code"]
redirect_uris = ["http://d.com/aaa"]
response_types = ["code"]
hide_ios = true
hide_web = true
auto_submit_toolbar = false
refresh_token_rotation = "ROTATE"
refresh_token_leeway = 30
}
16 changes: 13 additions & 3 deletions okta/resource_okta_app_oauth.go
Original file line number Diff line number Diff line change
Expand Up @@ -770,21 +770,31 @@ func buildAppOAuth(d *schema.ResourceData) *sdk.OpenIdConnectApplication {
}

refresh := &sdk.OpenIdConnectApplicationSettingsRefreshToken{}
hasRefresh := false
var hasRefresh bool
for _, grant_type := range grantTypes {
if grant_type == refreshToken {
hasRefresh = true
duytiennguyen-okta marked this conversation as resolved.
Show resolved Hide resolved
break
}
}
if rotate, ok := d.GetOk("refresh_token_rotation"); ok {
refresh.RotationType = rotate.(string)
hasRefresh = true
}

if leeway, ok := d.GetOk("refresh_token_leeway"); ok {
refresh.LeewayPtr = int64Ptr(leeway.(int))
hasRefresh = true
}

if hasRefresh {
app.Settings.OauthClient.RefreshToken = refresh
}

// TODO: need to put a warning
// if !hasRefresh && refresh != nil {
// return nil, errors.New("does not have refresh grant type but refresh_token_rotation and refresh_token_leeway exist in payload")
// }
// TODO unset refresh_token_rotation, refresh_token_leeway

app.Visibility = buildAppVisibility(d)
app.Accessibility = buildAppAccessibility(d)

Expand Down
14 changes: 13 additions & 1 deletion okta/resource_okta_app_oauth_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ func TestAccResourceOktaAppOauth_refreshToken(t *testing.T) {
mgr := newFixtureManager(appOAuth, t.Name())
config := mgr.GetFixtures("refresh.tf", t)
update := mgr.GetFixtures("refresh_update.tf", t)
secondUpdate := mgr.GetFixtures("refresh_second_update.tf", t)
resourceName := fmt.Sprintf("%s.test", appOAuth)

oktaResourceTest(t, resource.TestCase{
Expand All @@ -107,7 +108,7 @@ func TestAccResourceOktaAppOauth_refreshToken(t *testing.T) {
resource.TestCheckResourceAttr(resourceName, "type", "browser"),
resource.TestCheckResourceAttr(resourceName, "grant_types.#", "2"),
resource.TestCheckResourceAttr(resourceName, "refresh_token_rotation", "STATIC"),
resource.TestCheckResourceAttr(resourceName, "refresh_token_leeway", "0"),
resource.TestCheckNoResourceAttr(resourceName, "refresh_token_leeway"),
),
},
{
Expand All @@ -121,6 +122,17 @@ func TestAccResourceOktaAppOauth_refreshToken(t *testing.T) {
resource.TestCheckResourceAttr(resourceName, "refresh_token_leeway", "30"),
),
},
{
Config: secondUpdate,
Check: resource.ComposeTestCheckFunc(
ensureResourceExists(resourceName, createDoesAppExist(sdk.NewOpenIdConnectApplication())),
resource.TestCheckResourceAttr(resourceName, "label", buildResourceName(mgr.Seed)),
resource.TestCheckResourceAttr(resourceName, "type", "browser"),
resource.TestCheckResourceAttr(resourceName, "grant_types.#", "1"),
resource.TestCheckResourceAttr(resourceName, "refresh_token_rotation", "ROTATE"),
resource.TestCheckResourceAttr(resourceName, "refresh_token_leeway", "30"),
),
},
},
})
}
Expand Down