Azure / azure-sdk-for-node

Azure SDK for Node.js - Documentation
https://github.com/Azure/azure-sdk-for-node#documentation
MIT License
1.19k stars 566 forks source link

No support for connecting to service bus using sas (shared access tokens)??? #2251

Closed tony-gutierrez closed 5 years ago

tony-gutierrez commented 7 years ago

It's bad enough that we have to scour the web to try to discover code for generating SAS tokens for service bus, but then I find out that they are basically useless as there is no support in the Nodejs sdk for actually using them?

Why do you make a big deal out of SAS authentication in all your docs and then not even build in support into the SDK??

tony-gutierrez commented 7 years ago

Apparently the SAS token constant for the connection string is never used in this SDK at all: https://github.com/Azure/azure-sdk-for-node/search?utf8=%E2%9C%93&q=SHARED_ACCESS_SIGNATURE_NAME&type=

amarzavery commented 7 years ago

@tony-gutierrez - Extremely sorry the bad experience. The azure-sb package is not being actively maintained. Have you given a try to the amqp protocol based amqp10 package. The maintainers of this package claim to be actively testing their package against Azure Eventhubs, Servicebus queues and topics amongst other servers. Moreover, AMQP protocol is faster and resilient than HTTP.

tony-gutierrez commented 6 years ago

How are you as a company not maintaining an SDK for your own product????

mmosta commented 6 years ago

We just hit this same issue with the sdk for both PHP and Node.

tony-gutierrez commented 6 years ago

So I developed a workaround for connecting to SB with SAS tokens (via HTTPS, not AQMP) using the JS SDK. MS is a lost cause (they don't even have azure-node-sdk usage docs online, they are only in google cache: https://github.com/Azure/azure-sdk-for-node/issues/2291, https://github.com/Azure/azure-sdk-for-node/issues/2133) but maybe this will help someone.

You need to create a fake authenticationProvider class based of of the SAS auth provider class. Have it do nothing more than add the sas token to the header:

var azureCommon = require('azure-common');
var Constants = azureCommon.Constants;
var HeaderConstants = Constants.HeaderConstants;

function SharedAccessSignature(token) {
    this.token = token;
}

SharedAccessSignature.prototype.signRequest = function (webResource, callback) {
    webResource.withHeader(HeaderConstants.AUTHORIZATION, this.token);
    callback(null);
};

module.exports = SharedAccessSignature;

Then to connect to the sb do this:

const azure = require('azure');
const authenticationProviderService = require('./authenticationProvider');
authenticationProvider = new authenticationProviderService(yourSAStoken);
serviceBusService = azure.createServiceBusService({
    _serviceBusEndpointUri: 'https://xxxxxx.servicebus.windows.net' //HTTPS:// NOT SB://!!!
}, null, null, null, null, authenticationProvider);

You can periodically update the token in use by the authenticationProvider as well:

authenticationProvider = new authenticationProviderService(yourSAStoken);
tony-gutierrez commented 6 years ago

I still don't know how to use AMQP with SAS tokens. I think it involves sending a token message to a special AQMP queue after connecting, but needless to say there is 0 official JS support from Microsoft, and absolutely nothing in the SDK.

mmosta commented 6 years ago

Kudos @tony-gutierrez, will give it a shot!

tony-gutierrez commented 6 years ago

Something like this in JS might serve for AQMP, please let me know if anyone comes up with Node code along these lines! I'd love to have it but don't have time at the moment to try for it.

http://amqpnetlite.codeplex.com/SourceControl/latest#Examples/ServiceBus/ServiceBus.Cbs/Program.cs

davidh1004 commented 6 years ago

Any luck by@tony-gutierrez or anyone else in using SAS tokens with AMQP? I'm trying to solve the same problem...

amarzavery commented 6 years ago

I have recently published AzureEventHubs library in node.js that communicates over AMQP. Azure EventHubs is a subset of Azure ServiceBus (It is a service focused on efficient receive scenarios).

While developing the sdk for EventHubs, I got the CBS Auth working that uses SAS Tokens to authenticate with the Service.

This is the link to the CBS client. This is the link to the SAS Token provider.

Over the next couple of weeks I will be working on the V1 version of the azure service bus node.js client that communicates over AMQP. Hopefully that eases the pain that most of our customers have to go through for node.js.

tony-gutierrez commented 6 years ago

I have it working with rhea, but would love to see it in the official sdk. Retry strategies can be tricky though.

davidh1004 commented 6 years ago

Thanks @tony-gutierrez , I was able to get it working using your example here. Using the DescribedType on the cbs request body was what I was missing. @amarzavery looking forward to seeing this in the native SDK!

tony-gutierrez commented 6 years ago

@davidh1004 Id go with Rhea, that amqp10 lib is a little buggy. I have code if needed.

itsgk92 commented 6 years ago

+1

amarzavery commented 5 years ago

Please try out the new servicebus sdk npm i @azure/service-bus.

Source code for the new servicebus sdk can be found here.

A sample to send a message to ServiceBus Queue uses SAS token auth. In future please open service bus related issues in the new repo https://github.com/Azure/azure-sdk-for-js

onerob2000 commented 3 years ago

Please try out the new servicebus sdk npm i @azure/service-bus.

Source code for the new servicebus sdk can be found here.

A sample to send a message to ServiceBus Queue uses SAS token auth. In future please open service bus related issues in the new repo https://github.com/Azure/azure-sdk-for-js

Yeah the link to the sample is invalid... 404

marcinjahn commented 3 years ago

@amarzavery The link that you provided returns 404. Could you please update the link?

amarzavery commented 3 years ago

@Loreno10 , @onerob2000 - Please find all the samples over here https://github.com/Azure/azure-sdk-for-js/tree/master/sdk/servicebus/service-bus/samples/typescript. People keep moving samples over a period of time. General tip, try moving some folders up in the url and you should be able to find it. Everything is open source!