Skip to content
This repository has been archived by the owner on Mar 8, 2022. It is now read-only.

Commit

Permalink
Add support for google-apps connection strategy
Browse files Browse the repository at this point in the history
  • Loading branch information
mattoddie committed Jul 29, 2021
1 parent d2e837b commit f0f0fd1
Show file tree
Hide file tree
Showing 2 changed files with 88 additions and 0 deletions.
49 changes: 49 additions & 0 deletions auth0/resource_auth0_connection_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -760,6 +760,55 @@ resource "auth0_connection" "google_oauth2" {
}
`

func TestAccConnectionGoogleApps(t *testing.T) {

rand := random.String(6)

resource.Test(t, resource.TestCase{
Providers: map[string]terraform.ResourceProvider{
"auth0": Provider(),
},
Steps: []resource.TestStep{
{
Config: random.Template(testAccConnectionGoogleApps, rand),
Check: resource.ComposeTestCheckFunc(
random.TestCheckResourceAttr("auth0_connection.google_apps", "name", "Acceptance-Test-Google-Apps-{{.random}}", rand),
resource.TestCheckResourceAttr("auth0_connection.google_apps", "strategy", "google-apps"),
resource.TestCheckResourceAttr("auth0_connection.google_apps", "options.0.client_id", ""),
resource.TestCheckResourceAttr("auth0_connection.google_apps", "options.0.client_secret", ""),
resource.TestCheckResourceAttr("auth0_connection.google_apps", "options.0.domain", "example.com"),
resource.TestCheckResourceAttr("auth0_connection.google_apps", "options.0.tenant_domain", "example.com"),
resource.TestCheckResourceAttr("auth0_connection.google_apps", "options.0.domain_aliases.#", "2"),
resource.TestCheckResourceAttr("auth0_connection.google_apps", "options.0.domain_aliases.3506632655", "example.com"),
resource.TestCheckResourceAttr("auth0_connection.google_apps", "options.0.domain_aliases.3154807651", "api.example.com"),
resource.TestCheckResourceAttr("auth0_connection.google_apps", "options.0.api_enable_users", "true"),
resource.TestCheckResourceAttr("auth0_connection.google_apps", "options.0.scopes.#", "2"),
resource.TestCheckResourceAttr("auth0_connection.google_apps", "options.0.scopes.1268340351", "ext_profile"),
resource.TestCheckResourceAttr("auth0_connection.google_apps", "options.0.scopes.541325467", "ext_groups"),
),
},
},
})
}

const testAccConnectionGoogleApps = `
resource "auth0_connection" "google_apps" {
name = "Acceptance-Test-Google-Apps-{{.random}}"
is_domain_connection = false
strategy = "google-apps"
options {
client_id = ""
client_secret = ""
domain = "example.com"
tenant_domain = "example.com"
domain_aliases = [ "example.com", "api.example.com" ]
api_enable_users = true
scopes = [ "ext_profile", "ext_groups" ]
}
}
`

func TestAccConnectionFacebook(t *testing.T) {

rand := random.String(6)
Expand Down
39 changes: 39 additions & 0 deletions auth0/structure_auth0_connection.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ func flattenConnectionOptions(d ResourceData, options interface{}) []interface{}
m = flattenConnectionOptionsAuth0(d, o)
case *management.ConnectionOptionsGoogleOAuth2:
m = flattenConnectionOptionsGoogleOAuth2(o)
case *management.ConnectionOptionsGoogleApps:
m = flattenConnectionOptionsGoogleApps(o)
case *management.ConnectionOptionsOAuth2:
m = flattenConnectionOptionsOAuth2(o)
case *management.ConnectionOptionsFacebook:
Expand Down Expand Up @@ -99,6 +101,21 @@ func flattenConnectionOptionsGoogleOAuth2(o *management.ConnectionOptionsGoogleO
}
}

func flattenConnectionOptionsGoogleApps(o *management.ConnectionOptionsGoogleApps) interface{} {
return map[string]interface{}{
"client_id": o.GetClientID(),
"client_secret": o.GetClientSecret(),
"domain": o.GetDomain(),
"tenant_domain": o.GetTenantDomain(),
"api_enable_users": o.GetEnableUsersAPI(),
"scopes": o.Scopes(),
"set_user_root_attributes": o.GetSetUserAttributes(),
"non_persistent_attrs": o.GetNonPersistentAttrs(),
"domain_aliases": o.DomainAliases,
"icon_url": o.GetLogoURL(),
}
}

func flattenConnectionOptionsOAuth2(o *management.ConnectionOptionsOAuth2) interface{} {
return map[string]interface{}{
"client_id": o.GetClientID(),
Expand Down Expand Up @@ -295,6 +312,8 @@ func expandConnection(d ResourceData) *management.Connection {
c.Options = expandConnectionOptionsAuth0(d)
case management.ConnectionStrategyGoogleOAuth2:
c.Options = expandConnectionOptionsGoogleOAuth2(d)
case management.ConnectionStrategyGoogleApps:
c.Options = expandConnectionOptionsGoogleApps(d)
case management.ConnectionStrategyOAuth2:
c.Options = expandConnectionOptionsOAuth2(d)
case management.ConnectionStrategyFacebook:
Expand Down Expand Up @@ -417,6 +436,26 @@ func expandConnectionOptionsGoogleOAuth2(d ResourceData) *management.ConnectionO

return o
}

func expandConnectionOptionsGoogleApps(d ResourceData) *management.ConnectionOptionsGoogleApps {

o := &management.ConnectionOptionsGoogleApps{
ClientID: String(d, "client_id"),
ClientSecret: String(d, "client_secret"),
Domain: String(d, "domain"),
TenantDomain: String(d, "tenant_domain"),
EnableUsersAPI: Bool(d, "api_enable_users"),
SetUserAttributes: String(d, "set_user_root_attributes"),
NonPersistentAttrs: castToListOfStrings(Set(d, "non_persistent_attrs").List()),
DomainAliases: Set(d, "domain_aliases").List(),
LogoURL: String(d, "icon_url"),
}

expandConnectionOptionsScopes(d, o)

return o
}

func expandConnectionOptionsOAuth2(d ResourceData) *management.ConnectionOptionsOAuth2 {

o := &management.ConnectionOptionsOAuth2{
Expand Down

0 comments on commit f0f0fd1

Please sign in to comment.