Skip to content

Commit

Permalink
feat: add support for resource server settings endpoint (#421)
Browse files Browse the repository at this point in the history
* feat: add support for resource server settings endpoint

* fix: endpoint URL

* test: add unit test
  • Loading branch information
Ullaakut authored May 4, 2023
1 parent 70f6ad9 commit 640934d
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 0 deletions.
18 changes: 18 additions & 0 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -3154,6 +3154,24 @@ func (g *GoCloak) GetResourcesClient(ctx context.Context, token, realm string, p
return result, nil
}

// GetResourceServer returns resource server settings.
// The access token must have the realm view_clients role on its service
// account to be allowed to call this endpoint.
func (g *GoCloak) GetResourceServer(ctx context.Context, token, realm, idOfClient string) (*ResourceServerRepresentation, error) {
const errMessage = "could not get resource server settings"

var result *ResourceServerRepresentation
resp, err := g.GetRequestWithBearerAuth(ctx, token).
SetResult(&result).
Get(g.getAdminRealmURL(realm, "clients", idOfClient, "authz", "resource-server", "settings"))

if err := checkForError(resp, err, errMessage); err != nil {
return nil, err
}

return result, nil
}

// UpdateResource updates a resource associated with the client, using access token from admin
func (g *GoCloak) UpdateResource(ctx context.Context, token, realm, idOfClient string, resource ResourceRepresentation) error {
const errMessage = "could not update resource"
Expand Down
17 changes: 17 additions & 0 deletions client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4986,6 +4986,23 @@ func Test_CreateListGetUpdateDeleteResourceClient(t *testing.T) {
require.Equal(t, *(createdResource.Name), *(updatedResource.Name))
}

func Test_GetResourceServer(t *testing.T) {
t.Parallel()
cfg := GetConfig(t)
client := NewClientWithDebug(t)
token := GetAdminToken(t, client)

rs, err := client.GetResourceServer(
context.Background(),
token.AccessToken,
cfg.GoCloak.Realm,
gocloakClientID,
)
require.NoError(t, err, "GetResourceServer failed")
require.NotNil(t, rs)
t.Logf("Resource server settings: %+v", rs)
}

func Test_CreateListGetUpdateDeleteResource(t *testing.T) {
t.Parallel()
cfg := GetConfig(t)
Expand Down

0 comments on commit 640934d

Please sign in to comment.