Skip to content

Commit

Permalink
Added client-grants and resource-servers api changes
Browse files Browse the repository at this point in the history
  • Loading branch information
duedares-rvj committed Aug 13, 2024
1 parent a1a9f65 commit d94706d
Show file tree
Hide file tree
Showing 5 changed files with 124 additions and 0 deletions.
8 changes: 8 additions & 0 deletions management/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,14 @@ type Client struct {

// URLs that are valid to call back from Auth0 for OIDC logout.
OIDCLogout *OIDCLogout `json:"oidc_logout,omitempty"`

DefaultOrganization *DefaultOrganization `json:"default_organization,omitempty"`
}

// DefaultOrganization allows the support for client credentials feature.
type DefaultOrganization struct {
Flows *[]string `json:"flows,omitempty"`
OrganizationID *string `json:"organization_id,omitempty"`
}

// ClientJWTConfiguration is used to configure JWT settings for our Client.
Expand Down
29 changes: 29 additions & 0 deletions management/management.gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

35 changes: 35 additions & 0 deletions management/management.gen_test.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

42 changes: 42 additions & 0 deletions management/organization_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -474,6 +474,48 @@ func TestOrganizationManager_ClientGrants(t *testing.T) {
assert.Len(t, associatedGrants.ClientGrants, 0)
}

func TestOrganizationManager_ClientGrantsWithOrg(t *testing.T) {
configureHTTPTestRecordings(t)

org := givenAnOrganization(t)
resourceServer := givenAResourceServer(t)

client := givenAClient(t)
client.DefaultOrganization = &DefaultOrganization{
&[]string{"client_credentials"},
auth0.String(org.GetID()),
}

clientGrant := &ClientGrant{
ClientID: client.ClientID,
Audience: resourceServer.Identifier,
Scope: &[]string{"create:resource", "create:organization_client_grants"},
AllowAnyOrganization: auth0.Bool(true),
OrganizationUsage: auth0.String("allow"),
}

err := api.ClientGrant.Create(context.Background(), clientGrant)
require.NoError(t, err)
t.Cleanup(func() {
cleanupClientGrant(t, clientGrant.GetID())
})

err = api.Organization.AssociateClientGrant(context.Background(), org.GetID(), clientGrant.GetID())
require.NoError(t, err)

associatedGrants, err := api.Organization.ClientGrants(context.Background(), org.GetID(), Parameter("grant_ids", clientGrant.GetID()))
require.NoError(t, err)
assert.Len(t, associatedGrants.ClientGrants, 1)
assert.Equal(t, clientGrant.GetID(), associatedGrants.ClientGrants[0].GetID())

err = api.Organization.RemoveClientGrant(context.Background(), org.GetID(), clientGrant.GetID())
require.NoError(t, err)

associatedGrants, err = api.Organization.ClientGrants(context.Background(), org.GetID())
require.NoError(t, err)
assert.Len(t, associatedGrants.ClientGrants, 0)
}

func givenAnOrganization(t *testing.T) *Organization {
org := &Organization{
Name: auth0.String(fmt.Sprintf("test-organization%v", rand.Intn(999))),
Expand Down
10 changes: 10 additions & 0 deletions management/resource_server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -208,12 +208,22 @@ func givenAResourceServer(t *testing.T) *ResourceServer {
Value: auth0.String("create:resource"),
Description: auth0.String("Create Resource"),
},
{
Value: auth0.String("create:organization_client_grants"),
Description: auth0.String("Create Org Client Grants"),
},
},
}

err := api.ResourceServer.Create(context.Background(), resourceServer)
require.NoError(t, err)

resourceServerList, err := api.ResourceServer.List(context.Background(), Parameter("identifiers", resourceServer.GetIdentifier()))
require.NoError(t, err)
assert.NotEqual(t, len(resourceServerList.ResourceServers), 0)

assert.Equal(t, resourceServerList.ResourceServers[0].GetIdentifier(), resourceServer.GetIdentifier())

t.Cleanup(func() {
cleanupResourceServer(t, resourceServer.GetID())
})
Expand Down

0 comments on commit d94706d

Please sign in to comment.