Utility library for signing Azure Cosmos tokens and generating headers
Перейти к файлу
microsoft-github-policy-service[bot] b2af3010df
Auto merge mandatory file pr
This pr is auto merged as it contains a mandatory file and is opened for more than 10 days.
2022-11-28 19:35:25 +00:00
.circleci Add cirleci 2018-11-17 00:09:13 -05:00
.vscode Add vs code project settings 2018-11-17 14:29:48 -05:00
src generateheaders -> generateHeaders 2018-11-17 15:05:56 -05:00
.gitignore Split browser and node code. Check bundle size 2018-11-16 22:13:47 -05:00
LICENSE Complete move to Azure org 2018-12-18 15:19:09 -05:00
README.md Complete move to Azure org 2018-12-18 15:19:09 -05:00
SECURITY.md Microsoft mandatory file 2022-07-28 16:46:43 +00:00
package-lock.json Update package-lock file 2018-12-18 15:21:56 -05:00
package.json Complete move to Azure org 2018-12-18 15:19:09 -05:00
tsconfig.json Initial commit 2018-11-16 20:11:06 -05:00
webpack.config.js Add files 2018-11-16 22:13:55 -05:00

README.md

cosmos-sign

latest npm badge CircleCI npm bundle size (minified + gzip)

Utility library for signing Azure Cosmos tokens and generating headers. Works in both node and the browser

npm install cosmos-sign

Generate a signed header value using your master key

import { generateSignature } from "cosmos-sign"

const masterKey = "< your master key here >"
const method = "GET"
const resourceId = ""
const resourceType = ""

const result = generateSignature(masterKey, method, resourceType, resourceId)

Generate a headers object instead

import { generateHeaders } from "cosmos-sign"

const masterKey = "< your master key here >"
const method = "GET"
const resourceId = ""
const resourceType = ""

const headers = generateHeaders(masterKey, method, resourceType, resourceId)

fetch("https://your-db.cosmos.azure.com/", {
  headers
})

Optionally pass a date in

import { generateSignature } from "cosmos-sign"

const masterKey = "< your master key here >";
const method = "GET";
const resourceId = "";
const resourceType = "";
const date = new Date(<tomorrow>)

const result = generateSignature(masterKey, method, resourceType, resourceId, date);

Notes

See https://docs.microsoft.com/en-us/rest/api/cosmos-db/access-control-on-cosmosdb-resources for documentation on how to generate signatures

Contributing

This project welcomes contributions and suggestions. Most contributions require you to agree to a Contributor License Agreement (CLA) declaring that you have the right to, and actually do, grant us the rights to use your contribution. For details, visit https://cla.microsoft.com.

When you submit a pull request, a CLA-bot will automatically determine whether you need to provide a CLA and decorate the PR appropriately (e.g., label, comment). Simply follow the instructions provided by the bot. You will only need to do this once across all repos using our CLA.

This project has adopted the Microsoft Open Source Code of Conduct. For more information see the Code of Conduct FAQ or contact opencode@microsoft.com with any additional questions or comments.