@arkadecx/arkade-cloud-functions-auth

1.5.0-alpha-8 • Public • Published

arkade-cloud-functions-auth

Install

yarn install @arkadecx/arkade-cloud-functions-auth

Usage

Server side

import { auth } from '@arkadecx/arkade-cloud-functions-auth';

const r = auth(req, {
  hmacSecret: 'any secret',
  originDomainWhitelist: ['www.google.com.au'],
});
if (!r) {
  return res.status(401).json({ error: 'Unauthorised' });
}

AuthOptions

name desc default value
enableHmacCheck if enable hmac check true
hmacSecret secrect used to encrypt ''
enableOriginCheck if enable origin domain check true
originDomainWhitelist origin domain whilelist []

Client side

import { hmacSignature } from '@arkadecx/arkade-cloud-functions-auth';

const body = {
    //payload here
  };
const route = '/api/route';

const now = Date.now();
const signature = hmacSignature(
    'any secret',
    now,
    route,
    body
);
const response = await fetch(route, {
    method: 'post',
    headers: {
        'Content-Type': 'application/json',
        'x-authentication': `${now}:${signature}`,
    },
    body: JSON.stringify(body),
});

Limitation

  • Only work with NextJS api at the moment
  • If POST request, only works with Content-Type: application/json

Readme

Keywords

Package Sidebar

Install

npm i @arkadecx/arkade-cloud-functions-auth

Weekly Downloads

32

Version

1.5.0-alpha-8

License

MIT

Unpacked Size

14.7 kB

Total Files

5

Last publish

Collaborators

  • tew-arkade
  • fnandogp
  • yazhizhou
  • max.arkade
  • kyle-arkade