Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add support for resource server settings endpoint #421

Merged
merged 3 commits into from
May 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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