forked from bgarlow/okta-hooks
-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
86 lines (71 loc) · 2.65 KB
/
server.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
// init project
const express = require('express');
const app = express();
const http = require('http').Server(app);
http.listen(process.env.PORT);
const io = require('socket.io')(http);
const util = require('util');
const bodyParser = require('body-parser');
// define our hook command identifiers, as things may change during the beta
const hookCommandTypes = {
idTokenPatch: 'com.okta.identity.patch',
accessTokenPatch: 'com.okta.access.patch',
samlAssertionPatch: 'com.okta.tokens.assertion.patch'
}
module.exports = {
"io": io,
"hookCommandTypes": hookCommandTypes
}
// http://expressjs.com/en/starter/static-files.html
app.use(express.static('public'));
app.use(bodyParser.json());
// Define our API routes
const registrationHooks = require('./handlers/registrationHooks');
const eventHooks = require('./handlers/eventHooks');
const samlTokenHooks = require('./handlers/samlTokenHooks');
const oidcTokenHooks = require('./handlers/oidcTokenHooks');
const importHooks = require('./handlers/importHooks');
const oktaUtils = require('./oktaUtils');
app.use('/okta/hooks/registration', registrationHooks);
app.use('/okta/hooks/event', eventHooks);
app.use('/okta/hooks/saml-token', samlTokenHooks);
app.use('/okta/hooks/oidc-token', oidcTokenHooks);
app.use('/okta/hooks/import', importHooks);
app.use('/demo/utils', oktaUtils);
// Set up socket.io for real-time logging
io.on('connection', function(socket){
console.log('Client connection received');
const connectionMessage = {
'Logger Status': 'connected!'
}
// emit a startup message when the socket connects
//socket.emit('logMessage', { 'logMessage': 'Logger connected!' });
// Not used
socket.on('receivedFromClient', function (data) {
console.log(data);
});
});
// Bind prefix to log levels to make it easier to read the logs
console.log = console.log.bind(null, '[LOG]');
console.info = console.info.bind(null, '[INFO]');
console.warn = console.warn.bind(null, '[WARN]');
console.error = console.error.bind(null, '[ERROR]');
// Routes --------------------------------------------
// http://expressjs.com/en/starter/basic-routing.html
app.get('/', function(request, response) {
response.sendFile(__dirname + '/views/index.html');
});
app.get('/readme', function(request, response) {
response.sendFile(__dirname + '/README.md');
});
// Listen for requests ------------------------------------- :)
/*
http.listen(process.env.PORT, function(){
console.log('HTTP server started on port ' + process.env.PORT);
});
*/
/*
const listener = app.listen(process.env.PORT, function() {
console.log('Your app is listening on port ' + listener.address().port);
});
*/