Skip to content

Commit 0ed82d2

Browse files
author
Yvo
authored
Merge pull request go-auth0#221 from mattoddie/feature/google-apps-scopes
Add scope getter/setter to google-apps connection options
2 parents ac7d362 + b7024f3 commit 0ed82d2

File tree

3 files changed

+84
-0
lines changed

3 files changed

+84
-0
lines changed

management/connection.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -711,6 +711,7 @@ type ConnectionOptionsGoogleApps struct {
711711
ClientID *string `json:"client_id,omitempty"`
712712
ClientSecret *string `json:"client_secret,omitempty"`
713713
Domain *string `json:"domain,omitempty"`
714+
TenantDomain *string `json:"tenant_domain,omitempty"`
714715

715716
EnableUsersAPI *bool `json:"api_enable_users,omitempty"`
716717
BasicProfile *bool `json:"basic_profile,omitempty" scope:"basic_profile"`
@@ -727,6 +728,14 @@ type ConnectionOptionsGoogleApps struct {
727728
LogoURL *string `json:"icon_url,omitempty"`
728729
}
729730

731+
func (c *ConnectionOptionsGoogleApps) Scopes() []string {
732+
return tag.Scopes(c)
733+
}
734+
735+
func (c *ConnectionOptionsGoogleApps) SetScopes(enable bool, scopes ...string) {
736+
tag.SetScopes(c, enable, scopes...)
737+
}
738+
730739
type ConnectionManager struct {
731740
*Management
732741
}

management/connection_test.go

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,7 @@ func TestConnection(t *testing.T) {
153153
t.Logf("%v\n", cs)
154154
})
155155
}
156+
156157
func TestConnectionOptions(t *testing.T) {
157158

158159
t.Run("GoogleOAuth2", func(t *testing.T) {
@@ -222,6 +223,72 @@ func TestConnectionOptions(t *testing.T) {
222223
t.Logf("%s\n", g)
223224
})
224225

226+
t.Run("GoogleApps", func(t *testing.T) {
227+
g := &Connection{
228+
Name: auth0.Stringf("Test-Connection-%d", time.Now().Unix()),
229+
Strategy: auth0.String("google-apps"),
230+
Options: &ConnectionOptionsGoogleApps{
231+
Domain: auth0.String("example.com"),
232+
TenantDomain: auth0.String("example.com"),
233+
BasicProfile: auth0.Bool(true),
234+
ExtendedProfile: auth0.Bool(true),
235+
Groups: auth0.Bool(true),
236+
},
237+
}
238+
239+
defer func() {
240+
m.Connection.Delete(g.GetID())
241+
assertDeleted(t, g)
242+
243+
}()
244+
245+
err := m.Connection.Create(g)
246+
if err != nil {
247+
t.Fatal(err)
248+
}
249+
c, err := m.Connection.Read(g.GetID())
250+
if err != nil {
251+
t.Fatal(err)
252+
}
253+
o, ok := c.Options.(*ConnectionOptionsGoogleApps)
254+
if !ok {
255+
t.Fatalf("unexpected type %T", o)
256+
}
257+
expect.Expect(t, o.GetBasicProfile(), true)
258+
expect.Expect(t, o.GetExtendedProfile(), true)
259+
expect.Expect(t, o.GetGroups(), true)
260+
expect.Expect(t, o.GetAdmin(), false)
261+
expect.Expect(t, o.Scopes(), []string{"basic_profile", "ext_profile", "ext_groups"})
262+
263+
o.NonPersistentAttrs = &[]string{"gender", "ethnicity", "favorite_color"}
264+
err = m.Connection.Update(g.GetID(), &Connection{
265+
Options: o,
266+
})
267+
if err != nil {
268+
t.Fatal(err)
269+
}
270+
c, _ = m.Connection.Read(g.GetID())
271+
o, ok = c.Options.(*ConnectionOptionsGoogleApps)
272+
expect.Expect(t, o.GetNonPersistentAttrs(), []string{"gender", "ethnicity", "favorite_color"})
273+
274+
o.NonPersistentAttrs = &[]string{""}
275+
err = m.Connection.Update(g.GetID(), &Connection{
276+
Options: o,
277+
})
278+
if err != nil {
279+
log.Fatal(err)
280+
}
281+
282+
c, err = m.Connection.Read(g.GetID())
283+
if err != nil {
284+
log.Fatal(err)
285+
}
286+
o, ok = c.Options.(*ConnectionOptionsGoogleApps)
287+
expect.Expect(t, o.GetNonPersistentAttrs(), []string{""})
288+
289+
t.Logf("%s\n", g)
290+
})
291+
225292
t.Run("OIDC", func(t *testing.T) {
226293
o := &ConnectionOptionsOIDC{}
227294
expect.Expect(t, len(o.Scopes()), 0)

management/management.gen.go

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)