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

Admin SDK call urls wrong #161

Open
lobinhojr opened this issue Dec 4, 2024 · 4 comments
Open

Admin SDK call urls wrong #161

lobinhojr opened this issue Dec 4, 2024 · 4 comments

Comments

@lobinhojr
Copy link

I have the setup below and I am using keycloak 26

//My settings
"Keycloak": {
"realm": "myrealm-dev",
"auth-server-url": "http://localhost:8080",
"ssl-required": "none",
"verify-token-audience": false,
"resource": "myrealm-dev-api",
"credentials": {
"secret": ""
},
"confidential-port": 0
}

//On setup
var options = configuration.GetKeycloakOptions()!;

    services.AddDistributedMemoryCache();
    services
        .AddClientCredentialsTokenManagement()
        .AddClient(
            "Keycloak",
            client =>
            {
                client.ClientId = options.Resource;
                client.ClientSecret = options.Credentials.Secret;
                client.TokenEndpoint = options.KeycloakTokenEndpoint;
            }
        );
    
    services
       // TODO: hardcode settings used for force and try urls here on error analysis
      .AddKeycloakAdminHttpClient(new KeycloakAdminClientOptions 
        {
            AuthServerUrl = "http://localhost:8080",
            Realm = "myrealm-dev",
            Resource = "myrealm-dev-api",
        })
        .AddClientCredentialsTokenHandler("Keycloak");

However, when I inject the IKeycloakUserClient on my class and call the method GetUser("myrealm-dev")
var users = await _keycloakUserClient.GetUsersWithResponseAsync("myrealm-dev");

The method return a response with 404 Status.
Analysing the problems and RequestMessage, I realized that url called is wrong
URL called =>
http://localhost:8080/realms/myrealm-dev/admin/realms/myrealm-dev/users

The correct endpoint should be "http://localhost:8080/admin/realms/myrealm-dev/users"

@NikiforovAll
Copy link
Owner

NikiforovAll commented Dec 5, 2024

What versions of packages do you use?

@lobinhojr
Copy link
Author

lobinhojr commented Dec 11, 2024

version 2.5.5.

For now, I used this workaround to replace url

services
.AddKeycloakAdminHttpClient(configuration, client =>
{
client.BaseAddress = new Uri($"{options.AuthServerUrl}/admin");
})
.AddClientCredentialsTokenHandler("Keycloak");

@anperim
Copy link

anperim commented Dec 13, 2024

Same problem. I was using version 2.5.3 and the problem is that /auth (old version of keycloak) was removed and doing the update to 2.5.5 the problem is exactly as described above.

@NikiforovAll
Copy link
Owner

NikiforovAll commented Dec 13, 2024

Yes, sorry, I've unlisted 2.5.5 for this very particular reason, please use 2.6.0

https://www.nuget.org/packages/Keycloak.AuthServices.Authentication

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants