Repository: Nerzal/gocloak
Pull request #93 (2019-09-18 14:04:53)

Added some extra fields to ProtocolMappersConfig
Added the fields
* Multivalued
* UsermodelClientRoleMappingClientID
* IncludedClientAudience

Tested locally against keycloak v6.0.1


Patch:
diff --git a/models.go b/models.go
index adafdb5..5a5e67c 100644
--- a/models.go
+++ b/models.go
@@ -255,13 +255,16 @@ type ProtocolMappers struct {
 
 // ProtocolMappersConfig is a config of a protocol mapper
 type ProtocolMappersConfig struct {
-	UserinfoTokenClaim string `json:"userinfo.token.claim,omitempty"`
-	UserAttribute      string `json:"user.attribute,omitempty"`
-	IDTokenClaim       string `json:"id.token.claim,omitempty"`
-	AccessTokenClaim   string `json:"access.token.claim,omitempty"`
-	ClaimName          string `json:"claim.name,omitempty"`
-	ClaimValue         string `json:"claim.value,omitempty"`
-	JSONTypeLabel      string `json:"jsonType.label,omitempty"`
+	UserinfoTokenClaim                 string `json:"userinfo.token.claim,omitempty"`
+	UserAttribute                      string `json:"user.attribute,omitempty"`
+	IDTokenClaim                       string `json:"id.token.claim,omitempty"`
+	AccessTokenClaim                   string `json:"access.token.claim,omitempty"`
+	ClaimName                          string `json:"claim.name,omitempty"`
+	ClaimValue                         string `json:"claim.value,omitempty"`
+	JSONTypeLabel                      string `json:"jsonType.label,omitempty"`
+	Multivalued                        string `json:"multivalued,omitempty"`
+	UsermodelClientRoleMappingClientID string `json:"usermodel.clientRoleMapping.clientId,omitempty"`
+	IncludedClientAudience             string `json:"included.client.audience,omitempty"`
 }
 
 // Client is a ClientRepresentation


Test patch:
diff --git a/client_test.go b/client_test.go
index 387531b..15eaa04 100644
--- a/client_test.go
+++ b/client_test.go
@@ -1944,3 +1944,71 @@ func TestGoCloak_ClientServiceAccount(t *testing.T) {
 	AssertNotEquals(t, gocloakClientID, serviceAccount.ID)
 	AssertEquals(t, "service-account-gocloak", serviceAccount.Username)
 }
+
+func TestGocloak_CreateDeleteClientScopeWithMappers(t *testing.T) {
+	t.Parallel()
+	cfg := GetConfig(t)
+	client := NewClientWithDebug(t)
+	token := GetAdminToken(t, client)
+	id := "ed2d7d24-2703-430d-9cac-0954e41ff809"
+	rolemapperID := "5e3b5207-f84f-484e-8ceb-695dd3e3c532"
+	audiencemapperID := "abef1b33-43c0-4547-ad86-25f7824a83e8"
+	err := client.CreateClientScope(
+		token.AccessToken,
+		cfg.GoCloak.Realm,
+		ClientScope{
+			ID:          id,
+			Name:        "test-scope",
+			Description: "testing scope",
+			Protocol:    "openid-connect",
+			ClientScopeAttributes: &ClientScopeAttributes{
+				ConsentScreenText:      "false",
+				DisplayOnConsentScreen: "true",
+				IncludeInTokenScope:    "false",
+			},
+			ProtocolMappers: []ProtocolMappers{
+				{
+					ID:              rolemapperID,
+					Name:            "roles",
+					Protocol:        "openid-connect",
+					ProtocolMapper:  "oidc-usermodel-client-role-mapper",
+					ConsentRequired: false,
+					ProtocolMappersConfig: ProtocolMappersConfig{
+						UserinfoTokenClaim:                 "false",
+						AccessTokenClaim:                   "true",
+						IDTokenClaim:                       "true",
+						ClaimName:                          "test",
+						Multivalued:                        "true",
+						UsermodelClientRoleMappingClientID: "test",
+					},
+				},
+				{
+					ID:              audiencemapperID,
+					Name:            "audience",
+					Protocol:        "openid-connect",
+					ProtocolMapper:  "oidc-audience-mapper",
+					ConsentRequired: false,
+					ProtocolMappersConfig: ProtocolMappersConfig{
+						UserinfoTokenClaim:     "false",
+						IDTokenClaim:           "true",
+						AccessTokenClaim:       "true",
+						IncludedClientAudience: "test",
+					},
+				},
+			},
+		},
+	)
+	FailIfErr(t, err, "CreateClientScope failed")
+	clientScopeActual, err := client.GetClientScope(token.AccessToken, cfg.GoCloak.Realm, id)
+
+	FailIf(t, clientScopeActual == nil, "client scope has not been created")
+	FailIf(t, len(clientScopeActual.ProtocolMappers) != 2, "unexpected number of protocol mappers created")
+	err = client.DeleteClientScope(
+		token.AccessToken,
+		cfg.GoCloak.Realm,
+		id,
+	)
+	FailIfErr(t, err, "DeleteClientProtocolMapper failed")
+	clientScopeActual, err = client.GetClientScope(token.AccessToken, cfg.GoCloak.Realm, id)
+	FailIf(t, clientScopeActual != nil, "client scope has not been deleted")
+}