-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathapp.js
81 lines (64 loc) · 2.35 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
// app.js
/**
* Module dependencies.
*/
var fs = require('fs');
//Certificate for https
var https_options = {
key: fs.readFileSync('server.key'),
cert: fs.readFileSync('server.crt'),
requestCert: false,
rejectUnauthorized: false
};
var routescan = require('express-routescan');
var routes = require('./routes');
var cookieParser = require('cookie-parser');
var express = require('express');
var app = express();
var server = require('https').createServer(https_options,app);
var io = require('socket.io')(server);
var request = require('request');
passport = require('passport');
var AdobeStrategy = require('passport-adobe-oauth2').Strategy;
var port = process.env.PORT || 3000;
app.use(express.static(__dirname + '/public'));
server.listen(port);
var consoleClientID, consoleClientSecret, consoleAuthCode, consoleAccessToken, consoleAuthURL, consoleTokenURL,
consoleScopes;
io.on('connection', function (socket) {
socket.emit('welcome', {});
socket.emit('getCookie',{});
socket.on('getAuthCode', function (consoleCredentials) {
consoleClientID = consoleCredentials.clientID;
consoleAuthURL = consoleCredentials.authEndpoint;
consoleScopes = consoleCredentials.scope;
consoleClientSecret=consoleCredentials.clientSecret;
consoleTokenURL=consoleCredentials.tokenEndpoint;
passport.serializeUser(function(user, done) {
done(null, user);
});
passport.deserializeUser(function(obj, done) {
done(null, obj);
});
passport.use(new AdobeStrategy({
authorizationURL:consoleAuthURL,
tokenURL:consoleTokenURL,
clientID: consoleClientID,
clientSecret: consoleClientSecret,
scope: consoleScopes
},
//verify function below
function(accessToken, refreshToken, profile, done) {
// asynchronous verification, for effect...
socket.emit("accessToken",{accessToken:accessToken,refreshToken:refreshToken});
var tokens={accessToken:accessToken, refreshToken:refreshToken};
return done(null,tokens);
}
));
socket.emit('openUrl',{url:'/auth'});
});
});
app.use(cookieParser('secret'));
app.use(passport.initialize());
app.use(passport.session());
routescan(app);