This repository has been archived by the owner on Jul 22, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
app.js
47 lines (41 loc) · 1.56 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
const express = require("express"); // https://www.npmjs.com/package/express
const session = require("express-session"); // https://www.npmjs.com/package/express-session
const passport = require("passport"); // https://www.npmjs.com/package/passport
const WebAppStrategy = require("ibmcloud-appid").WebAppStrategy; // https://www.npmjs.com/package/ibmcloud-appid
const app = express();
// Warning The default server-side session storage implementation, MemoryStore,
// is purposely not designed for a production environment. It will
// leak memory under most conditions, it does not scale past a single process,
// and is meant for debugging and developing.
// For a list of stores, see compatible session stores below
// https://www.npmjs.com/package/express-session#compatible-session-stores
app.use(
session({
secret: "123456",
resave: true,
saveUninitialized: true
})
);
app.use(passport.initialize());
app.use(passport.session());
passport.serializeUser((user, cb) => cb(null, user));
passport.deserializeUser((user, cb) => cb(null, user));
passport.use(
new WebAppStrategy({
tenantId: "",
clientId: "",
secret: "",
oauthServerUrl: "",
redirectUri: "http://localhost:3000/appid/callback"
})
);
// Handle callback
app.get("/appid/callback", passport.authenticate(WebAppStrategy.STRATEGY_NAME));
// Protect the whole app
app.use(passport.authenticate(WebAppStrategy.STRATEGY_NAME));
// Serve static resources
app.use(express.static("./public"));
// Start server
app.listen(3000, () => {
console.log("Listening on http://localhost:3000");
});