Skip to content

Commit

Permalink
Merge pull request #2 from dlnilsson/main
Browse files Browse the repository at this point in the history
Add IdentityProviderToOrganization
  • Loading branch information
WilfredDube authored Feb 2, 2025
2 parents 466e9d5 + 8825095 commit 88f3b2a
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
16 changes: 16 additions & 0 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -4523,6 +4523,22 @@ func (g *GoCloak) CreateOrganization(ctx context.Context, token, realm string, o
return getID(resp), nil
}

// Adds the identity provider with the specified id to the organization
// POST /admin/realms/{realm}/organizations/{id}/identity-providers
func (g *GoCloak) AddIdentityProviderToOrganization(ctx context.Context, token, realm string, organizationID, identityProviderAlias string) error {
const errMessage = "could not add identity provider to organization"

resp, err := g.GetRequestWithBearerAuth(ctx, token).
SetBody(identityProviderAlias).
Post(g.getAdminRealmURL(realm, "organizations", organizationID, "identity-providers"))

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

return nil
}

// GetOrganizations returns a paginated list of organizations filtered according to the specified parameters
func (g *GoCloak) GetOrganizations(ctx context.Context, token, realm string, params GetOrganizationsParams) ([]*OrganizationRepresentation, error) {
const errMessage = "could not get organizations"
Expand Down
8 changes: 6 additions & 2 deletions models.go
Original file line number Diff line number Diff line change
Expand Up @@ -460,6 +460,8 @@ type ProtocolMappersConfig struct {
AttributeNameFormat *string `json:"attribute.nameformat,omitempty"`
Single *string `json:"single,omitempty"`
Script *string `json:"script,omitempty"`
AddOrganizationAttributes *string `json:"addOrganizationAttributes,omitempty"`
AddOrganizationId *string `json:"addOrganizationId,omitempty"`
}

// Client is a ClientRepresentation
Expand Down Expand Up @@ -735,6 +737,7 @@ type RolesRepresentation struct {
}

// RealmRepresentation represents a realm
// https://www.keycloak.org/docs-api/latest/rest-api/index.html#RealmRepresentation
type RealmRepresentation struct {
AccessCodeLifespan *int `json:"accessCodeLifespan,omitempty"`
AccessCodeLifespanLogin *int `json:"accessCodeLifespanLogin,omitempty"`
Expand Down Expand Up @@ -829,6 +832,7 @@ type RealmRepresentation struct {
UserFederationMappers *[]interface{} `json:"userFederationMappers,omitempty"`
UserFederationProviders *[]interface{} `json:"userFederationProviders,omitempty"`
UserManagedAccessAllowed *bool `json:"userManagedAccessAllowed,omitempty"`
OrganizationsEnabled *bool `json:"organizationsEnabled,omitempty"`
Users *[]User `json:"users,omitempty"`
VerifyEmail *bool `json:"verifyEmail,omitempty"`
WaitIncrementSeconds *int `json:"waitIncrementSeconds,omitempty"`
Expand Down Expand Up @@ -1501,8 +1505,8 @@ type OrganizationRepresentation struct {
RedirectURL *string `json:"redirectUrl,omitempty"`
Attributes *map[string][]string `json:"attributes,omitempty"`
Domains *[]OrganizationDomainRepresentation `json:"domains,omitempty"`
Members *[]string `json:"members,omitempty"`
IdentityProviders *[]string `json:"identityProviders,omitempty"`
Members *[]MemberRepresentation `json:"members,omitempty"`
IdentityProviders *[]IdentityProviderRepresentation `json:"identityProviders,omitempty"`
}

// prettyStringStruct returns struct formatted into pretty string
Expand Down

0 comments on commit 88f3b2a

Please sign in to comment.