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

Commit 07b1412

Browse files
authored
Merge pull request #422 from mattoddie/feature/google-apps-connection-strategy
Add support for google-apps connection strategy options
2 parents 29fbde4 + f0f0fd1 commit 07b1412

File tree

2 files changed

+88
-0
lines changed

2 files changed

+88
-0
lines changed

auth0/resource_auth0_connection_test.go

+49
Original file line numberDiff line numberDiff line change
@@ -820,6 +820,55 @@ resource "auth0_connection" "google_oauth2" {
820820
}
821821
`
822822

823+
func TestAccConnectionGoogleApps(t *testing.T) {
824+
825+
rand := random.String(6)
826+
827+
resource.Test(t, resource.TestCase{
828+
Providers: map[string]terraform.ResourceProvider{
829+
"auth0": Provider(),
830+
},
831+
Steps: []resource.TestStep{
832+
{
833+
Config: random.Template(testAccConnectionGoogleApps, rand),
834+
Check: resource.ComposeTestCheckFunc(
835+
random.TestCheckResourceAttr("auth0_connection.google_apps", "name", "Acceptance-Test-Google-Apps-{{.random}}", rand),
836+
resource.TestCheckResourceAttr("auth0_connection.google_apps", "strategy", "google-apps"),
837+
resource.TestCheckResourceAttr("auth0_connection.google_apps", "options.0.client_id", ""),
838+
resource.TestCheckResourceAttr("auth0_connection.google_apps", "options.0.client_secret", ""),
839+
resource.TestCheckResourceAttr("auth0_connection.google_apps", "options.0.domain", "example.com"),
840+
resource.TestCheckResourceAttr("auth0_connection.google_apps", "options.0.tenant_domain", "example.com"),
841+
resource.TestCheckResourceAttr("auth0_connection.google_apps", "options.0.domain_aliases.#", "2"),
842+
resource.TestCheckResourceAttr("auth0_connection.google_apps", "options.0.domain_aliases.3506632655", "example.com"),
843+
resource.TestCheckResourceAttr("auth0_connection.google_apps", "options.0.domain_aliases.3154807651", "api.example.com"),
844+
resource.TestCheckResourceAttr("auth0_connection.google_apps", "options.0.api_enable_users", "true"),
845+
resource.TestCheckResourceAttr("auth0_connection.google_apps", "options.0.scopes.#", "2"),
846+
resource.TestCheckResourceAttr("auth0_connection.google_apps", "options.0.scopes.1268340351", "ext_profile"),
847+
resource.TestCheckResourceAttr("auth0_connection.google_apps", "options.0.scopes.541325467", "ext_groups"),
848+
),
849+
},
850+
},
851+
})
852+
}
853+
854+
const testAccConnectionGoogleApps = `
855+
856+
resource "auth0_connection" "google_apps" {
857+
name = "Acceptance-Test-Google-Apps-{{.random}}"
858+
is_domain_connection = false
859+
strategy = "google-apps"
860+
options {
861+
client_id = ""
862+
client_secret = ""
863+
domain = "example.com"
864+
tenant_domain = "example.com"
865+
domain_aliases = [ "example.com", "api.example.com" ]
866+
api_enable_users = true
867+
scopes = [ "ext_profile", "ext_groups" ]
868+
}
869+
}
870+
`
871+
823872
func TestAccConnectionFacebook(t *testing.T) {
824873

825874
rand := random.String(6)

auth0/structure_auth0_connection.go

+39
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ func flattenConnectionOptions(d ResourceData, options interface{}) []interface{}
1616
m = flattenConnectionOptionsAuth0(d, o)
1717
case *management.ConnectionOptionsGoogleOAuth2:
1818
m = flattenConnectionOptionsGoogleOAuth2(o)
19+
case *management.ConnectionOptionsGoogleApps:
20+
m = flattenConnectionOptionsGoogleApps(o)
1921
case *management.ConnectionOptionsOAuth2:
2022
m = flattenConnectionOptionsOAuth2(o)
2123
case *management.ConnectionOptionsFacebook:
@@ -101,6 +103,21 @@ func flattenConnectionOptionsGoogleOAuth2(o *management.ConnectionOptionsGoogleO
101103
}
102104
}
103105

106+
func flattenConnectionOptionsGoogleApps(o *management.ConnectionOptionsGoogleApps) interface{} {
107+
return map[string]interface{}{
108+
"client_id": o.GetClientID(),
109+
"client_secret": o.GetClientSecret(),
110+
"domain": o.GetDomain(),
111+
"tenant_domain": o.GetTenantDomain(),
112+
"api_enable_users": o.GetEnableUsersAPI(),
113+
"scopes": o.Scopes(),
114+
"set_user_root_attributes": o.GetSetUserAttributes(),
115+
"non_persistent_attrs": o.GetNonPersistentAttrs(),
116+
"domain_aliases": o.DomainAliases,
117+
"icon_url": o.GetLogoURL(),
118+
}
119+
}
120+
104121
func flattenConnectionOptionsOAuth2(o *management.ConnectionOptionsOAuth2) interface{} {
105122
return map[string]interface{}{
106123
"client_id": o.GetClientID(),
@@ -319,6 +336,8 @@ func expandConnection(d ResourceData) *management.Connection {
319336
c.Options = expandConnectionOptionsAuth0(d)
320337
case management.ConnectionStrategyGoogleOAuth2:
321338
c.Options = expandConnectionOptionsGoogleOAuth2(d)
339+
case management.ConnectionStrategyGoogleApps:
340+
c.Options = expandConnectionOptionsGoogleApps(d)
322341
case management.ConnectionStrategyOAuth2:
323342
c.Options = expandConnectionOptionsOAuth2(d)
324343
case management.ConnectionStrategyFacebook:
@@ -443,6 +462,26 @@ func expandConnectionOptionsGoogleOAuth2(d ResourceData) *management.ConnectionO
443462

444463
return o
445464
}
465+
466+
func expandConnectionOptionsGoogleApps(d ResourceData) *management.ConnectionOptionsGoogleApps {
467+
468+
o := &management.ConnectionOptionsGoogleApps{
469+
ClientID: String(d, "client_id"),
470+
ClientSecret: String(d, "client_secret"),
471+
Domain: String(d, "domain"),
472+
TenantDomain: String(d, "tenant_domain"),
473+
EnableUsersAPI: Bool(d, "api_enable_users"),
474+
SetUserAttributes: String(d, "set_user_root_attributes"),
475+
NonPersistentAttrs: castToListOfStrings(Set(d, "non_persistent_attrs").List()),
476+
DomainAliases: Set(d, "domain_aliases").List(),
477+
LogoURL: String(d, "icon_url"),
478+
}
479+
480+
expandConnectionOptionsScopes(d, o)
481+
482+
return o
483+
}
484+
446485
func expandConnectionOptionsOAuth2(d ResourceData) *management.ConnectionOptionsOAuth2 {
447486

448487
o := &management.ConnectionOptionsOAuth2{

0 commit comments

Comments
 (0)