keycloak-auth-utils

Config

constructor
Config()

Option name Type Description
config String,Object Configuration path or details.

Construct a configuration object.

A configuration object may be constructed with either
a path to a keycloak.json file (which defaults to
$PWD/keycloak.json if not present, or with a configuration
object akin to what parsing keycloak.json provides.

function Config(config) {
  if ( ! config ) {
    config = path.join( process.cwd(), 'keycloak.json' );
  }

  if ( typeof config == 'string' ) {
    this.loadConfiguration( config );
  } else {
    this.configure( config );
  }
}

loadConfiguration

method
Config.prototype.loadConfiguration()

Option name Type Description
configPath String Path to a `keycloak.json` configuration.

Load configuration from a path.

Config.prototype.loadConfiguration = function(configPath) {
  var json = fs.readFileSync( configPath );
  var config = JSON.parse( json.toString() );
  this.configure( config );
};

configure

method
Config.prototype.configure()

Option name Type Description
config Object The configuration to instill.

Configure this Config object.

This will set the internal configuration details. The details
may come from a keycloak.json formatted object (with names such
as auth-server-url) or from an existing Config object (using
names such as authServerUrl).

Config.prototype.configure = function(config) {

realm

property
this.realm

Realm ID

this.realm          = config['realm']                      || config.realm;

clientId

property
this.clientId

Client/Application ID

this.clientId       = config['resource']                   || config.clientId;

secret

property
this.secret

Client/Application secret

this.secret         = (config['credentials'] || {}).secret || config.secret;

public

property
this.public

If this is a public application or confidential.

this.public         = config['public-client'] || config.public || false;

authServerUrl

property
this.authServerUrl

Authentication server URL

this.authServerUrl  = config['auth-server-url']            || config.authServerUrl;

realmUrl

property
this.realmUrl

Root realm URL.

this.realmUrl      = this.authServerUrl + '/realms/' + this.realm;

realmAdminUrl

property
this.realmAdminUrl

Root realm admin URL.

this.realmAdminUrl = this.authServerUrl + '/admin/realms/' + this.realm;

var plainKey = config['realm-public-key'];

publicKey

property
this.publicKey

Formatted public-key.

this.publicKey = "-----BEGIN PUBLIC KEY-----\n";

for ( i = 0 ; i < plainKey.length ; i = i + 64 ) {
  this.publicKey += plainKey.substring( i, i + 64 );
  this.publicKey += "\n";
}

this.publicKey += "-----END PUBLIC KEY-----\n";
};

module.exports = Config;