|
13 | 13 | ###### Example of how to create and pass a token credential sample -
|
14 | 14 |
|
15 | 15 | ```typescript
|
16 |
| - // Import the TokenCredential class that you wish to use. This examples uses a Client SecretCredential |
17 |
| - import { ClientSecretCredential } from "@azure/identity"; |
18 |
| - import { TokenCredentialAuthenticationProvider, TokenCredentialAuthenticationProviderOptions } from "@microsoft/microsoft-graph-client/authProviders/azureTokenCredentials"; |
19 |
| - // Create an instance of the TokenCredential Class that is imported |
20 |
| - const tokenCredential = new ClientSecretCredential("your_tenantId", "your_clientId", "your_clientSecret"); |
21 |
| - |
22 |
| - // Set your scopes and options for TokenCredential.getToken (Check the ` interface GetTokenOptions` in (TokenCredential Implementation)[https://github.com/Azure/azure-sdk-for-js/blob/master/sdk/core/core-auth/src/tokenCredential.ts]) |
23 |
| - const options:TokenCredentialAuthenticationProviderOptions = { scopes: [scopes], getTokenoptions: <> } |
24 |
| - |
25 |
| - // Create an instance of the TokenCredentialAuthenticationProvider by passing the tokenCredential instance and options to the constructor |
26 |
| - const authProvider = new TokenCredentialAuthenticationProvider(tokenCredential, options); |
27 |
| - const client = Client.initWithMiddleware({ |
28 |
| - debugLogging: true, |
29 |
| - authProvider: authProvider, |
30 |
| - }); |
31 |
| - const res = await client.api("/users/").get(); |
| 16 | +// Import the TokenCredential class that you wish to use. This examples uses a Client SecretCredential |
| 17 | + |
| 18 | +import { ClientSecretCredential } from "@azure/identity"; |
| 19 | +import { TokenCredentialAuthenticationProvider, TokenCredentialAuthenticationProviderOptions } from "@microsoft/microsoft-graph-client/authProviders/azureTokenCredentials"; |
| 20 | + |
| 21 | +// Create an instance of the TokenCredential Class that is imported |
| 22 | +const tokenCredential = new ClientSecretCredential("your_tenantId", "your_clientId", "your_clientSecret"); |
| 23 | + |
| 24 | +// Set your scopes and options for TokenCredential.getToken (Check the ` interface GetTokenOptions` in (TokenCredential Implementation)[https://github.com/Azure/azure-sdk-for-js/blob/master/sdk/core/core-auth/src/tokenCredential.ts]) |
| 25 | + |
| 26 | +const options: TokenCredentialAuthenticationProviderOptions = { scopes: [scopes], getTokenoptions }; |
| 27 | + |
| 28 | +// Create an instance of the TokenCredentialAuthenticationProvider by passing the tokenCredential instance and options to the constructor |
| 29 | +const authProvider = new TokenCredentialAuthenticationProvider(tokenCredential, options); |
| 30 | +const client = Client.initWithMiddleware({ |
| 31 | + debugLogging: true, |
| 32 | + authProvider: authProvider, |
| 33 | +}); |
| 34 | +const res = await client.api("/users/").get(); |
| 35 | +``` |
| 36 | + |
| 37 | +```javascript |
| 38 | +// Import the TokenCredential class that you wish to use. This examples uses a Client SecretCredential |
| 39 | + |
| 40 | +const { ClientSecretCredential } = require("@azure/identity"); |
| 41 | +const { Client } = require("@microsoft/microsoft-graph-client"); |
| 42 | +const { TokenCredentialAuthenticationProvider } = require("@microsoft/microsoft-graph-client/authProviders/azureTokenCredentials"); |
| 43 | + |
| 44 | +// Create an instance of the TokenCredential Class that is imported |
| 45 | +const credential = new ClientSecretCredential(tenantId, clientId, clientSecret); |
| 46 | + |
| 47 | +// Set your scopes and options for TokenCredential.getToken (Check the ` interface GetTokenOptions` in (TokenCredential Implementation)[https://github.com/Azure/azure-sdk-for-js/blob/master/sdk/core/core-auth/src/tokenCredential.ts]) |
| 48 | + |
| 49 | +const authProvider = new TokenCredentialAuthenticationProvider(credential, { scopes: [scopes] }); |
| 50 | + |
| 51 | +const client = Client.initWithMiddleware({ |
| 52 | + debugLogging: true, |
| 53 | + authProvider, |
| 54 | +}); |
| 55 | +const res = await client.api("/users/").get(); |
32 | 56 | ```
|
0 commit comments