-
Notifications
You must be signed in to change notification settings - Fork 36
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
07ab7f8
commit a0e4350
Showing
12 changed files
with
2,282 additions
and
2,184 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
/** | ||
* This file defines a router for a virtual server. A virtual server is mostly | ||
* just a pair of FHIR server for specific FHIR version and an auth server. | ||
* These virtual server routers will be mounted on two parallel locations: | ||
* - `{base}/v/{fhirVersion}` - default server | ||
* - `{base}/v/{fhirVersion}/sim/{sim}` - with additional metadata in the {sim} | ||
*/ | ||
|
||
const express = require("express") | ||
const base64url = require("base64-url") | ||
const wellKnownOIDC = require("./wellKnownOIDCConfiguration") | ||
const wellKnownSmart = require("./wellKnownSmartConfiguration") | ||
const AuthorizeHandler = require("./AuthorizeHandler") | ||
const RegistrationHandler = require("./RegistrationHandler") | ||
const TokenHandler = require("./TokenHandler") | ||
const { introspectionHandler } = require("./introspect") | ||
const lib = require("./lib") | ||
const simpleProxy = require("./simple-proxy") | ||
|
||
const fhirServer = module.exports = express.Router({ mergeParams: true }) | ||
const urlencoded = express.urlencoded({ extended: false, limit: '64kb' }) | ||
const text = express.text({ type: "*/*", limit: 1e6 }) | ||
|
||
// Authorization endpoints | ||
// ----------------------------------------------------------------------------- | ||
|
||
fhirServer.get("/auth/authorize", AuthorizeHandler.handleRequest) | ||
|
||
fhirServer.post("/auth/token", urlencoded, TokenHandler.handleRequest) | ||
|
||
fhirServer.post("/auth/register", urlencoded, RegistrationHandler.handleRequest) | ||
|
||
fhirServer.post("/auth/introspect", urlencoded, introspectionHandler) | ||
|
||
|
||
// Metadata endpoints | ||
// ----------------------------------------------------------------------------- | ||
|
||
fhirServer.get("/.well-known/smart-configuration", wellKnownSmart) | ||
|
||
fhirServer.get("/.well-known/openid-configuration", wellKnownOIDC) | ||
|
||
|
||
// UI endpoints | ||
// ----------------------------------------------------------------------------- | ||
|
||
// patient picker | ||
fhirServer.get("/picker", (_, res) => res.sendFile("picker.html", { root: './static' })) | ||
|
||
// encounter picker | ||
fhirServer.get("/encounter", (_, res) => res.sendFile("encounter-picker.html", { root: './static' })) | ||
|
||
// user picker | ||
fhirServer.get("/login", (_, res) => res.sendFile("login.html", { root: './static' })) | ||
|
||
// approve launch dialog | ||
fhirServer.get("/authorize", (_, res) => res.sendFile("authorize.html", { root: './static' })) | ||
|
||
|
||
// Other endpoints | ||
// ----------------------------------------------------------------------------- | ||
|
||
// Provide launch_id if the CDS Sandbox asks for it | ||
fhirServer.post("/fhir/_services/smart/launch", express.json(), (req, res) => { | ||
res.json({ | ||
launch_id: base64url.encode(JSON.stringify({ | ||
context: req.body.parameters || {} | ||
})) | ||
}); | ||
}); | ||
|
||
// Proxy everything else under `/fhir` to the underlying FHIR server | ||
fhirServer.use("/fhir", text, handleParseError, simpleProxy); | ||
|
||
|
||
|
||
function handleParseError(err, req, res, next) { | ||
if (err instanceof SyntaxError && err.status === 400) { | ||
return lib.operationOutcome( | ||
res, | ||
`Failed to parse JSON content, error was: ${err.message}`, | ||
{ httpCode: 400 } | ||
); | ||
} | ||
next(err, req, res); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,52 +1,28 @@ | ||
const router = require("express").Router({ mergeParams: true }); | ||
const ursa = require('ursa-purejs'); | ||
const crypto = require("crypto"); | ||
const jose = require("node-jose") | ||
const { whitelist } = require("./lib") | ||
|
||
module.exports = router; | ||
|
||
router.get("/rsa", (req, res) => { | ||
|
||
let enc = String(req.query.enc || ""); | ||
if (["base64", "binary", "hex", "utf8"].indexOf(enc) == -1) { | ||
enc = undefined; | ||
} | ||
|
||
// create a pair of keys (a private key contains both keys...) | ||
const keys = ursa.generatePrivateKey(); | ||
|
||
// reconstitute the private and public keys from a base64 encoding | ||
// @ts-ignore | ||
const privatePem = keys.toPrivatePem(enc); | ||
const publicPem = keys.toPublicPem(enc); | ||
|
||
// make a private key, to be used for encryption | ||
// const privateKey = ursa.createPrivateKey(privatePem, '', enc); | ||
const router = module.exports = require("express").Router({ mergeParams: true }); | ||
|
||
// make a public key, to be used for decryption | ||
// const publicKey = ursa.createPublicKey(publicPem, enc); | ||
|
||
res.json({ | ||
privateKey: privatePem, | ||
publicKey : publicPem | ||
}); | ||
module.exports = router; | ||
|
||
router.get("/rsa", (req, res, next) => { | ||
jose.JWK.createKey("RSA", 2048, { alg: "RS384" }).then(key => { | ||
res.json({ | ||
publicKey: key.toPEM(), | ||
privateKey: key.toPEM(true) | ||
}) | ||
}, next) | ||
}); | ||
|
||
router.get("/random", (req, res) => { | ||
const encodings = ["base64", "binary", "hex", "utf8", "ascii"]; | ||
let enc = whitelist(encodings, String(req.query.enc), "hex"); | ||
|
||
/** | ||
* @type { "base64" | "binary" | "hex" | "utf8" } | ||
*/ | ||
// @ts-ignore | ||
let enc = String(req.query.enc || "ascii"); | ||
if (["base64", "binary", "hex", "utf8"].indexOf(enc) == -1) { | ||
enc = undefined; | ||
} | ||
|
||
let len = +req.query.len; | ||
let len = +(req.query.len || 32); | ||
if (isNaN(len) || !isFinite(len) || len < 1 || len > 1024) { | ||
len = 32; | ||
} | ||
|
||
res.send(crypto.randomBytes(len).toString(enc)); | ||
|
||
res.set("content-type", "text/plain") | ||
res.end(jose.util.randomBytes(len).toString(enc)) | ||
}); |
Oops, something went wrong.