You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
const cosmosClient = new CosmosClient({ endpoint, key });
299
+
// New instance of CosmosClient class using a connection string
300
+
const cosmosClient = new CosmosClient(process.env.COSMOS_CONNECTION_STRING);
309
301
```
310
302
311
303
### Connect using the Microsoft Identity Platform
@@ -335,16 +327,18 @@ The **@azure/identity** npm package contains core authentication functionality t
335
327
```
336
328
#### Create CosmosClient with default credential implementation
337
329
338
-
If you're testing on a local machine, or your application will run on Azure services with direct support for managed identities, obtain an OAuth token by creating a [``DefaultAzureCredential``](/javascript/api/@azure/identity/defaultazurecredential) instance.
330
+
If you're testing on a local machine, or your application will run on Azure services with direct support for managed identities, obtain an OAuth token by creating a [``DefaultAzureCredential``](/javascript/api/@azure/identity/defaultazurecredential) instance. Then create a new instance of the **CosmosClient** class with the ``COSMOS_ENDPOINT`` environment variable and the **TokenCredential** object as parameters.
Create a new instance of the **CosmosClient** class with the ``COSMOS_ENDPOINT`` environment variable and the **TokenCredential** object as parameters.
345
-
346
-
```javascript
336
+
const credential = new DefaultAzureCredential();
347
337
338
+
const cosmosClient = new CosmosClient({
339
+
endpoint,
340
+
aadCredentials: credential
341
+
});
348
342
```
349
343
350
344
#### Create CosmosClient with a custom credential implementation
@@ -353,15 +347,24 @@ If you plan to deploy the application out of Azure, you can obtain an OAuth toke
353
347
354
348
For this example, we create a [``ClientSecretCredential``](/javascript/api/@azure/identity/tokencredential) instance by using client and tenant identifiers, along with a client secret.
355
349
356
-
```javascript
357
-
```
358
-
359
350
You can obtain the client ID, tenant ID, and client secret when you register an application in Azure Active Directory (AD). For more information about registering Azure AD applications, see [Register an application with the Microsoft identity platform](../../active-directory/develop/quickstart-register-app.md).
360
351
361
352
Create a new instance of the **CosmosClient** class with the ``COSMOS_ENDPOINT`` environment variable and the **TokenCredential** object as parameters.
0 commit comments