-
Notifications
You must be signed in to change notification settings - Fork 1
/
api.js
49 lines (45 loc) · 1.79 KB
/
api.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
var express = require('express');
var app = express();
var bodyParser = require('body-parser');
var urlencodedParser = bodyParser.urlencoded({
extended: true
});
var signing = require("./sign.js");
var html = require("./html.js");
var reqDecodedResult;
app.get('/rcs/jwk.pub', function (req, res) {
res.setHeader('content-type', 'application/json');
res.end(JSON.stringify(signing.getJWK()));
});
app.get('/rcs/consent', function (req, res) {
reqDecoded = signing.decode(req.query.consent_request);
res.setHeader('content-type', 'text/html');
res.write("<H1>CONSENT PAGE</H1>");
reqDecoded.then(result => {
reqDecodedResult = result;
var scopeTokens = Object.keys(reqDecodedResult.scopes);
html.displayConsent(scopeTokens, res);
})
});
app.post('/rcs/consent', urlencodedParser, function (req, res) {
var consentApprovalURL = reqDecodedResult.consentApprovalRedirectUri;
var scopeTokens = Object.keys(req.body);
var submit = scopeTokens.indexOf("submit");
if (submit > -1) {
scopeTokens.splice(submit, 1);
}
reqDecodedResult.scopes = scopeTokens; // Overriding the scopes key in ConsentReq with user consent
res.setHeader('content-type', 'text/html');
res.write("<h2>Thank you</h2>")
var signedJWT = signing.sign(reqDecodedResult);
signedJWT.then(result => {
res.end('<form action="' + consentApprovalURL + '" method="post"><input type="hidden" value=' + result + ' name="consent_response" />' +
'<input type="submit" value="Submit Consent" name="submit"></input>' +
'</form>')
})
});
var server = app.listen(3000, function () {
var host = server.address().address;
var port = server.address().port;
console.log("Remote Consent Service listening at http://%s:%s", host, port);
});