-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathserver.js
132 lines (110 loc) · 3.24 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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
const express = require("express");
const app = express();
const bodyParser = require("body-parser");
const fetch = require("node-fetch");
const { Parser } = require("htmlparser2");
var querystring = require("querystring");
const session = require("express-session");
const {issue, jwk} = require("./sdjwt.js");
app.use(bodyParser.json());
app.use(express.json());
app.use(express.urlencoded({ extended: true }));
app.use("/.well-known/web-identity", async (req, res) => {
res.type("json");
res.send({
provider_urls: ["/fedcm.json"],
});
});
app.use("/jwks.json", async (req, res) => {
res.set("Access-Control-Allow-Origin", "*");
res.type("json");
const key = await jwk();
// Some verifiers fail with these extra WebCrypto parameters.
delete key.key_ops;
delete key.ext;
res.send({
keys: [key]
});
});
app.use("/fedcm.json", async function (req, res, next) {
res.type("json");
res.send({
accounts_endpoint: "/accounts",
vc_issuance_endpoint: "/vc_issuance_endpoint",
id_assertion_endpoint: "/vc_issuance_endpoint",
client_metadata_endpoint: "/client_metadata",
id_assertion_endpoint: "/id_assertion_endpoint",
revocation_endpoint: "/revoke_endpoint.json",
metrics_endpoint: "/metrics_endpoint.json",
login_url: "/",
// types: ["indieauth"],
formats: ["vc+sd-jwt"],
scheme: "issuer",
branding: {
background_color: "#1a73e8",
color: "#fff",
icons: [{
url: "https://cdn-icons-png.flaticon.com/512/25/25231.png",
size: 32
}, {
url: "https://cdn-icons-png.flaticon.com/512/25/25231.png",
size: 40
}]
},
});
});
function error(res, message) {
return res.status(400).end();
}
app.use("/accounts", (req, res) => {
res.type("json");
res.send({
accounts: [{
id: "1234",
account_id: "1234",
email: "samuelgoto@gmail.com",
name: "Sam Goto",
given_name: "Sam",
picture: "https://pbs.twimg.com/profile_images/920758039325564928/vp0Px4kC_400x400.jpg",
approved_clients: [],
},],
});
});
app.use("/client_metadata", (req, res) => {
// Check for the CORS headers
res.type("json");
res.send({
privacy_policy_url: "https://rp.example/privacy_policy.html",
terms_of_service_url: "https://rp.example/terms_of_service.html",
});
});
const tokens = {};
app.post("/vc_issuance_endpoint", async (req, res) => {
res.type("json");
//res.set("Access-Control-Allow-Origin", req.headers.origin);
//res.set("Access-Control-Allow-Credentials", "true");
console.log("What the Issuer got:");
console.log(req.body);
const holder = req.body.holder_key;
const sdjwt = await issue(holder, [
["sub", "https://sgo.to"],
["email", "samuelgoto@gmail.com"],
["name", "Sam Goto"],
["picture", "https://pbs.twimg.com/profile_images/920758039325564928/vp0Px4kC_400x400.jpg"],
["firstName", "Sam"],
["lastName", "Goto"],
]);
console.log(sdjwt);
res.json({
token: sdjwt
});
});
app.use(express.static("public"));
app.get("/", async (req, res) => {
res.send(`
This is the absolutely simplest FedCM IdP Implementation.
`);
});
const listener = app.listen(process.env.PORT || 8080, async () => {
console.log("Your app is listening on port " + listener.address().port);
});