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 );
}
}
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 );
};
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 ID
this.realm = config['realm'] || config.realm;
Client/Application ID
this.clientId = config['resource'] || config.clientId;
Client/Application secret
this.secret = (config['credentials'] || {}).secret || config.secret;
If this is a public application or confidential.
this.public = config['public-client'] || config.public || false;
Authentication server URL
this.authServerUrl = config['auth-server-url'] || config.authServerUrl;
Root realm URL.
this.realmUrl = this.authServerUrl + '/realms/' + this.realm;
Root realm admin URL.
this.realmAdminUrl = this.authServerUrl + '/admin/realms/' + this.realm;
var plainKey = config['realm-public-key'];
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;