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

UpdatePolicy unknown_error #286

Open
mstrYoda opened this issue Jun 23, 2021 · 12 comments
Open

UpdatePolicy unknown_error #286

mstrYoda opened this issue Jun 23, 2021 · 12 comments
Labels
bug Something isn't working good first issue Good for newcomers

Comments

@mstrYoda
Copy link

mstrYoda commented Jun 23, 2021

Describe the bug
When I use the UpdatePolicy method, I got unknown_error. But when I change the url with debugging, add the path "/role" at the end of the policy path Put(client.getAdminRealmURL(realm, "clients", clientID, "authz", "resource-server", "policy", *(policy.ID))) I successfully updated the Policy.

When I check from the keycloak UI network, I see that keycloak sends update requests with policy type path. What I mean keycloak adds /role or /group at the end of the path. Gocloak does not include those paths.

To Reproduce
Send an update request for any policy.

Expected behavior
Update policy successfully.

Screenshots
Here is my code:

func (k Keycloak) DeleteRoleFromPolicy() {
	policies, err := k.client.GetPolicies(context.Background(), k.clientAdminJWTAccessToken ,k.realm,k.clientUID, gocloak.GetPolicyParams{
		Type: gocloak.StringP("role"),
		Name: gocloak.StringP("test-policy"),
	})
	if err != nil {
		fmt.Println(err)
	}
	policy := policies[0]

	for i, r := range *policy.Roles {
		role, _ := k.client.GetClientRoleByID(context.Background(), k.clientAdminJWTAccessToken, k.realm, *r.ID)
		if *role.Name == "test-role" {
			new := append((*policy.Roles)[:i], (*policy.Roles)[i+1:]...)
			policy.Roles = &new
			break
		}
	}

	err = k.client.UpdatePolicy(context.Background(), k.clientAdminJWTAccessToken, k.realm, k.clientUID, *policy)
	if err != nil {
		fmt.Println(err)
	}
}
@Nerzal Nerzal added bug Something isn't working good first issue Good for newcomers labels Aug 12, 2021
@dheeraj-326
Copy link

@Nerzal Is anyone else working on this that you are aware of?

@Nerzal
Copy link
Owner

Nerzal commented Feb 23, 2023

Hi, nope

@mstrYoda
Copy link
Author

Well, I can fix it if you okay with this?

@dheeraj-326
Copy link

dheeraj-326 commented Feb 24, 2023

@mstrYoda I would like to get started but not sure if I will be able to get to this soon because of work. I can pick the other "good first issue" if you are about to work on this.

@mstrYoda
Copy link
Author

@mstrYoda I would like to get started but not sure if I will be able to get to this soon because of work. I can pick the other "good first issue" if you are about to work on this.

If you would like to, you can contribute/collaborate on my PR, if you are not available soon, I can create a PR today or tomorrow.

@dheeraj-326
Copy link

@mstrYoda I would like to get started but not sure if I will be able to get to this soon because of work. I can pick the other "good first issue" if you are about to work on this.

If you would like to, you can contribute/collaborate on my PR, if you are not available soon, I can create a PR today or tomorrow.

Please go ahead. I might not make it today.

@dheeraj-326
Copy link

@mstrYoda If you haven't started this yet, I would like to do this as my first issue.

@mstrYoda
Copy link
Author

@mstrYoda If you haven't started this yet, I would like to do this as my first issue.

Hi, of course, you can implement it 🙏

@dheeraj-326
Copy link

@mstrYoda If you haven't started this yet, I would like to do this as my first issue.

Hi, of course, you can implement it 🙏

Thank you. I don't have a fix yet but will start understanding the issue once I do my dev setup for gocloak.

@dheeraj-326
Copy link

@Nerzal I think this is already fixed in #310.
image

@mstrYoda Can you please check if you are able to replicate the issue in the latest version? The UpdatePolicy tests are passing when I checked (ran all tests and all passed).
image

@mstrYoda
Copy link
Author

mstrYoda commented Mar 9, 2023

@Nerzal I think this is already fixed in #310. image

@mstrYoda Can you please check if you are able to replicate the issue in the latest version? The UpdatePolicy tests are passing when I checked (ran all tests and all passed). image

Yeap, seems like that 👍

@osamaadam
Copy link

osamaadam commented Apr 3, 2024

Hello just ran into this problem today for different reasons: On Keycloak 24.0, the /role segment is actually omitted so now I'm getting 500 when trying to get/create/update resources.

These routes work for me on 24.0:

GET /admin/realms/${REALM}/clients/${REALM_ID}/authz/resource-server/policy
POST /admin/realms/${REALM}/clients/${REALM_ID}/authz/resource-server/policy
PUT /admin/realms/${REALM}/clients/${REALM_ID}/authz/resource-server/policy

I don't know if there's a workaround to get the keycloak version and changing the URLs accordingly without adding too much complexity.

I'm on v13.9.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

4 participants