A simple JavaScript Azure SAS token generator
The current project is about how to programmatically generate a Shared Access Signature (SAS) token to use with Postman in order to post messages to Azure Service Bus Topic/Queue.
After googling for a while in order to generate the necessary token, to post messages to Azure service bus, I noticed that there is no clear explanations, how to achieve it in JavaScript!!
I'm proud to offer you a simple JS way to generate Azure SAS token - using node - or angular.
azure sas token generation in node
Don't forget to let me a Star ⭐ :-)
npm install azure-sas-token
import { createSharedAccessToken } from 'azure-sas-token';
// default token validity is 7 days
let sasToken = createSharedAccessToken('https://<service namespace>.servicebus.windows.net/<topic name or queue>',
'<signature key name>',
'<signature hash>');
console.log(`sasToken: ${sasToken}`);
// Specify your own validity in secs, two hours in this example
sasToken = createSharedAccessToken('https://<service namespace>.servicebus.windows.net/<topic name or queue>',
'<signature key name>',
'<signature hash>',
60 * 60 * 2);
console.log(`sasToken: ${sasToken}`);
If you prefer a simplier way to get fastly a token, you could use my angular application azure-sas-token from here:
https://ah584d.github.io/azure-sas-token/
This is the same application of the 'angular' folder, you can use the online version, or to checkout the repository and run it locally on your computer.
cd azure-sas-token/angular
npm install
npm run start
POST https://<yournamespace>.servicebus.windows.net/<yourentity>/messages
Content-Type: application/json
Authorization: SharedAccessSignature sr=https%3A%2F%2F<yournamespace>.servicebus.windows.net%2F<yourentity>&sig=<your token generated by this repository code>&se=1438205742&skn=KeyName
The application is totally safe, nothing is saved on third party, no request is sent outside, everything is handled in client side
https://github.com/ah584d/azure-send-message-to-service-bus-with-postman
POST https://<yournamespace>.servicebus.windows.net/<yourentity>/messages
Content-Type: application/json
Authorization: SharedAccessSignature sr=https%3A%2F%2F<yournamespace>.servicebus.windows.net%2F<yourentity>&sig=<your token generated by this repository code>&se=1438205742&skn=KeyName
Done!
The only related topic that I founded on Microsoft Azure help
https://docs.microsoft.com/en-us/rest/api/eventhub/generate-sas-token
Icon from: http://www.kameleon.pics
A short snippet describing the license (MIT, Apache etc)
MIT © Avraham Hamu