-
Notifications
You must be signed in to change notification settings - Fork 4
/
app.js
107 lines (88 loc) · 3.22 KB
/
app.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
// dependencies
var express = require('express');
var path = require('path');
var passport = require('passport');
var fs = require('fs');
var cookieParser = require('cookie-parser');
var bodyParser = require('body-parser');
var session = require('express-session');
var logger = require('morgan');
var methodOverride = require('method-override');
var idmWeb = require('./index');
var errorHandler = require('./routes/errorHandler');
/*
use during development:
- var idmWeb = require('../index');
- & make sure that you use the package.json without requiring passport!! use package.json
for production:
- var idmWeb = require('agile-idm-web-ui'); to bring the module from github
- use the package-prod.json with passport!
*/
//load configurations
var conf;
//to find the configuration file (if it is provided as argument, then it is used.)
var location = './conf';
if(process.argv.length >2){
location = process.argv[2];
}
try{
//this one is ignored safely... where you can have your own tokens for Oauth2 :)
conf = require(location+'/my-agile-ui-conf');
}
catch(error){
conf = require(location+'/agile-ui-conf');
}
var core_conf = require(location+'/agile-idm-core-conf');
var https = require('https');
var app = express();
app.set('view engine', 'ejs');
app.use(logger('dev'));
app.use(cookieParser());
app.use(bodyParser.urlencoded({
extended: true
}));
app.use(methodOverride());
app.use(session({
secret: idmWeb.tokens.uid(26),
resave: false,
saveUninitialized: false
}));
app.use(passport.initialize());
//NOTE: could help for error handling
/*var flash = require('connect-flash');
app.use(flash());*/
//also enable failureFlash in the proper part of routes/provider-routes.js
app.use(passport.session());
//set serializer for users and clients
idmWeb.serializer(conf,core_conf);
//set up external providers with passport
var strategies = idmWeb.authStrategies(conf,core_conf);
//set ahentication endpoints to authenticate with different means (webid, oauth2, etc)
app.use("/auth", idmWeb.routerProviders(strategies, conf));
//set up entities API
app.use("/api/v1", idmWeb.routerApi(conf, core_conf,strategies));
//policies API
app.use("/api/v1", idmWeb.RouterPoliciesApi(conf, core_conf));
app.use("/api/v1", idmWeb.RouterAuditApi(conf, core_conf));
//set up static sites
app.use("/static", express.static(path.join(__dirname, './static')));
//oauth2orize server (this allows IDM to work as an Oauth2 provider to apps)
var oauth2 = idmWeb.oauth2orizeServer(conf,core_conf);
idmWeb.oauth2ServerStrategies(conf,core_conf);
app.use("/oauth2",idmWeb.routerOauth2(conf,core_conf));
app.use("/",idmWeb.routerSite(strategies, conf));
app.use(errorHandler);
var options = {
key: fs.readFileSync(conf.tls.key),
cert: fs.readFileSync(conf.tls.cert),
requestCert: true
};
app.listen(conf.http_port);
https.createServer(options, app).listen(conf.https_port_with_client);
options.requestCert = false;
idmWeb.configure(core_conf);
https.createServer(options, app).listen(conf.https_port);
console.log("listening on port "+conf.http_port+ " for http ");
console.log("listening on port "+conf.https_port+ " for https ");
console.log("listening on port "+conf.https_port_with_client+ " for https and client certificate request for webid ");
module.exports = app;