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 CreateIdentityProviderMapper call #268

Merged
merged 2 commits into from
Mar 27, 2021
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
11 changes: 11 additions & 0 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -2305,6 +2305,17 @@ func (client *gocloak) DeleteIdentityProvider(ctx context.Context, token, realm,
return checkForError(resp, err, errMessage)
}

// CreateIdentityProviderMapper creates an instance of an identity provider mapper associated with the given alias
func (client *gocloak) CreateIdentityProviderMapper(ctx context.Context, token, realm, alias string, mapper IdentityProviderMapper) error {
const errMessage = "could not create mapper for identity provider"

resp, err := client.getRequestWithBearerAuth(ctx, token).
SetBody(mapper).
Post(client.getAdminRealmURL(realm, "identity-provider", "instances", alias, "mappers"))

return checkForError(resp, err, errMessage)
}

// ------------------
// Protection API
// ------------------
Expand Down
18 changes: 18 additions & 0 deletions client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3819,6 +3819,24 @@ func TestGocloak_CreateGetDeleteUserFederatedIdentity(t *testing.T) {
require.NoError(t, err)
require.Equal(t, idp, res)

err = client.CreateIdentityProviderMapper(
context.Background(),
token.AccessToken,
cfg.GoCloak.Realm,
"google",
gocloak.IdentityProviderMapper{
Name: gocloak.StringP("add-google-origin-attribute"),
IdentityProviderMapper: gocloak.StringP("hardcoded-attribute-idp-mapper"),
IdentityProviderAlias: gocloak.StringP("google"),
Config: &map[string]string{
"syncMode": "INHERIT",
"attribute": "origin",
"attribute.value": "google",
},
},
)
require.NoError(t, err)

defer func() {
err = client.DeleteIdentityProvider(
context.Background(),
Expand Down
2 changes: 2 additions & 0 deletions gocloak.go
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,8 @@ type GoCloak interface {
UpdateIdentityProvider(ctx context.Context, token, realm, alias string, providerRep IdentityProviderRepresentation) error
// DeleteIdentityProvider deletes the identity provider in a realm
DeleteIdentityProvider(ctx context.Context, token, realm, alias string) error
// CreateIdentityProviderMapper creates an instance of an identity provider mapper associated with the given alias
CreateIdentityProviderMapper(ctx context.Context, token, realm, alias string, mapper IdentityProviderMapper) error

// *** Protection API ***
// GetResource returns a client's resource with the given id, using access token from client
Expand Down
9 changes: 9 additions & 0 deletions models.go
Original file line number Diff line number Diff line change
Expand Up @@ -899,6 +899,15 @@ type IdentityProviderRepresentation struct {
TrustEmail *bool `json:"trustEmail,omitempty"`
}

// IdentityProviderMapper represents the body of a call to add a mapper to
// an identity provider
type IdentityProviderMapper struct {
Name *string `json:"name,omitempty"`
IdentityProviderMapper *string `json:"identityProviderMapper,omitempty"`
IdentityProviderAlias *string `json:"identityProviderAlias,omitempty"`
Config *map[string]string `json:"config"`
}

// GetResourceParams represents the optional parameters for getting resources
type GetResourceParams struct {
Deep *bool `json:"deep,string,omitempty"`
Expand Down