1.5.0-alpha-8 • Published 2 years ago

@arkadecx/arkade-cloud-functions-auth v1.5.0-alpha-8

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

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

namedescdefault value
enableHmacCheckif enable hmac checktrue
hmacSecretsecrect used to encrypt''
enableOriginCheckif enable origin domain checktrue
originDomainWhitelistorigin 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
1.5.0-alpha-1

2 years ago

1.5.0-alpha-2

2 years ago

1.5.0-alpha-3

2 years ago

1.5.0-alpha-4

2 years ago

1.5.0-alpha-5

2 years ago

1.5.0-alpha-7

2 years ago

1.5.0-alpha-8

2 years ago

1.4.0

3 years ago

1.3.0

3 years ago

1.2.0

3 years ago

1.1.0

3 years ago

1.0.0

3 years ago