@hutiwephy/ape-express

1.0.1 • Public • Published

Authenticated Payload Exchange

Authenticate and Encrypt HTTP with User Credentials (Not TLS-SRP) (ExpressJS Implementation).

Content

* only the contents belong to this repo, all other content is related to the APE library

Usage

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);

Documentation

ape(callback)

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 id Buffer and returns null or the corresponding secret in Buffer format.

Returns:

  • Express.Middleware
    Middleware.

ape.libroute

A Router to handle calls for the ape.min.js and ape.js library on the client side.

Returns:

  • Express.Router
    Router constant.

Express

Express.Request.session

If Authentication succeded this constant will be set with the current session.

Returns:

Response.ape.send(data)

Send Encrypted body chunks.

Parameters:

  • data: string, object
    Data to send. If object then it will automatically set Content-Type to application/json.

Returns:

  • Express.Response
    Returns response instance to allow daisy chaining.

Response.ape.json(data)

Send Encrypted object as body chunks.

Parameters:

  • data: object
    object to send. It will automatically set Content-Type to application/json.

Returns:

  • void

Package Sidebar

Install

npm i @hutiwephy/ape-express

Weekly Downloads

0

Version

1.0.1

License

MIT

Unpacked Size

9.35 kB

Total Files

8

Last publish

Collaborators

  • hutiwephy