Skip to content

Commit

Permalink
update: add get organization
Browse files Browse the repository at this point in the history
update: get organization to list of organization

fix: organization id

fix: wrong endpoint

fix: typo json

update: add create organization
  • Loading branch information
Herdanis committed Dec 12, 2024
1 parent 77d3ec8 commit fb03ae6
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 2 deletions.
31 changes: 31 additions & 0 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -4507,3 +4507,34 @@ func (g *GoCloak) GetUsersManagementPermissions(ctx context.Context, accessToken

return &result, nil
}

// CreateOrganization creates a new Organization
func (g *GoCloak) CreateOrganization(ctx context.Context, token, realm string, organization Organization) (string, error) {
const errMessage = "could not create organization"

resp, err := g.GetRequestWithBearerAuth(ctx, token).
SetBody(organization).
Post(g.getAdminRealmURL(realm, "organizations"))

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

return getID(resp), nil
}

// GetOrganization returns a list of the organization
func (g *GoCloak) GetOrganization(ctx context.Context, token, realm string) ([]*Organization, error) {
const errMessage = "could not get organization"

var result []*Organization

resp, err := g.GetRequestWithBearerAuth(ctx, token).
SetResult(&result).
Get(g.getAdminRealmURL(realm, "organizations"))
if err := checkForError(resp, err, errMessage); err != nil {
return nil, err
}

return result, nil
}
23 changes: 21 additions & 2 deletions models.go
Original file line number Diff line number Diff line change
Expand Up @@ -934,8 +934,7 @@ func (p *AuthorizationParameters) FormData() map[string]string {
}

// AuthorizationResponse represents the response to an authorization request.
type AuthorizationResponse struct {
}
type AuthorizationResponse struct{}

// TokenOptions represents the options to obtain a token
type TokenOptions struct {
Expand Down Expand Up @@ -1455,6 +1454,24 @@ func prettyStringStruct(t interface{}) string {
return string(json)
}

type Domain struct {
Name *string `json:"name,omitempty"`
Verified *bool `json:"verified,omitempty"`
}

type Organization struct {
Id *string `json:"id,omitempty"`
Name *string `json:"name,omitempty"`
Alias *string `json:"alias,omitempty"`
Enable *bool `json:"enabled,omitempty"`
Description *string `json:"description,omitempty"`
RedirectUrl *string `json:"redirectUrl,omitempty"`
Attributes *map[string][]string `json:"attributes,omitempty"`
Domains *[]Domain `json:"domains,omitempty"`
Members *[]string `json:"members,omitempty"`
IdentityProviders *[]string `json:"identityProviders,omitempty"`
}

// Stringer implementations for all struct types
func (v *CertResponseKey) String() string { return prettyStringStruct(v) }
func (v *CertResponse) String() string { return prettyStringStruct(v) }
Expand Down Expand Up @@ -1539,3 +1556,5 @@ func (v *CredentialRepresentation) String() string { return pre
func (v *RequiredActionProviderRepresentation) String() string { return prettyStringStruct(v) }
func (v *BruteForceStatus) String() string { return prettyStringStruct(v) }
func (v *GetClientUserSessionsParams) String() string { return prettyStringStruct(v) }
func (v *Domain) String() string { return prettyStringStruct(v) }
func (v *Organization) String() string { return prettyStringStruct(v) }

0 comments on commit fb03ae6

Please sign in to comment.