# @neurocode.io/azure-sas-token

> Cloudflare worker app to issue limited access to Azure Storage resources using shared access signatures (SAS)

Latest version **1.3.0** (published 2023-01-14) · MIT license · 0 weekly downloads

## Install

```sh
npm install @neurocode.io/azure-sas-token
pnpm add @neurocode.io/azure-sas-token
yarn add @neurocode.io/azure-sas-token
bun add @neurocode.io/azure-sas-token
```

## Health

**Score 30/100 (F)** — status: abandoned.

Positive: has types; esm support; no vulnerabilities; high quality score.

Warnings: low downloads.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.3.0 |
| Published | 2023-01-14 |
| First published | 2020-09-27 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 0 |
| Unpacked size | 11.4 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 3 |
| Author | neurocode I/O GmbH |
| Maintainers | bdonchev |
| Keywords | azure-sas-token, cloudflare-azure-sas, cloudflare-workers |

## Links

- npm: https://www.npmjs.com/package/@neurocode.io/azure-sas-token
- Repository: https://github.com/neurocode-io/azure-sas-token
- Homepage: https://github.com/neurocode-io/azure-sas-token/tree/master/README.md
- npm.io page: https://npm.io/package/@neurocode.io/azure-sas-token

## Alternatives

- [cron](https://npm.io/package/cron.md) — 4.9M weekly downloads
- [@vercel/queue](https://npm.io/package/@vercel/queue.md) — 731.6K weekly downloads
- [create-sonicjs](https://npm.io/package/create-sonicjs.md) — 1.6K weekly downloads
- [@exellix/jobs-api](https://npm.io/package/@exellix/jobs-api.md) — 941 weekly downloads
- [@forwardimpact/libskill](https://npm.io/package/@forwardimpact/libskill.md) — 575 weekly downloads

## Recent versions

- 1.3.0 (latest) — 2023-01-14
- 1.2.2 — 2020-09-30
- 1.2.1 — 2020-09-30
- 1.2.0 — 2020-09-30
- 1.1.0 — 2020-09-27
- 1.0.1 — 2020-09-27
- 1.0.0 — 2020-09-27

## README

# Azure-SAS-token

[![Quality Gate Status](https://sonarcloud.io/api/project_badges/measure?project=NeuroCode-io_azure-sas-token&metric=alert_status)](https://sonarcloud.io/dashboard?id=NeuroCode-io_azure-sas-token)
[![Maintainability Rating](https://sonarcloud.io/api/project_badges/measure?project=NeuroCode-io_azure-sas-token&metric=sqale_rating)](https://sonarcloud.io/dashboard?id=NeuroCode-io_azure-sas-token)
[![Reliability Rating](https://sonarcloud.io/api/project_badges/measure?project=NeuroCode-io_azure-sas-token&metric=reliability_rating)](https://sonarcloud.io/dashboard?id=NeuroCode-io_azure-sas-token)
[![Security Rating](https://sonarcloud.io/api/project_badges/measure?project=NeuroCode-io_azure-sas-token&metric=security_rating)](https://sonarcloud.io/dashboard?id=NeuroCode-io_azure-sas-token)
[![Vulnerabilities](https://sonarcloud.io/api/project_badges/measure?project=NeuroCode-io_azure-sas-token&metric=vulnerabilities)](https://sonarcloud.io/dashboard?id=NeuroCode-io_azure-sas-token)


Generate Azure SAS tokens on the edge with cloudflare workers and this library. 
This library has zero depdendencies.

We used it in our [sepa-form-recogizer](https://neurocode.io/blog/sepa-payment-recognizer?s=github) API

## What is a SAS token?

![sas](./sas-storage-uri.png)


SAS token is a string that you generate and give your client for temp access to your Azure storage. The Azure Storage client library does not work in the browser since it uses NodeJS crypto to compute the HMAC SHA256.

This library uses webCrypto to compute the HMAC SHA256 and is thus compatible with cloudflare workers.


## Install

Use either npm or yarn
```
npm i @neurocode.io/azure-sas-token
yarn add @neurocode.io/azure-sas-token
```

## How to use the library

```ts
import { createBlobSas } from '@neurocode.io/azure-sas-token'

const expireInMin = 5

const { blobSasUrl } = await createBlobSas({
      accountKey: 'yourStorageAccountKey',
      accountName: 'yourAccountName',
      containerName: 'youStorageContainerName',
      blobName: 'someBlob.txt',
      permissions: 'rw',
      expiresOn: new Date(new Date().valueOf() + expireInMin * 60 * 1000)
})

```

Be careful with **startsOn** property. If you set the start time for a SAS to the current time, you may observe failures occurring intermittently for the first few minutes due to different machines having slight variations of the current time (known as clock skew). 

In general, set the start time to be at least 15 minutes in the past. Or, don't set it at all :)



## Current implementation

- [x] Blob SAS token
- [ ] Container SAS token
- [ ] Account SAS token

---
_Source: https://npm.io/package/@neurocode.io/azure-sas-token · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
