* Various improvements and bugfixes * Requires CaaS version 0.11.89 or later
npm install ts3d.hc.caas.usermanagementnpm install
npm start
http://localhost:3000
npm install ts3d.hc.caas.usermanagement
const caasUserManagementServer = require('ts3d.hc.caas.usermanagement');
json
{
"hc-caas-um": {
"mongodbURI": "mongodb://127.0.0.1:27017/caas_demo_app",
"conversionServiceURI": "http://localhost:3001",
"publicURL": "http://localhost:3000",
"useDirectFetch": false,
"useStreaming": false,
"demoMode": false,
"assignDemoHub": false,
"demoProject": ""
}
}
`
3. Start the CaasUserManagementServer with caasUserManagementServer.start(), providing your express app as a parameter as well as other configuration settings. See below for a minimal example:
`
const express = require('express');
const path = require('path');
const app = express();
app.use(express.static(path.join(__dirname, 'public')));
const caasUserManagementServer = require('ts3d.hc.caas.usermanagement');
caasUserManagementServer.start(app, null,{createSession:true, sessionSecret:"12345"});
app.listen(3000);
`
$3
1. Add 'caasu.min.js' to your client-side project. The client-side library is included in the /dist folder of this repository.
2. Create a new CaasUserManagementClient object, specifying your server address.
myUserManagmentClient = new CaasU.CaasUserManagementClient("http://localhost:3000");
3. See the frontend code in the public folder of this project and the reference manual for further API usage. Alternatively, feel free to copy the content of the public folder from this repository to your own project and use the provided reference implementation as a starting point for your own application.
Frontend
The frontend is a straightforward bootstrap based implementation that uses the client-side library to communicate with the server. The emphasis is on simplicity, the goal during development was to make it easy to understand and extend, not to provide a fully production ready implementation.
Additional Details on the Server
By default the CaaS User Management server will add its own REST end-points to your express app, which are all prefixed with /caas_um_api. It will also start its own database session as well as create a user-session for cookie management. If you are already using mongoose as your database you can provide its connection as the second parameter to the start function. In addition, the User Management Server can create its own session store for cookie based session management but you can choose to provide your own as well. In this case the user management library will expect a session to be present on the request object for all its REST API calls. If you allow the User Management server to create its own session store, you should provide an "unguessable" sessionSecret string for the session store, which will be used to sign the session cookies.
Security and User Accounts
Account management is provided out of the box, with a simple registration and login process, utilizing a straightforward encrypted password scheme. However it is easy to use the library with your own account management. To allow for this, the server-side library has a function to retrieve all user account data, which gives you the ability to create and query accounts directly server-side via mongoose, thereyby bypassing the REST API. This approach allows you to handle all account creation while still leveraging the library for managing the connection to CaaS as well as Hubs and Project. See below for an example on how to retrieve all user account data and add the user to the session object:
`
app.put('/myLogin', async function (req, res, next) {
//perform custom login procedure
//...
let usersDB = caasUserManagementServer.getDatabaseObjects().users;
let user = await usersDB.findOne({email:loggedinuser});
req.session.caasUser = users2;
});
`
If you use this approach, it is advisable to do additional authentication on the REST API calls to the User Management server to prevent unauthorized access to the user data and login endpoints.
Running CaaS User Management on a separate server
If you want to use the User Management node module on a separate server from your main application, you can do so by simply proxying its REST API calls (which are all prefixed with /caas_um_api) from your web-server. In this scenario you might want to add an extra layer to the server to handle authentication and authorization if desired.
Running CaaS and CaaS User Management from the same project
You can easily run both CaaS and the CaaS User Management together. See below for a minimal example that initializes both libraries fromt the same Node application:
`
const express = require('express');
const path = require('path');
const app = express();
app.use(express.static(path.join(__dirname, 'public')));
const conversionserver = require('ts3d.hc.caas');
conversionserver.start();
const caasUserManagementServer = require('ts3d.hc.caas.usermanagement');
caasUserManagementServer.start(app, null,{createSession:true, sessionSecret:"12345"});
app.listen(3000);
`
In this case, you want to make sure to have a local.json file in the config folder of your application which configures the two libraries following the pattern in the example below:
`json
{
"hc-caas-um": {
//local settings for CaaS User Management
},
"hc-caas": {
//local settings for CaaS
}
}
``