-
Notifications
You must be signed in to change notification settings - Fork 23
/
app.js
56 lines (50 loc) · 1.36 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
const express = require("express");
const app = express();
const fido = require('./fido.js');
const bodyParser = require('body-parser');
const enforce = require('express-sslify');
if (process.env.ENFORCE_SSL_HEROKU === "true") {
app.use(enforce.HTTPS({ trustProtoHeader: true }));
} else if (process.env.ENFORCE_SSL_AZURE === "true") {
app.use(enforce.HTTPS({ trustAzureHeader: true }));
}
app.use(express.static('public'));
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: true }));
app.get('/challenge', async (req, res) => {
try {
const challenge = await fido.getChallenge();
res.json({
result: challenge
});
} catch (e) {
res.json({
error: e.message
});
};
});
app.put('/credentials', async (req, res) => {
try {
const credential = await fido.makeCredential(req.body);
res.json({
result: credential
});
} catch (e) {
res.json({
error: e.message
});
}
});
app.put('/assertion', async (req, res) => {
try {
const credential = await fido.verifyAssertion(req.body);
res.json({
result: credential
});
} catch (e) {
res.json({
error: e.message
});
}
});
app.listen(process.env.PORT || 3000, () => console.log('App launched.'));