How to create a WebPubSubServiceClient
with JavaScript and Azure Identity
This how-to guide shows you how to create a WebPubSubServiceClient
using Microsoft Entra ID in JavaScript.
Requirements
Install @azure/identity package from npmjs.com.
npm install --save @azure/identity
Install @azure/web-pubsub package from npmjs.com
npm install @azure/web-pubsub
Sample codes
Create a
TokenCredential
with Azure Identity SDK.const { DefaultAzureCredential } = require("@azure/identity"); let credential = new DefaultAzureCredential();
credential
can be any class that inherits fromTokenCredential
class.- EnvironmentCredential
- ClientSecretCredential
- ClientCertificateCredential
- ManagedIdentityCredential
- VisualStudioCredential
- VisualStudioCodeCredential
- AzureCliCredential
To learn more, see Azure Identity client library for JavaScript
Then create a
client
withendpoint
,hub
, andcredential
.const { DefaultAzureCredential } = require("@azure/identity"); let credential = new DefaultAzureCredential(); let serviceClient = new WebPubSubServiceClient( "<endpoint>", credential, "<hub>" );
Learn how to use this client, see Azure Web PubSub service client library for JavaScript