Skip to content

Commit 571bdaf

Browse files
committed
adding js sample
1 parent c61af2e commit 571bdaf

17 files changed

+17979
-39
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ src/**/*.js.map
2121
src/**/*.d.ts
2222

2323
samples/**/*/secrets.ts
24+
samples/**/*/secrets.js
2425
samples/node/secrets.json
2526
samples/browser/src/secrets.js
2627
samples/browser/src/graph-js-sdk.js

docs/ImplicitMSALAuthenticationProvider.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,7 @@ npm install msal@<version>
3636
```typescript
3737
import { UserAgentApplication } from "msal";
3838

39-
import { ImplicitMSALAuthenticationProvider } from "@microsoft/microsoft-graph-client/lib/src/authentication/ImplicitMSALAuthenticationProvider";
40-
import { MSALAuthenticationProviderOptions } from "@microsoft/microsoft-graph-client/lib/src/MSALAuthenticationProviderOptions";
39+
import { ImplicitMSALAuthenticationProvider, MSALAuthenticationProviderOptions } from "@microsoft/microsoft-graph-client/authProviders/msal";
4140

4241
// An Optional options for initializing the MSAL @see https://github.com/AzureAD/microsoft-authentication-library-for-js/wiki/MSAL-basics#configuration-options
4342
const msalConfig = {
@@ -49,6 +48,7 @@ const msalConfig = {
4948
const graphScopes = ["user.read", "mail.send"]; // An array of graph scopes
5049

5150
// Important Note: This library implements loginPopup and acquireTokenPopup flow, remember this while initializing the msal
51+
5252
// Initialize the MSAL @see https://github.com/AzureAD/microsoft-authentication-library-for-js#1-instantiate-the-useragentapplication
5353
const msalApplication = new UserAgentApplication(msalConfig);
5454
const options = new MSALAuthenticationProviderOptions(graphScopes);

docs/TokenCredentialAuthenticationProvider.md

+40-16
Original file line numberDiff line numberDiff line change
@@ -13,20 +13,44 @@
1313
###### Example of how to create and pass a token credential sample -
1414

1515
```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();
3256
```

package-lock.json

-6
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@
3737
"chai": "^4.2.0",
3838
"esm": "^3.2.25",
3939
"form-data": "^2.3.3",
40-
"fs": "0.0.1-security",
4140
"gulp": "^4.0.2",
4241
"husky": "^2.2.0",
4342
"isomorphic-fetch": "^3.0.0",

rollup.config.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,4 +32,4 @@ const config = [
3232
},
3333
];
3434

35-
export default config;
35+
export default config;

samples/tokenCredentialSamples/AuthenticationCodeFlow/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Sample of passing a AuthorizationCodeCredential to the Javascript Client Library
1+
# Sample of passing an AuthorizationCodeCredential to the Javascript Client Library
22

33
1. Register your application to enable authentication to Azure Active Directory using an authorization code that was obtained through the authorization code flow. For more details, please check the following links
44

0 commit comments

Comments
 (0)