Authenticate and Encrypt HTTP with User Credentials (Not TLS-SRP) (ExpressJS Implementation).
* only the contents belong to this repo, all other content is related to the APE library
const express = require("express");
const ape = require("@hutiwephy/ape-express");
var app = express();
var api = express.Router();
api.use(ape((id)=>{
return // Client secret
}));
api.use((err, req, res, next)=>{
if(err){
next(401);
}
});
api.post("/", (req, res, next)=>{
res.ape.json({
error: false,
code: 200,
request_body: req.body,
});
next();
});
api.use((err, req, res, next)=>{
// Handle errors
});
app.use("/api", api);
app.use(ape.libroute);
app.get("/", (req, res, next)=>{
res.sendFile(__dirname+"/index.html");
});
app.listen(3000);
Takes a client id to secret solver and automatically handles the entire ape authentication and body decryption.
Note: Asyncronous callback is supported.
Parameters:
-
callback
:function
Takes a client idBuffer
and returnsnull
or the corresponding secret inBuffer
format.
Returns:
-
Express.Middleware
Middleware.
A Router to handle calls for the ape.min.js
and ape.js
library on the client side.
Returns:
-
Express.Router
Router constant.
If Authentication succeded this constant will be set with the current session.
Returns:
-
ape.Session
Current Session.
Send Encrypted body chunks.
Parameters:
-
data
:string
,object
Data to send. Ifobject
then it will automatically setContent-Type
toapplication/json
.
Returns:
-
Express.Response
Returns response instance to allow daisy chaining.
Send Encrypted object as body chunks.
Parameters:
-
data
:object
object
to send. It will automatically setContent-Type
toapplication/json
.
Returns:
-
void