1.0.2 • Published 2 years ago

@cedrick-ah/http-signature v1.0.2

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years ago

@cedrick-ah/http-signature

GitHub license

Usage

This package help you construct http signature header.

Example

This basic usage example should help you get started :

const express = require('express'),
axios = require('axios'),
moment = require('moment'),
app = express(),
port = 8001

moment().format()

const {
    createSignature,
    constructSignature,
    generateAuth,
} = require('../lib/index.js')

app.get('/', function(req, res, next){
    const signature = constructSignature({
        method: 'post', //method in protected url
        path: '/create', //path in protected url
        date: moment() //moment of request
    },['(request-target)', 'date']//headers
    )

    const Signature = createSignature(signature,
        '21357d1e-7185-41ce-86c3-163db561fad1', //admin key
        '9eb0740b687fa04e1933c3022e7e753b09bee953a2c081c4f827e4eba119eec303fba56978a7318fd5e82b1756465b1241d467dec5a30a2b8eca684f1ea2625c',//admin secret
        'hmac-sha256'//algorithm
    )
    const auth = generateAuth(Signature)

    const data = {
        userName: "Google",
        email: "google@example.com",
        scope: ["email"]
    }
    const protectedURL = 'http://admin.localhost:8000/clients/create'
    
    axios.post(protectedURL, data,
    {
        headers: {
            'Authorization': auth
        }
    }
    ).then((response)=>{
        const data = response.data.msg
        res.json(data)
        next()
    }).catch((err)=>{
        return res.json({err})
    })
})

app.listen(port, function(err){
    if (err) throw err
    console.log('Server listening on Port', port)
})
1.0.2

2 years ago

1.0.1

2 years ago

1.0.0

2 years ago