-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
93 lines (76 loc) · 2.89 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
/*********************************************************************
* Copyright (c) 2018 University of Passau and others
*
* This program and the accompanying materials are made
* available under the terms of the Eclipse Public License 2.0
* which is available at https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
**********************************************************************/
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;