First Discovery Server
The First Discovery Server acts as a web server for a First Discovery Editor instance and provides a means for storing preferences to the GPII Preferences Server. The First Discovery Server makes use of the Kettle configuration system for configuration and instantiation, but uses gpii-express rather than Kettle for expressing an HTTP server.
Access to the GPII Preferences Server is mediated by the GPII OAuth2 Security layer. The First Discovery Server communicates with the Security layer via the Client Credentials Grant workflow.
Configuration
The First Discovery Server can be configured via Kettle Configs. A set of these are provided with the server in the config directory. An integrator can choose to make use of the provided configs directly or use them as the basis for creating new configs.
The gpii.firstDiscovery.server.configurator
grade defines a default schema which the configuration is validated against. If the validation fails, the application will throw an error.
environment.json
environment.json accepts environment variables for all of the critical configuration options that are needed for running the First Discovery Server and connecting to the OAuth2 security server.
Environment Variable | Description |
---|---|
FIRST_DISCOVERY_SERVER_TCP_PORT
|
The port number that the First Discovery Server is hosted at.
Example: "8088"
Option Path:
|
GPII_OAUTH2_TCP_PORT
|
The port number that the GPII OAuth2 server is hosted at.
Example: "8081"
Option Path:
|
GPII_OAUTH2_HOST_NAME
|
The hostname that the GPII OAuth2 server is hosted at.
Example: "http://localhost"
Option Path:
|
GPII_OAUTH2_ACCESS_TOKEN_PATH
|
The path to the resource for requesting an access token.
Example: "/access_token"
Option Path:
|
GPII_OAUTH2_ADD_PREFERENCES_PATH
|
The path to the resource for creating a preference set.
A query parameter can be added to provide the view/ontology that the
preferences are to be stored in.
Example: "/add-preferences?view=%view"
Option Path:
|
GPII_OAUTH2_AUTH_GRANT_TYPE
|
The grant type supported by the OAuth2 server.
Example: "client_credentials"
Option Path:
|
GPII_OAUTH2_AUTH_SCOPE
|
The level of permissions that are being requested.
Example: "add_preferences"
Option Path:
|
GPII_OAUTH2_AUTH_CLIENT_ID
|
The client ID registered with the OAuth2 server.
Should be kept confidentially.
Example: "client_id_first_discovery"
Option Path:
|
GPII_OAUTH2_AUTH_CLIENT_SECRET
|
The client secret registered with the OAuth2 server.
Used to securely identify the client with the OAuth2.
Should be kept confidentially.
Example: "client_secret_first_discovery"
Option Path:
|
oauth2.json
oauth2.json merges on top of environment.json to replace the authentication related environment variables with concrete values for the Client Credentials Grant workflow.
Option Path | Description | Value |
---|---|---|
preferencesConfig.securityServer.paths.token
|
The path to the resource for requesting an access token. (see: GPII OAuth 2 Guide: Access Token) | "/access_token" |
preferencesConfig.securityServer.paths.preferences
|
The path to the resource for creating a preference set. A query parameter can be added to provide the view/ontology that the preferences are to be stored in. (see: GPII OAuth 2 Guide: User's Preferences) | "/add-preferences?view=%view" |
preferencesConfig.authentication.grant_type
|
The grant type supported by the OAuth2 server. | "client_credentials" |
preferencesConfig.authentication.scope
|
The level of permissions that are being requested. | "add_preferences" |
vagrant.json
vagrant.json merges on top of oauth2.json, replacing the environment variables for connecting to the OAuth2 server with the expect hostname and port when running inside of a Vagrant VM. The configuration assumes that an instance of the OAuth2 server is available through the host machine at port 8081.
A Vagrant VM is provided with the First Discovery Server for quickly creating its own development environment.
(see: vagrant.json)
Option Path | Description | Value |
---|---|---|
preferencesConfig.securityServer.port
|
The port number that the GPII OAuth2 server is hosted at. | "8081" |
preferencesConfig.securityServer.hostname
|
The hostname that the GPII OAuth2 server is hosted at. | "http://10.0.2.2" |
Launching
The First Discovery Server can be launched as a Kettle application by making use of Kettle Configs.
There are two typical ways of launching a Kettle app, programmatically and from command line.
(See: Starting a Kettle application)
Programmatically
// require the kettle module
var kettle = require("kettle");
// load the config
kettle.config.loadConfig({
// path to the config directory
configPath:"./src/config",
// name of the config to load, without the file extension
configName: "vagrant"
});
Command Line
# Call Kettle's init.js script with the
# configPath and configName
# node node_modules/kettle/init.js <configPath> [<configName>]
node node_modules/kettle/init.js ./src/config vagrant
# or using an environment variable to specify
# the configName
# NODE_ENV=<configName> node node_modules/kettle/init.js <configPath>
NODE_ENV=vagrant node node_modules/kettle/init.js ./src/config
REST API
URL | Request | Description |
---|---|---|
/user[?view=:view] |
POST |
Accepts a set of preferences, in a JSON object, to be stored on the preferences server. For example:
On successfully storing the preferences set, a JSON object is returned containing userToken and preferences properties. The userToken is the GPII token, which can be used for retrieving the preferences on a GPII enabled device. The preferences are a confirmation of the preferences stored on Preferences server for that GPII token. For example:
The optional view query parameter is used to specify which ontology the preferences are stored in. (See: Preferences Server)
|
Demos
This demo implements the integration with the GPII Preferences Server to save preferences. http://build.fluidproject.org/first-discovery/demos/prefsServerIntegration