filestack / filestack-js

Official Javascript SDK for the Filestack API and content ingestion system.
https://www.filestack.com
MIT License
206 stars 78 forks source link

Generating policy and signature using from Javascript? #476

Open nizamani opened 2 years ago

nizamani commented 2 years ago

We want to generate policy and signature using Javascript with nestJS but couldn't find anywhere in documentation how to do this. Right now we are using Php sdk with class FilestackSecurity to generate policy and signature but we want to move everything to JS. That's why I want to ask if there a way that we can use Javascipt server side to generate policy and signature?

timofei-iatsenko commented 1 year ago
import { createHmac } from 'crypto';

const policy = Buffer.from(JSON.stringify({
  expiry: Date.now() / 1000 + 30 * 86400 * 630,
  call: ['read', 'convert'],
})).toString('base64');

const signature = createHmac('sha256', config.env.FILESTACK_SECRET_KEY)
  .update(policy)
  .digest('hex');