Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
d274967
Changes:
muthurathinam-m May 7, 2019
454c0a3
Updated readme with installation guide
muthurathinam-m May 7, 2019
4b1406b
Changes:
muthurathinam-m May 8, 2019
da2c5e3
Added tests for middleware util append request header method
muthurathinam-m May 8, 2019
ee554ad
Upgraded to msal 1.0.0 and made corresponding changes (breaking chang…
muthurathinam-m May 9, 2019
edd80e4
fix readme typo
muthurathinam-m May 9, 2019
fe087b7
Merge remote-tracking branch 'origin/dev' into v2.0.0
muthurathinam-m May 21, 2019
10217b1
Bug Fixes:
muthurathinam-m May 21, 2019
ad564db
Merge remote-tracking branch 'origin/dev' into v2.0.0
muthurathinam-m May 24, 2019
47093b1
Renamed MSALAuthenticationProvider and MSALAuthenticationProviderOpti…
muthurathinam-m May 24, 2019
7cbe481
Update README.md
muthurathinam May 24, 2019
10df55f
Update README.md
muthurathinam May 24, 2019
c2cb47a
Removing unnecessary dependencies
muthurathinam-m May 24, 2019
418c2a2
Merge branch 'v2.0.0' of https://github.com/microsoftgraph/msgraph-sd…
muthurathinam-m May 24, 2019
b3a2713
Update README.md
muthurathinam May 24, 2019
1f860b1
Update README.md
muthurathinam May 24, 2019
930a96c
Update README.md
muthurathinam May 25, 2019
fe07204
Renaming ImplicitMSALAuthenticationProviderOptions to MSALAuthenticat…
muthurathinam-m May 28, 2019
159e1c4
Merge branch 'v2.0.0' of https://github.com/microsoftgraph/msgraph-sd…
muthurathinam-m May 28, 2019
e90f4f8
Added babel polyfill in readme
muthurathinam-m May 29, 2019
5803f2c
Bump version with 2.0.0-Preview.1
muthurathinam-m May 29, 2019
441cfa0
Auto generation of version file and fix review comments
muthurathinam-m May 30, 2019
9714304
2.0.0-Preview.0
muthurathinam-m May 30, 2019
01d698c
Picking correct preview version
muthurathinam-m May 30, 2019
e7c7f01
Precommit hook will now add generated Version.ts file to commit
muthurathinam-m May 30, 2019
0d30e21
Fix CI build error in gulpfile.js: async funcitons are not supported …
muthurathinam-m May 31, 2019
700e2be
Merge branch 'dev' into v2.0.0
muthurathinam May 31, 2019
93680f8
Merge branch 'dev' into v2.0.0
muthurathinam Jun 19, 2019
032f559
Renamed msalInstance as msalApplication
muthurathinam-m Jun 19, 2019
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@ src/**/*.d.ts

samples/node/secrets.json
samples/browser/src/secrets.js
samples/browser/src/graph-js-sdk-core.js
samples/browser/src/graph-js-sdk-web.js
samples/browser/src/graph-js-sdk.js
samples/browser/src/graph-es-sdk.js

spec/**/*.js
Expand Down
2 changes: 1 addition & 1 deletion .huskyrc
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"hooks": {
"pre-commit": "lint-staged && npm run lint && npm run test"
"pre-commit": "npm run pre-build && git add src/Version.ts && lint-staged && npm run lint && npm run test"
}
}
65 changes: 40 additions & 25 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,24 +16,32 @@ The Microsoft Graph JavaScript client library is a lightweight wrapper around th
npm install @microsoft/microsoft-graph-client
```

import `@microsoft/microsoft-graph-client` into your module.
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).

```typescript
import "isomorphic-fetch";
import { Client } from "@microsoft/microsoft-graph-client";
```

### Via Script Tag

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

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

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`
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.

```HTML
<script type="text/javascript" src="graph-js-sdk-core.js"></script>
<!-- polyfilling promise -->
<script type="text/javascript" src="https://cdn.jsdelivr.net/npm/es6-promise/dist/es6-promise.auto.min.js"></script>

<!-- polyfilling fetch -->
<script type="text/javascript" src="https://cdn.jsdelivr.net/npm/whatwg-fetch/dist/fetch.umd.min.js"></script>

<!-- depending on your browser you might wanna include babel polyfill -->
<script type="text/javascript" src="https://cdn.jsdelivr.net/npm/@babel/polyfill@7.4.4/dist/polyfill.min.js"></script>
```

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

### 2. Authenticate for the Microsoft Graph service

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)).
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)).

> **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).
> **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).

#### Creating an instance of MSALAuthenticationProvider in browser environment
#### Creating an instance of ImplicitMSALAuthenticationProvider in browser environment

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

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

```typescript
const clientId = "your_client_id"; // Client Id of the registered application
const callback = (errorDesc, token, error, tokenType) => {};
// An Optional options for initializing the MSAL @see https://github.com/AzureAD/microsoft-authentication-library-for-js/wiki/MSAL-basics#configuration-options
const options = {
redirectUri: "Your redirect URI",

// Configuration options for MSAL @see https://github.com/AzureAD/microsoft-authentication-library-for-js/wiki/MSAL.js-1.0.0-api-release#configuration-options
const msalConfig = {
auth: {
clientId: "your_client_id"; // Client Id of the registered application
redirectUri: "your_redirect_uri",
},
};
const graphScopes = ["user.read", "mail.send"]; // An array of graph scopes

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

#### Creating an instance of MSALAuthenticationProvider in node environment
#### Creating an instance of ImplicitMSALAuthenticationProvider in node environment

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

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

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

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

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

User can integrate own preferred authentication library by implementing `IAuthenticationProvider` interface. Refer implementing [Custom Authentication Provider](./docs/CustomAuthenticationProvider.md).
Expand Down
30 changes: 30 additions & 0 deletions babel.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
module.exports = function(api) {
api.cache(true);
const presets = [
[
"@babel/preset-env",
{
targets: {
ie: 11,
},
},
],
];

const plugins = [
[
"@babel/plugin-transform-runtime",
{
absoluteRuntime: false,
corejs: false,
helpers: true,
regenerator: true,
useESModules: false,
},
],
];
return {
presets,
plugins,
};
};
11 changes: 0 additions & 11 deletions browser-wrapper.js

This file was deleted.

15 changes: 0 additions & 15 deletions browserify-with-dependencies.js

This file was deleted.

17 changes: 0 additions & 17 deletions browserify.js

This file was deleted.

39 changes: 19 additions & 20 deletions docs/CallingPattern.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,46 +4,45 @@ All calls to Microsoft Graph are chained together starting with **.api()**, then

## Path supports the following formats

* `me`
* `/me`
* `https://graph.microsoft.com/v1.0/me`
* `https://graph.microsoft.com/beta/me`
* `me/events?$filter=startswith(subject, "Adventure")`
- `me`
- `/me`
- `https://graph.microsoft.com/v1.0/me`
- `https://graph.microsoft.com/beta/me`
- `me/events?$filter=startswith(subject, "Adventure")`

## Promise based calling

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

```typescript
try {
let res = await client.api("/me").get();
console.log(res);
let res = await client.api("/me").get();
console.log(res);
} catch (error) {
throw error;
throw error;
}
```

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

```typescript
client
.api('/me')
.get()
.then((res) => {
console.log(res);
}).catch((err) => {
console.log(err);
});
.api("/me")
.get()
.then((res) => {
console.log(res);
})
.catch((err) => {
console.log(err);
});
```

## Callback based calling

Getting user details by passing `callback`,

```typescript
client
.api('/me')
.get((err, res, rawResponse) => {
console.log(res);
});
client.api("/me").get((err, res) => {
console.log(res);
});
```
18 changes: 15 additions & 3 deletions docs/CreatingClientInstance.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,24 @@ In order to instantiate a Client object, one has to pass in the `authProvider` o

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.

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.
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.

```typescript
// Instantiating Client with MSALAuthenticationProvider
// Instantiating Client with ImplicitMSALAuthenticationProvider

// An Optional options for initializing the MSAL @see https://github.com/AzureAD/microsoft-authentication-library-for-js/wiki/MSAL-basics#configuration-options
const msalConfig = {
auth: {
clientId: <CLIENT_ID> // Client Id of the registered application
},
};

// Important Note: This library implements loginPopup and acquireTokenPopup flow, remember this while initializing the msal
// Initialize the MSAL @see https://github.com/AzureAD/microsoft-authentication-library-for-js#1-instantiate-the-useragentapplication
const msalApplication = new UserAgentApplication(msalConfig);
const options = new MicrosoftGraph.MSALAuthenticationProviderOptions(<SCOPES>); // An array of graph scopes
let clientOptions: ClientOptions = {
authProvider: new MSALAuthenticationProvider(<CLIENT_ID>, <SCOPES>, <OPTIONS>)
authProvider: new ImplicitMSALAuthenticationProvider(msalApplication, options)
};
const client = Client.initWithMiddleware(clientOptions);
```
Expand Down
6 changes: 3 additions & 3 deletions docs/CustomMiddlewareChain.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,14 +68,14 @@ Can use own middlewares and the ones shipped with the library [[Here](../src/mid

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

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

```typescript
import { MSALAuthenticationProvider } from "@microsoft/microsoft-graph-client";
import { ImplicitMSALAuthenticationProvider } from "@microsoft/microsoft-graph-client";
import { MyLoggingHandler } from "./MyLoggingHandler";
import { MyHttpMessageHandler } from "./MyHttpMessageHandler";

let authProvider = new MSALAuthenticationProvider("<CLIENT_ID>", ["user.read"]);
let authProvider = new ImplicitMSALAuthenticationProvider("<CLIENT_ID>", ["user.read"]);
let authenticationHandler = new AuthenticationHandler(authProvider);
let myLoggingHandler = new MyLoggingHandler();
let myHttpMessageHandler = new MyHttpMessageHandler();
Expand Down
2 changes: 1 addition & 1 deletion docs/GettingRawResponse.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,6 @@ client
.select("displayName")
.responseType(ResponseType.RAW)
.get((error, rawResponse) => {
console.log(rawResponse)
console.log(rawResponse);
});
```
31 changes: 31 additions & 0 deletions gulpfile.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
const { series } = require("gulp");

const licenseStr = `/**
* -------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All Rights Reserved. Licensed under the MIT License.
* See License in the project root for license information.
* -------------------------------------------------------------------------------------------
*/
`;

const moduleHeader = `/**
* @module Version
*/
`;

const versionFile = `${licenseStr}
// THIS FILE IS AUTO GENERATED
// ANY CHANGES WILL BE LOST DURING BUILD

${moduleHeader}
export const PACKAGE_VERSION = "[VERSION]";
`;

function setVersion(cb) {
var pkg = require("./package.json");
var fs = require("fs");
fs.writeFileSync("src/Version.ts", versionFile.replace("[VERSION]", pkg.version));
cb();
}

exports.setVersion = setVersion;
Loading