Azure-sdk-for-js: [service-bus] Cannot use latest @azure/ms-rest-nodeauth with latest @azure/service-bus

Created on 22 Apr 2020  Â·  9Comments  Â·  Source: Azure/azure-sdk-for-js

  • Package Name: @azure/ms-rest-nodeauth && @azure/service-bus
  • Package Version: 3.0.3 && 1.1.5
  • Operating system: Windows
  • [x] nodejs

    • version: 10.16.1

  • [x] typescript

    • version: 3.7.4

Describe the bug
ApplicationTokenCredential generated using loginWithServicePrincipalSecret() function from @azure/ms-rest-nodeauth is cannot be passed to ServiceBusClient.createFromAadTokenCredentials() because of a type mismatch.

To Reproduce
Steps to reproduce the behavior:

  1. Create an instance of ApplicationTokenCredentials using loginWithServicePrincipalSecret()
  2. Try to create an instance of ServiceBusClient using that credential

Expected behavior
Should be able to create an instance of ServiceBusClient using credential without a compile time error.

Client Service Bus customer-reported question

All 9 comments

Here is the full error:

Argument of type 'ApplicationTokenCredentials' is not assignable to parameter of type 'ApplicationTokenCredentials | UserTokenCredentials | DeviceTokenCredentials | MSITokenCredentials'.
Type 'import("c:/.../.../.../node_modules/@azure/ms-rest-nodeauth/dist/lib/credentials/applicationTokenCredentials").ApplicationTokenCredentials' is not assignable to type 'import("c:/.../.../.../node_modules/@azure/amqp-common/node_modules/@azure/ms-rest-nodeauth/dist/lib/credentials/applicationTokenCredentials").ApplicationTokenCredentials'.
Property 'getTokenFromCache' is protected but type 'ApplicationTokenCredentialsBase' is not a class derived from 'ApplicationTokenCredentials'.

Downgrading to v2.0.5 of @azure/ms-rest-nodeauth produces the same error.

@daviwil can correct me on this, but I'm not sure that ms-rest-nodeauth is intended to be compatible with @azure/service-bus.

Are you not able to use @azure/identity?

@xirzec this is the documentation comment on ServiceBusClient.createFromAadTokenCredentials() :
"
Creates a ServiceBusClient for the Service Bus Namespace represented by the given host using the TokenCredentials generated using the @azure/ms-rest-nodeauth library.
...
@param credentials — The Token credentials generated by using the @azure/ms-rest-nodeauth library. It can be one of the following:
"

Oh, of course, you're using the 1.x version of service-bus. Sorry, I was looking at the version 7 preview.

Passing the credential as any manages to instantiate a client, but when I attempt to send a message to ServiceBus I get Invalid TokenAudience error. I wonder the first issue is causing the second?

'import("c:/.../.../.../node_modules/@azure/amqp-common/node_modules/@azure/ms-rest-nodeauth/dist/lib/credentials/applicationTokenCredentials"

It seems that amqp-common is depending on a different version of ms-rest-nodeauth than you are.

This seems to be because service-bus 1.1.5 depends on amqp-common 1.0.0-preview11 which incorrectly lists ms-rest-nodeauth as a dependency rather than a dev dependency.

The version it's dragging in is pretty old too: @azure/ms-rest-nodeauth: ^0.9.2

You could try depending on that version of ms-rest-nodeauth to see if that unblocks you?

@xirzec Downgrading @azure/ms-rest-nodeauth to the older version does not work because the credential generated is of type ''TokenCredentialBase"

The any trick for now is probably the right solution. Audience errors makes me think something is going wrong with your credentials. Are you specifying the tokenAudience when you call loginWithServicePrincipalSecret?

const tokenCreds = await loginWithServicePrincipalSecret(clientId, clientSecret, tenantId, {
    tokenAudience: "https://servicebus.azure.net/"
  });

Sorry for the confusion here @ysalo

This issue is actually a duplicate of #8041 which we have been working on.
We are happy to share that we just released an update to the @azure/service-bus package (
version 1.1.6) where we no longer rely on the @azure/ms-rest-nodeauth package.

This allows users to use any version of @azure/ms-rest-nodeauth directly with @azure/service-bus without TypeScript compilation errors.

Thanks for reporting!

Was this page helpful?
0 / 5 - 0 ratings