Skip to content

Commit

Permalink
Merge Pinta365/webauthn-demo-koa
Browse files Browse the repository at this point in the history
  • Loading branch information
Hexagon committed Dec 17, 2021
2 parents e8a70bd + c15b517 commit 776c51c
Show file tree
Hide file tree
Showing 9 changed files with 942 additions and 998 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
## Fork information
All credit goes to the original contributors as seen below. This is a only forked and ported copy that use Koa instead of Express as web framework.

# webauthn-skeleton

This is a working skeleton of a Node.js/Express application with passwordless login (Web Authentication API, WebAuthN, FIDO2).
Expand Down
68 changes: 33 additions & 35 deletions app.js
Original file line number Diff line number Diff line change
@@ -1,49 +1,47 @@
const
express = require("express"),
bodyParser = require("body-parser"),
cookieSession = require("cookie-session"),
path = require("path"),
crypto = require("crypto"),
const Koa = require('koa');
const serve = require('koa-static');
const bodyParser = require('koa-bodyparser');
const session = require('koa-session');

config = require("./config"),
const path = require('path');
const crypto = require('crypto');

defaultroutes = require("./routes/default"),
webuathnroutes = require("./routes/webauthn"),
tokenroutes = require("./routes/token"),
const config = require('./config');

app = express();
const defaultroutes = require('./routes/default');
const webuathnauth = require('./routes/webauthn.js');
const tokenroutes = require("./routes/token");

app.use(bodyParser.json());
const app = new Koa();

// Sessions
app.use(cookieSession({
name: "session",
keys: [crypto.randomBytes(32).toString("hex")],
// Static files (./static)
app.use(serve(path.join(__dirname, 'public/static')));

// Cookie Options
maxAge: config.cookieMaxAge
}));
// Session
app.keys = [crypto.randomBytes(32).toString('hex')];
app.use(session({}, app));

// Static files (./static)
app.use(express.static(path.join(__dirname, "public/static")));
// Middleware
app.use(bodyParser());

//Routes
app.use(defaultroutes.routes());
app.use(defaultroutes.allowedMethods());

// Routes
app.use("/", defaultroutes);
app.use("/webauthn", webuathnroutes);
app.use("/token", tokenroutes);
app.use(webuathnroutes.routes());
app.use(webuathnroutes.allowedMethods());

const port = config.port;
app.use(tokenroutes.routes());
app.use(tokenroutes.allowedMethods());

// Local development
if (config.mode === "development") {
const https = require("https");
const fs = require("fs");
let privateKey = fs.readFileSync("./keys/key.pem");
let certificate = fs.readFileSync("./keys/cert.pem");
https.createServer({
key: privateKey,
cert: certificate
}, app).listen(port);
if (config.mode === 'development') {
const https = require('https');
const fs = require('fs');
https.createServer({
key: fs.readFileSync('./keys/key.pem'),
cert: fs.readFileSync('./keys/cert.pem')
}, app.callback()).listen(port);

// "Production" HTTP - (for use behind https proxy)
} else {
Expand Down
File renamed without changes.
Loading

0 comments on commit 776c51c

Please sign in to comment.