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

Add support for users-management-permissions get/put #463

Merged
merged 3 commits into from
Feb 1, 2024
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
36 changes: 35 additions & 1 deletion client.go
Original file line number Diff line number Diff line change
Expand Up @@ -508,7 +508,6 @@
if err := checkForError(resp, err, errMessage); err != nil {
return nil, err
}

return &res, nil
}

Expand Down Expand Up @@ -4304,3 +4303,38 @@

return checkForError(resp, err, errMessage)
}

// UpdateUsersManagementPermissions updates the management permissions for users
func (g *GoCloak) UpdateUsersManagementPermissions(ctx context.Context, accessToken, realm string, managementPermissions ManagementPermissionRepresentation) (*ManagementPermissionRepresentation, error) {
const errMessage = "could not update users management permissions"

Check warning on line 4309 in client.go

View check run for this annotation

Codecov / codecov/patch

client.go#L4309

Added line #L4309 was not covered by tests

var result ManagementPermissionRepresentation

Check warning on line 4311 in client.go

View check run for this annotation

Codecov / codecov/patch

client.go#L4311

Added line #L4311 was not covered by tests

resp, err := g.GetRequestWithBearerAuth(ctx, accessToken).
SetResult(&result).
SetBody(managementPermissions).
Put(g.getAdminRealmURL(realm, "users-management-permissions"))

Check warning on line 4316 in client.go

View check run for this annotation

Codecov / codecov/patch

client.go#L4313-L4316

Added lines #L4313 - L4316 were not covered by tests

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

Check warning on line 4319 in client.go

View check run for this annotation

Codecov / codecov/patch

client.go#L4318-L4319

Added lines #L4318 - L4319 were not covered by tests
}

return &result, nil

Check warning on line 4322 in client.go

View check run for this annotation

Codecov / codecov/patch

client.go#L4322

Added line #L4322 was not covered by tests
}

// GetUsersManagementPermissions returns the management permissions for users
func (g *GoCloak) GetUsersManagementPermissions(ctx context.Context, accessToken, realm string) (*ManagementPermissionRepresentation, error) {
const errMessage = "could not get users management permissions"

Check warning on line 4327 in client.go

View check run for this annotation

Codecov / codecov/patch

client.go#L4327

Added line #L4327 was not covered by tests

var result ManagementPermissionRepresentation

Check warning on line 4329 in client.go

View check run for this annotation

Codecov / codecov/patch

client.go#L4329

Added line #L4329 was not covered by tests

resp, err := g.GetRequestWithBearerAuth(ctx, accessToken).
SetResult(&result).
Get(g.getAdminRealmURL(realm, "users-management-permissions"))

Check warning on line 4333 in client.go

View check run for this annotation

Codecov / codecov/patch

client.go#L4331-L4333

Added lines #L4331 - L4333 were not covered by tests

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

Check warning on line 4336 in client.go

View check run for this annotation

Codecov / codecov/patch

client.go#L4335-L4336

Added lines #L4335 - L4336 were not covered by tests
}

return &result, nil

Check warning on line 4339 in client.go

View check run for this annotation

Codecov / codecov/patch

client.go#L4339

Added line #L4339 was not covered by tests
}
26 changes: 14 additions & 12 deletions models.go
Original file line number Diff line number Diff line change
Expand Up @@ -965,18 +965,20 @@ func (t *TokenOptions) FormData() map[string]string {

// RequestingPartyTokenOptions represents the options to obtain a requesting party token
type RequestingPartyTokenOptions struct {
GrantType *string `json:"grant_type,omitempty"`
Ticket *string `json:"ticket,omitempty"`
ClaimToken *string `json:"claim_token,omitempty"`
ClaimTokenFormat *string `json:"claim_token_format,omitempty"`
RPT *string `json:"rpt,omitempty"`
Permissions *[]string `json:"-"`
Audience *string `json:"audience,omitempty"`
ResponseIncludeResourceName *bool `json:"response_include_resource_name,string,omitempty"`
ResponsePermissionsLimit *uint32 `json:"response_permissions_limit,omitempty"`
SubmitRequest *bool `json:"submit_request,string,omitempty"`
ResponseMode *string `json:"response_mode,omitempty"`
SubjectToken *string `json:"subject_token,omitempty"`
GrantType *string `json:"grant_type,omitempty"`
Ticket *string `json:"ticket,omitempty"`
ClaimToken *string `json:"claim_token,omitempty"`
ClaimTokenFormat *string `json:"claim_token_format,omitempty"`
RPT *string `json:"rpt,omitempty"`
Permissions *[]string `json:"-"`
PermissionResourceFormat *string `json:"permission_resource_format,omitempty"`
PermissionResourceMatchingURI *bool `json:"permission_resource_matching_uri,string,omitempty"`
Audience *string `json:"audience,omitempty"`
ResponseIncludeResourceName *bool `json:"response_include_resource_name,string,omitempty"`
ResponsePermissionsLimit *uint32 `json:"response_permissions_limit,omitempty"`
SubmitRequest *bool `json:"submit_request,string,omitempty"`
ResponseMode *string `json:"response_mode,omitempty"`
SubjectToken *string `json:"subject_token,omitempty"`
}

// FormData returns a map of options to be used in SetFormData function
Expand Down
Loading