From 7987bbdcea311fdbff41891b4c57ec34ad5a2f7e Mon Sep 17 00:00:00 2001 From: Richard Park Date: Tue, 29 Sep 2020 15:26:24 -0700 Subject: [PATCH 1/3] Update readme to contain an actual snippet of code showing the construction of the service bus client. --- sdk/servicebus/service-bus/README.md | 49 ++++++++++++++++++++++------ 1 file changed, 39 insertions(+), 10 deletions(-) diff --git a/sdk/servicebus/service-bus/README.md b/sdk/servicebus/service-bus/README.md index 52659b66fdae..e07b62a7951b 100644 --- a/sdk/servicebus/service-bus/README.md +++ b/sdk/servicebus/service-bus/README.md @@ -55,18 +55,45 @@ To use this client library in the browser, first you need to use a bundler. For ### Authenticate the client -Interaction with Service Bus starts with an instance of the [ServiceBusClient][sbclient] class. +Interaction with Service Bus starts with an instance of the [ServiceBusClient][sbclient] class. You can +authenticate to Service Bus using a connection string or using a service principal. -You can instantiate this class using its constructors: +#### Using a connection string -- [Create using a connection string][sbclient_constructor] - - This method takes the connection string to your Service Bus instance. You can get the connection string - from the Azure portal. -- [Create using a TokenCredential][sbclient_tokencred_overload] - - This method takes the host name of your Service Bus instance and a credentials object that you need - to generate using the [@azure/identity](https://www.npmjs.com/package/@azure/identity) - library. The host name is of the format `name-of-service-bus-instance.servicebus.windows.net`. - If you're using an own implementation of the `TokenCredential` interface against AAD, then set the "scopes" for service-bus to be `["https://servicebus.azure.net//user_impersonation"]` to get the appropriate token. +This method takes the connection string to your Service Bus instance. You can get +the connection string from the Azure portal. + +```javascript +const { ServiceBusClient } = require("@azure/service-bus"); + +const serviceBusClient = new ServiceBusClient(connectionString); +``` + +More information about this constructor is available in the [API documentation][sbclient_constructor]. + +#### Using an Azure Active Directory Credential + +Authentication with Azure Active Directory uses the [Azure Identity library][azure_identity]. + +The example below uses the [DefaultAzureCredential][defaultazurecredential], one of many +available credential providers from the `@azure/identity` library. + +```javascript +const { ServiceBusClient } = require("@azure/service-bus"); +const { DefaultAzureCredential } = require("@azure/identity"); + +const endpoint = ".servicebus.windows.net"; +const credential = new DefaultAzureCredential(); +const serviceBusClient = new ServiceBusClient(endpoint, credential); +``` + + NOTE: If you're using your own implementation of the `TokenCredential` interface + against AAD, then set the "scopes" for service-bus to the following to get + the appropriate token: + + ["https://servicebus.azure.net//user_impersonation"] + +More information about this constructor is available in the [API documentation][sbclient_tokencred_overload] ### Key concepts @@ -342,6 +369,8 @@ If you'd like to contribute to this library, please read the [contributing guide ![Impressions](https://azure-sdk-impressions.azurewebsites.net/api/impressions/azure-sdk-for-js%2Fsdk%2Fservicebus%2Fservice-bus%2FREADME.png) [apiref]: https://aka.ms/azsdk/js/service-bus/docs +[azure_identity]: https://github.com/Azure/azure-sdk-for-js/blob/master/sdk/identity/identity/README.md +[defaultazurecredential]: https://github.com/Azure/azure-sdk-for-js/tree/master/sdk/identity/identity#defaultazurecredential [sbclient]: https://docs.microsoft.com/javascript/api/%40azure/service-bus/servicebusclient?view=azure-node-preview [sbclient_constructor]: https://docs.microsoft.com/javascript/api/@azure/service-bus/servicebusclient?view=azure-node-preview#servicebusclient-string--servicebusclientoptions- [sbclient_tokencred_overload]: https://docs.microsoft.com/javascript/api/@azure/service-bus/servicebusclient?view=azure-node-preview#servicebusclient-string--tokencredential--servicebusclientoptions- From 8b2b30525756a0612b197060b05bc3cf3d9d2e78 Mon Sep 17 00:00:00 2001 From: Richard Park <51494936+richardpark-msft@users.noreply.github.com> Date: Tue, 29 Sep 2020 16:10:26 -0700 Subject: [PATCH 2/3] Update README.md Be consistent in terminology. --- sdk/servicebus/service-bus/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sdk/servicebus/service-bus/README.md b/sdk/servicebus/service-bus/README.md index e07b62a7951b..1e373b34c0be 100644 --- a/sdk/servicebus/service-bus/README.md +++ b/sdk/servicebus/service-bus/README.md @@ -56,7 +56,7 @@ To use this client library in the browser, first you need to use a bundler. For ### Authenticate the client Interaction with Service Bus starts with an instance of the [ServiceBusClient][sbclient] class. You can -authenticate to Service Bus using a connection string or using a service principal. +authenticate to Service Bus using a connection string or using an Azure Active Directory credential. #### Using a connection string From 3b7a018494b25be5002efab8595171df0178e37c Mon Sep 17 00:00:00 2001 From: Richard Park <51494936+richardpark-msft@users.noreply.github.com> Date: Wed, 30 Sep 2020 09:30:03 -0700 Subject: [PATCH 3/3] The right construct here was > (blockquote) vs what I was doing (continuing the code block!) --- sdk/servicebus/service-bus/README.md | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/sdk/servicebus/service-bus/README.md b/sdk/servicebus/service-bus/README.md index 1e373b34c0be..96e6ae69703f 100644 --- a/sdk/servicebus/service-bus/README.md +++ b/sdk/servicebus/service-bus/README.md @@ -87,11 +87,13 @@ const credential = new DefaultAzureCredential(); const serviceBusClient = new ServiceBusClient(endpoint, credential); ``` - NOTE: If you're using your own implementation of the `TokenCredential` interface - against AAD, then set the "scopes" for service-bus to the following to get - the appropriate token: +> NOTE: If you're using your own implementation of the `TokenCredential` interface +> against AAD, then set the "scopes" for service-bus to the following to get +> the appropriate token: - ["https://servicebus.azure.net//user_impersonation"] +> ```typescript +> ["https://servicebus.azure.net//user_impersonation"] +> ``` More information about this constructor is available in the [API documentation][sbclient_tokencred_overload]