1.5.0-alpha-8 • Published 2 years ago
@arkadecx/arkade-cloud-functions-auth v1.5.0-alpha-8
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
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