Skip to content

Commit f813590

Browse files
Merge pull request #179 from microsoftgraph/v2.0.0
Version 2.0.0
2 parents d571846 + 032f559 commit f813590

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+4584
-2294
lines changed

.gitignore

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,7 @@ src/**/*.d.ts
2020

2121
samples/node/secrets.json
2222
samples/browser/src/secrets.js
23-
samples/browser/src/graph-js-sdk-core.js
24-
samples/browser/src/graph-js-sdk-web.js
23+
samples/browser/src/graph-js-sdk.js
2524
samples/browser/src/graph-es-sdk.js
2625

2726
spec/**/*.js

.huskyrc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
22
"hooks": {
3-
"pre-commit": "lint-staged && npm run lint && npm run test"
3+
"pre-commit": "npm run pre-build && git add src/Version.ts && lint-staged && npm run lint && npm run test"
44
}
55
}

README.md

Lines changed: 40 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -16,24 +16,32 @@ The Microsoft Graph JavaScript client library is a lightweight wrapper around th
1616
npm install @microsoft/microsoft-graph-client
1717
```
1818

19-
import `@microsoft/microsoft-graph-client` into your module.
19+
import `@microsoft/microsoft-graph-client` into your module and also you will need polyfills for fetch like [isomorphic-fetch](https://www.npmjs.com/package/isomorphic-fetch).
2020

2121
```typescript
22+
import "isomorphic-fetch";
2223
import { Client } from "@microsoft/microsoft-graph-client";
2324
```
2425

2526
### Via Script Tag
2627

27-
Include `lib/graph-js-sdk-web.js` in your page.
28+
Include [graph-js-sdk.js](https://cdn.jsdelivr.net/npm/@microsoft/microsoft-graph-client/lib/graph-js-sdk.js) in your HTML page.
2829

2930
```HTML
30-
<script type="text/javascript" src="graph-js-sdk-web.js"></script>
31+
<script type="text/javascript" src="https://cdn.jsdelivr.net/npm/@microsoft/microsoft-graph-client/lib/graph-js-sdk.js"></script>
3132
```
3233

33-
Incase if your application ships with [es6-promise](https://www.npmjs.com/package/es6-promise) and [isomorphic-fetch](https://www.npmjs.com/package/isomorphic-fetch) just use `lib/graph-js-sdk-core.js`
34+
In case your browser doesn't have support for [Fetch](https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API) [[support](https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API#Browser_compatibility)] or [Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise) [[support](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise#Browser_compatibility)], you need to use polyfills like [github/fetch](https://github.com/github/fetch) for fetch and [es6-promise](https://github.com/stefanpenner/es6-promise) for promise.
3435

3536
```HTML
36-
<script type="text/javascript" src="graph-js-sdk-core.js"></script>
37+
<!-- polyfilling promise -->
38+
<script type="text/javascript" src="https://cdn.jsdelivr.net/npm/es6-promise/dist/es6-promise.auto.min.js"></script>
39+
40+
<!-- polyfilling fetch -->
41+
<script type="text/javascript" src="https://cdn.jsdelivr.net/npm/whatwg-fetch/dist/fetch.umd.min.js"></script>
42+
43+
<!-- depending on your browser you might wanna include babel polyfill -->
44+
<script type="text/javascript" src="https://cdn.jsdelivr.net/npm/@babel/[email protected]/dist/polyfill.min.js"></script>
3745
```
3846

3947
## Getting started
@@ -47,11 +55,11 @@ Register your application to use Microsoft Graph API using one of the following
4755

4856
### 2. Authenticate for the Microsoft Graph service
4957

50-
The Microsoft Graph JavaScript Client Library has an adapter implementation ([MSALAuthenticationProvider](src/MSALAuthenticationProvider.ts)) for [MSAL](https://github.com/AzureAD/microsoft-authentication-library-for-js/tree/dev/lib/msal-core) (Microsoft Authentication Library) which takes care of getting the `accessToken`. MSAL library does not ship with this library, user has to include it externally (For including MSAL, refer [this](https://github.com/AzureAD/microsoft-authentication-library-for-js/tree/dev/lib/msal-core#installation)).
58+
The Microsoft Graph JavaScript Client Library has an adapter implementation ([ImplicitMSALAuthenticationProvider](src/ImplicitMSALAuthenticationProvider.ts)) for [MSAL](https://github.com/AzureAD/microsoft-authentication-library-for-js/tree/dev/lib/msal-core) (Microsoft Authentication Library) which takes care of getting the `accessToken`. MSAL library does not ship with this library, user has to include it externally (For including MSAL, refer [this](https://github.com/AzureAD/microsoft-authentication-library-for-js/tree/dev/lib/msal-core#installation)).
5159

52-
> **Note:** MSAL is supported only for frontend applications, for server-side authentication you have to implement your own AuthenticationProvider. Refer implementing [Custom Authentication Provider](./docs/CustomAuthenticationProvider.md).
60+
> **Important Note:** MSAL is supported only for frontend applications, for server-side authentication you have to implement your own AuthenticationProvider. Learn how you can create a [Custom Authentication Provider](./docs/CustomAuthenticationProvider.md).
5361
54-
#### Creating an instance of MSALAuthenticationProvider in browser environment
62+
#### Creating an instance of ImplicitMSALAuthenticationProvider in browser environment
5563

5664
Refer devDependencies in [package.json](./package.json) for the compatible msal version and update that version in below.
5765

@@ -60,20 +68,24 @@ Refer devDependencies in [package.json](./package.json) for the compatible msal
6068
```
6169

6270
```typescript
63-
const clientId = "your_client_id"; // Client Id of the registered application
64-
const callback = (errorDesc, token, error, tokenType) => {};
65-
// An Optional options for initializing the MSAL @see https://github.com/AzureAD/microsoft-authentication-library-for-js/wiki/MSAL-basics#configuration-options
66-
const options = {
67-
redirectUri: "Your redirect URI",
71+
72+
// Configuration options for MSAL @see https://github.com/AzureAD/microsoft-authentication-library-for-js/wiki/MSAL.js-1.0.0-api-release#configuration-options
73+
const msalConfig = {
74+
auth: {
75+
clientId: "your_client_id"; // Client Id of the registered application
76+
redirectUri: "your_redirect_uri",
77+
},
6878
};
6979
const graphScopes = ["user.read", "mail.send"]; // An array of graph scopes
7080

71-
// Initialize the MSAL @see https://github.com/AzureAD/microsoft-authentication-library-for-js/wiki/MSAL-basics#initialization-of-msal
72-
const userAgentApplication = new Msal.UserAgentApplication(clientId, undefined, callback, options);
73-
const authProvider = new MicrosoftGraph.MSALAuthenticationProvider(userAgentApplication, graphScopes);
81+
// Important Note: This library implements loginPopup and acquireTokenPopup flow, remember this while initializing the msal
82+
// Initialize the MSAL @see https://github.com/AzureAD/microsoft-authentication-library-for-js#1-instantiate-the-useragentapplication
83+
const msalApplication = new Msal.UserAgentApplication(msalConfig);
84+
const options = new MicrosoftGraph.MSALAuthenticationProviderOptions(graphScopes);
85+
const authProvider = new MicrosoftGraph.ImplicitMSALAuthenticationProvider(msalApplication, options);
7486
```
7587

76-
#### Creating an instance of MSALAuthenticationProvider in node environment
88+
#### Creating an instance of ImplicitMSALAuthenticationProvider in node environment
7789

7890
Refer devDependencies in [package.json](./package.json) for the compatible msal version and update that version in below.
7991

@@ -84,19 +96,22 @@ npm install msal@<version>
8496
```typescript
8597
import { UserAgentApplication } from "msal";
8698

87-
import { MSALAuthenticationProvider } from "./node_modules/@microsoft/microsoft-graph-client/lib/src/MSALAuthenticationProvider";
99+
import { ImplicitMSALAuthenticationProvider } from "./node_modules/@microsoft/microsoft-graph-client/lib/src/ImplicitMSALAuthenticationProvider";
88100

89-
const clientId = "your_client_id"; // Client Id of the registered application
90-
const callback = (errorDesc, token, error, tokenType) => {};
91101
// An Optional options for initializing the MSAL @see https://github.com/AzureAD/microsoft-authentication-library-for-js/wiki/MSAL-basics#configuration-options
92-
const options = {
93-
redirectUri: "Your redirect URI",
102+
const msalConfig = {
103+
auth: {
104+
clientId: "your_client_id", // Client Id of the registered application
105+
redirectUri: "your_redirect_uri",
106+
},
94107
};
95108
const graphScopes = ["user.read", "mail.send"]; // An array of graph scopes
96109

97-
// Initialize the MSAL @see https://github.com/AzureAD/microsoft-authentication-library-for-js/wiki/MSAL-basics#initialization-of-msal
98-
const userAgentApplication = new UserAgentApplication(clientId, undefined, callback, options);
99-
const authProvider = new MSALAuthenticationProvider(userAgentApplication, graphScopes);
110+
// Important Note: This library implements loginPopup and acquireTokenPopup flow, remember this while initializing the msal
111+
// Initialize the MSAL @see https://github.com/AzureAD/microsoft-authentication-library-for-js#1-instantiate-the-useragentapplication
112+
const msalApplication = new UserAgentApplication(msalConfig);
113+
const options = new MicrosoftGraph.MSALAuthenticationProviderOptions(graphScopes);
114+
const authProvider = new ImplicitMSALAuthenticationProvider(msalApplication, options);
100115
```
101116

102117
User can integrate own preferred authentication library by implementing `IAuthenticationProvider` interface. Refer implementing [Custom Authentication Provider](./docs/CustomAuthenticationProvider.md).

babel.config.js

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
module.exports = function(api) {
2+
api.cache(true);
3+
const presets = [
4+
[
5+
"@babel/preset-env",
6+
{
7+
targets: {
8+
ie: 11,
9+
},
10+
},
11+
],
12+
];
13+
14+
const plugins = [
15+
[
16+
"@babel/plugin-transform-runtime",
17+
{
18+
absoluteRuntime: false,
19+
corejs: false,
20+
helpers: true,
21+
regenerator: true,
22+
useESModules: false,
23+
},
24+
],
25+
];
26+
return {
27+
presets,
28+
plugins,
29+
};
30+
};

browser-wrapper.js

Lines changed: 0 additions & 11 deletions
This file was deleted.

browserify-with-dependencies.js

Lines changed: 0 additions & 15 deletions
This file was deleted.

browserify.js

Lines changed: 0 additions & 17 deletions
This file was deleted.

docs/CallingPattern.md

Lines changed: 19 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -4,46 +4,45 @@ All calls to Microsoft Graph are chained together starting with **.api()**, then
44

55
## Path supports the following formats
66

7-
* `me`
8-
* `/me`
9-
* `https://graph.microsoft.com/v1.0/me`
10-
* `https://graph.microsoft.com/beta/me`
11-
* `me/events?$filter=startswith(subject, "Adventure")`
7+
- `me`
8+
- `/me`
9+
- `https://graph.microsoft.com/v1.0/me`
10+
- `https://graph.microsoft.com/beta/me`
11+
- `me/events?$filter=startswith(subject, "Adventure")`
1212

1313
## Promise based calling
1414

1515
Getting user details with `async`/`await`,
1616

1717
```typescript
1818
try {
19-
let res = await client.api("/me").get();
20-
console.log(res);
19+
let res = await client.api("/me").get();
20+
console.log(res);
2121
} catch (error) {
22-
throw error;
22+
throw error;
2323
}
2424
```
2525

2626
Getting user details with `then`/`catch`,
2727

2828
```typescript
2929
client
30-
.api('/me')
31-
.get()
32-
.then((res) => {
33-
console.log(res);
34-
}).catch((err) => {
35-
console.log(err);
36-
});
30+
.api("/me")
31+
.get()
32+
.then((res) => {
33+
console.log(res);
34+
})
35+
.catch((err) => {
36+
console.log(err);
37+
});
3738
```
3839

3940
## Callback based calling
4041

4142
Getting user details by passing `callback`,
4243

4344
```typescript
44-
client
45-
.api('/me')
46-
.get((err, res, rawResponse) => {
47-
console.log(res);
48-
});
45+
client.api("/me").get((err, res) => {
46+
console.log(res);
47+
});
4948
```

docs/CreatingClientInstance.md

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,24 @@ In order to instantiate a Client object, one has to pass in the `authProvider` o
1010

1111
Pass an instance of a class which implements [AuthenticationProvider](../src/IAuthenticationProvider.ts) interface as `authProvider` in [ClientOptions](../src/IClientOptions.ts), which will instantiate the Client with default set of middleware chain.
1212

13-
Library is shipped with one such authentication provider named [MSALAuthenticationProvider](../src/MSALAuthenticationProvider.ts). This MSALAuthenticationProvider depends on an authentication library [msal.js](https://github.com/AzureAD/microsoft-authentication-library-for-js) which is not shipped along with the library, one has to externally include msal.js to use MSALAuthenticationProvider.
13+
Library is shipped with one such authentication provider named [ImplicitMSALAuthenticationProvider](../src/ImplicitMSALAuthenticationProvider.ts). This ImplicitMSALAuthenticationProvider depends on an authentication library [msal.js](https://github.com/AzureAD/microsoft-authentication-library-for-js) which is not shipped along with the library, one has to externally include msal.js to use ImplicitMSALAuthenticationProvider.
1414

1515
```typescript
16-
// Instantiating Client with MSALAuthenticationProvider
16+
// Instantiating Client with ImplicitMSALAuthenticationProvider
17+
18+
// An Optional options for initializing the MSAL @see https://github.com/AzureAD/microsoft-authentication-library-for-js/wiki/MSAL-basics#configuration-options
19+
const msalConfig = {
20+
auth: {
21+
clientId: <CLIENT_ID> // Client Id of the registered application
22+
},
23+
};
24+
25+
// Important Note: This library implements loginPopup and acquireTokenPopup flow, remember this while initializing the msal
26+
// Initialize the MSAL @see https://github.com/AzureAD/microsoft-authentication-library-for-js#1-instantiate-the-useragentapplication
27+
const msalApplication = new UserAgentApplication(msalConfig);
28+
const options = new MicrosoftGraph.MSALAuthenticationProviderOptions(<SCOPES>); // An array of graph scopes
1729
let clientOptions: ClientOptions = {
18-
authProvider: new MSALAuthenticationProvider(<CLIENT_ID>, <SCOPES>, <OPTIONS>)
30+
authProvider: new ImplicitMSALAuthenticationProvider(msalApplication, options)
1931
};
2032
const client = Client.initWithMiddleware(clientOptions);
2133
```

docs/CustomMiddlewareChain.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,14 +68,14 @@ Can use own middlewares and the ones shipped with the library [[Here](../src/mid
6868

6969
Using AuthenticationHandler [one shipped with the library] and MyLoggingHandler, and MyHttpMessageHandler [custom ones] to create a middleware chain here.
7070

71-
NOTE: Instead of MSALAuthenticationProvider, one can provide his own Authentication Handler. For more about using custom authentication provider, refer [here](./CustomAuthenticationProvider.md).
71+
NOTE: Instead of ImplicitMSALAuthenticationProvider, one can provide his own Authentication Handler. For more about using custom authentication provider, refer [here](./CustomAuthenticationProvider.md).
7272

7373
```typescript
74-
import { MSALAuthenticationProvider } from "@microsoft/microsoft-graph-client";
74+
import { ImplicitMSALAuthenticationProvider } from "@microsoft/microsoft-graph-client";
7575
import { MyLoggingHandler } from "./MyLoggingHandler";
7676
import { MyHttpMessageHandler } from "./MyHttpMessageHandler";
7777

78-
let authProvider = new MSALAuthenticationProvider("<CLIENT_ID>", ["user.read"]);
78+
let authProvider = new ImplicitMSALAuthenticationProvider("<CLIENT_ID>", ["user.read"]);
7979
let authenticationHandler = new AuthenticationHandler(authProvider);
8080
let myLoggingHandler = new MyLoggingHandler();
8181
let myHttpMessageHandler = new MyHttpMessageHandler();

0 commit comments

Comments
 (0)