Home > other >  Keycloak Admin client, 405 DELETE METHOD NOT ALLOWED
Keycloak Admin client, 405 DELETE METHOD NOT ALLOWED

Time:10-18

I am implementing a nodejs backend to manage users in Keycloak and for this I am using the npm package keycloak-nodejs-admin-client.

Everything works fine but when I started to try to delete resources I got 405 DELETE METHOD NOT ALLOWED

        const adminClient = await initializeKeycloak()
        let mapper = await adminClient.clientScopes.findProtocolMapperByName({id: openIdScopeId, name: keycloakId})
        await adminClient.clientScopes.delProtocolMapper({id: openIdScopeId, name: mapper.name});
        await adminClient.clientScopes.delProtocolMapper({id: samlScopeId, name: mapper.name});
        

For example the findProtocolMapperByName Works fine but the Delete does not and returns 405 I already tried to make sure I am using the library correctly so I think must be a keycloak configuration This is how I configured the keycloak admin npm package:

        kcAdminClient.setConfig({
        realmName: 'master',
      });
    adminClient = await kcAdminClient.auth({
        username: 'admin',
        password: 'dummy',
        grantType: 'password',
        clientId:'admin-cli',
    });

    kcAdminClient.setConfig({
        realmName: dummy,
      });

the fact that I configure two realms is not affecting as this issue was happening before and I tried to use a user from Master realm to perform the request.

There is no information direct information on keycloak/http method and I think many a clarification of this can help lots of people, thanks!

CodePudding user response:

I have found the issue: On the keycloak-nodejs-admin-client there is little docs and a test file to test the methods, there they user the mapper name to make the delete, in reality you need using the mapperID.

  • Related