Skip to content

Commit

Permalink
URL encode role name.
Browse files Browse the repository at this point in the history
  • Loading branch information
Cedric Thiebault committed Feb 5, 2020
1 parent 0690c34 commit b7261c1
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions keycloak/role.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package keycloak
import (
"fmt"
"log"
"strings"
"net/url"
)

type Role struct {
Expand Down Expand Up @@ -36,22 +36,22 @@ func roleByNameUrl(realmId, clientId string) string {
}

func (keycloakClient *KeycloakClient) CreateRole(role *Role) error {
url := roleByNameUrl(role.RealmId, role.ClientId)
roleUrl := roleByNameUrl(role.RealmId, role.ClientId)

if role.ClientId != "" {
role.ContainerId = role.ClientId
role.ClientRole = true
}

_, _, err := keycloakClient.post(url, role)
_, _, err := keycloakClient.post(roleUrl, role)
if err != nil {
return err
}

var createdRole Role
var roleName = strings.Replace(role.Name, "/", "%2F", -2)
var roleName = url.PathEscape(role.Name)

err = keycloakClient.get(fmt.Sprintf("%s/%s", url, roleName), &createdRole, nil)
err = keycloakClient.get(fmt.Sprintf("%s/%s", roleUrl, roleName), &createdRole, nil)
if err != nil {
return err
}
Expand Down Expand Up @@ -137,7 +137,7 @@ func (keycloakClient *KeycloakClient) GetRole(realmId, id string) (*Role, error)

func (keycloakClient *KeycloakClient) GetRoleByName(realmId, clientId, name string) (*Role, error) {
var role Role
var roleName = strings.Replace(name, "/", "%2F", -2)
var roleName = url.PathEscape(name)

err := keycloakClient.get(fmt.Sprintf("%s/%s", roleByNameUrl(realmId, clientId), roleName), &role, nil)
if err != nil {
Expand Down

0 comments on commit b7261c1

Please sign in to comment.