Skip to content

Commit

Permalink
Added condition for fetching roles having forward slash(/) in its name
Browse files Browse the repository at this point in the history
  • Loading branch information
shubham-mathur committed Nov 16, 2019
1 parent 6c14219 commit 104edc9
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions keycloak/role.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package keycloak
import (
"fmt"
"log"
"strings"
)

type Role struct {
Expand Down Expand Up @@ -43,7 +44,9 @@ func (keycloakClient *KeycloakClient) CreateRole(role *Role) error {
}

var createdRole Role
err = keycloakClient.get(fmt.Sprintf("%s/%s", url, role.Name), &createdRole, nil)
var roleName = strings.Replace(role.Name, "/", "%2F", -2)

err = keycloakClient.get(fmt.Sprintf("%s/%s", url, roleName), &createdRole, nil)
if err != nil {
return err
}
Expand All @@ -55,7 +58,6 @@ func (keycloakClient *KeycloakClient) CreateRole(role *Role) error {

func (keycloakClient *KeycloakClient) GetRole(realmId, id string) (*Role, error) {
var role Role

err := keycloakClient.get(fmt.Sprintf("/realms/%s/roles-by-id/%s", realmId, id), &role, nil)
if err != nil {
return nil, err
Expand All @@ -72,8 +74,9 @@ 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)

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

0 comments on commit 104edc9

Please sign in to comment.