0.9.0 • Published 5 years ago

kiss-auth-fetch v0.9.0

Weekly downloads
-
License
ISC
Repository
-
Last release
5 years ago

KISS Auth Fetch

A Simple NodeJs module to append Authorisation header to fetch pipeline

##Purpose

To simplify the process of appending a Authorisation header into a fetch operation. Rather than append the Authorisation header to each API call, configure the fetcher process to perform this automagically.

##Usage

The module returns a factory function.

const kissAuthFetch = require('kiss-auth-fetch')

const authFetch = authFetchFactory({
        auth:  Promise.resolve('Bearer xxxxxx/yyyyyy')
    })

// use authFetch as FetchAPI

By default, the module assumes that the Fetch API is exposed on the global context. If this is not the case or want to pipeline an alternate to the Fetch API, then define this in the 'fetch' property ...

const kissAuthFetch = require('kiss-auth-fetch')
const nodeFetch = require('none-fetch')

const authFetch = authFetchFactory({
        fetch: nodeFetch,
        auth:  Promise.resolve('Bearer xxxxxx/yyyyyy')
    })

##Advanced Usage

const kissAuthFetch = require('kiss-auth-fetch')

const authFetch = authFetchFactory({
        async auth() {
            const key = await getKeyFromDatabase()
            return 'Bearer ' + signJwt('xxxx', key) 
        }       
    })

// use authFetch as FetchAPI