Repository: Nerzal/gocloak
Pull request #231 (2020-11-24 12:12:42)

Added api to fetch role using role ID
- Added an API method to fetch role using role ID
- Fixed build failure because GitHub actions has removed set-env and add-path commands



Patch:
diff --git a/.github/workflows/go.yml b/.github/workflows/go.yml
index cd7ade2..0f8105b 100644
--- a/.github/workflows/go.yml
+++ b/.github/workflows/go.yml
@@ -7,15 +7,15 @@ jobs:
     runs-on: ubuntu-latest
     steps:
       - name: Install Go
-        uses: actions/setup-go@v2
+        uses: actions/setup-go@v2.1.3
         with:
           go-version: 1.15
       - name: Checkout code
         uses: actions/checkout@v2
       - name: Run golangci-lint
-        uses: golangci/golangci-lint-action@v1
+        uses: golangci/golangci-lint-action@v2.3.0
         with:
-          version: v1.27
+          version: v1.28.3
       - name: WriteGoList
         run: go list -json -m all > go.list
       - name: nancy
diff --git a/client.go b/client.go
index 1a2db02..31d4614 100644
--- a/client.go
+++ b/client.go
@@ -1363,6 +1363,22 @@ func (client *gocloak) GetClientRoles(ctx context.Context, token, realm, clientI
 	return result, nil
 }
 
+// GetClientRoleById gets role for the given client in realm using role ID
+func (client *gocloak) GetClientRoleByID(ctx context.Context, token, realm, roleID string) (*Role, error) {
+	const errMessage = "could not get client role"
+
+	var result Role
+	resp, err := client.getRequestWithBearerAuth(ctx, token).
+		SetResult(&result).
+		Get(client.getAdminRealmURL(realm, "roles-by-id", roleID))
+
+	if err := checkForError(resp, err, errMessage); err != nil {
+		return nil, err
+	}
+
+	return &result, nil
+}
+
 // GetRealmRolesByUserID returns all client roles assigned to the given user
 func (client *gocloak) GetClientRolesByUserID(ctx context.Context, token, realm, clientID, userID string) ([]*Role, error) {
 	const errMessage = "could not client roles by user id"
diff --git a/gocloak.go b/gocloak.go
index 48c5428..ee97ea2 100644
--- a/gocloak.go
+++ b/gocloak.go
@@ -226,6 +226,8 @@ type GoCloak interface {
 	DeleteClientRoleFromGroup(ctx context.Context, token, realm, clientID, groupID string, roles []Role) error
 	// GetClientRoles gets roles for the given client
 	GetClientRoles(ctx context.Context, accessToken, realm, clientID string) ([]*Role, error)
+	// GetClientRoleById gets role for the given client using role id
+	GetClientRoleByID(ctx context.Context, accessToken, realm, roleID string) (*Role, error)
 	// GetRealmRolesByUserID returns all client roles assigned to the given user
 	GetClientRolesByUserID(ctx context.Context, token, realm, clientID, userID string) ([]*Role, error)
 	// GetClientRolesByGroupID returns all client roles assigned to the given group


Test patch:
diff --git a/client_test.go b/client_test.go
index daf27b1..f884748 100644
--- a/client_test.go
+++ b/client_test.go
@@ -1070,6 +1070,16 @@ func TestGocloak_GetClientRole(t *testing.T) {
 	)
 	require.NoError(t, err, "GetClientRoleI failed")
 	require.NotNil(t, role)
+
+	role, err = client.GetClientRoleByID(
+		context.Background(),
+		token.AccessToken,
+		cfg.GoCloak.Realm,
+		*role.ID,
+	)
+	require.NoError(t, err, "GetClientRoleI failed")
+	require.NotNil(t, role)
+
 	token = GetAdminToken(t, client)
 	role, err = client.GetClientRole(
 		context.Background(),