keycloak-nodejs-admin-client icon indicating copy to clipboard operation
keycloak-nodejs-admin-client copied to clipboard

BaseUrl isn't getting used

Open stevehogdahl opened this issue 4 years ago • 6 comments

I'm getting the following error when calling the auth function: ERROR Invoke Error { "errorType": "Error", "errorMessage": "connect ECONNREFUSED 127.0.0.1:8080", "trace": [ "Error: connect ECONNREFUSED 127.0.0.1:8080", " at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1107:14)" ] }

It looks like it's trying to hit the default baseUrl even though i passed in a new baseUrl. Code is below:

const KeycloakAdminClient = require('keycloak-admin').default;

const settings = {
	baseUrl   : config.KeycloakBaseLocation,
	username  : config.KeycloakUsername,
	password  : config.KeycloakPassword,
	grant_type: 'password',
	client_id : 'admin-cli',
	realmName : config.KeycloakRealm
}

const client = new KeycloakAdminClient();
await client.auth(settings);

stevehogdahl avatar May 23 '20 12:05 stevehogdahl

I'm getting the same error while using keycloak/keycloak-nodejs-connect, so your issue might be caused by something else

Kinrany avatar May 25 '20 17:05 Kinrany

In my case I was trying to write a test with request(app).get("some/route"). The route must start with a /.

Kinrany avatar May 25 '20 18:05 Kinrany

Same error

manuserranog avatar May 26 '20 08:05 manuserranog

I think example in readme is wrong realm should be in the auth settings and baseUrl in the options for client constructor

@stevehogdahl try below it works for me

const KeycloakAdminClient = require('keycloak-admin').default;

const settings = {
  username  : config.KeycloakUsername,
  password  : config.KeycloakPassword,
  grant_type: 'password',
  client_id : 'admin-cli',
  realmName : config.KeycloakRealm
}

const client = new KeycloakAdminClient( {
  baseUrl: config.KeycloakBaseLocation,
});

await client.auth(settings);

patrykwegrzyn avatar Jun 01 '20 21:06 patrykwegrzyn

@patrykwegrzyn thank you, I'll give that a try.

stevehogdahl avatar Jun 02 '20 22:06 stevehogdahl

I think example in readme is wrong realm should be in the auth settings and baseUrl in the options for client constructor

@stevehogdahl try below it works for me

const KeycloakAdminClient = require('keycloak-admin').default;

const settings = {
  username  : config.KeycloakUsername,
  password  : config.KeycloakPassword,
  grant_type: 'password',
  client_id : 'admin-cli',
  realmName : config.KeycloakRealm
}

const client = new KeycloakAdminClient( {
  baseUrl: config.KeycloakBaseLocation,
});

await client.auth(settings);

No. The REAME is correct, In your case maybe you were using the wrong "realm" and by not putting "realmName" in "KeycloakAdminClient" the library put you the realm "master"

itsalb3rt avatar Oct 19 '20 18:10 itsalb3rt