Skip to content

Commit a2b6dea

Browse files
nikithauczengin
andauthored
ReadMe - Adding table of contents (#416)
* creating table of contents * CreateClient md changes, more links in toc * Adding additional resources * Removing travis badge * Apply suggestions from code review Co-authored-by: Mustafa Zengin <muzengin@microsoft.com> * replace - with : Co-authored-by: Mustafa Zengin <muzengin@microsoft.com>
1 parent a703e6e commit a2b6dea

File tree

3 files changed

+92
-87
lines changed

3 files changed

+92
-87
lines changed

README.md

+61-65
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,40 @@
11
# Microsoft Graph JavaScript Client Library
22

3-
[![npm version badge](https://img.shields.io/npm/v/@microsoft/microsoft-graph-client.svg?maxAge=86400)](https://www.npmjs.com/package/@microsoft/microsoft-graph-client) [![Travis](https://travis-ci.org/microsoftgraph/msgraph-sdk-javascript.svg?maxAge=86400)](https://travis-ci.org/microsoftgraph/msgraph-sdk-javascript) [![Known Vulnerabilities](https://snyk.io/test/github/microsoftgraph/msgraph-sdk-javascript/badge.svg?maxAge=86400)](https://snyk.io/test/github/microsoftgraph/msgraph-sdk-javascript) [![Licence](https://img.shields.io/github/license/microsoftgraph/msgraph-sdk-javascript.svg)](https://github.com/microsoftgraph/msgraph-sdk-javascript) [![code style: prettier](https://img.shields.io/badge/code_style-prettier-ff69b4.svg)](https://github.com/microsoftgraph/msgraph-sdk-javascript) [![Downloads](https://img.shields.io/npm/dm/@microsoft/microsoft-graph-client.svg?maxAge=86400)](https://www.npmjs.com/package/@microsoft/microsoft-graph-client)
3+
[![npm version badge](https://img.shields.io/npm/v/@microsoft/microsoft-graph-client.svg?maxAge=86400)](https://www.npmjs.com/package/@microsoft/microsoft-graph-client) [![Known Vulnerabilities](https://snyk.io/test/github/microsoftgraph/msgraph-sdk-javascript/badge.svg?maxAge=86400)](https://snyk.io/test/github/microsoftgraph/msgraph-sdk-javascript) [![Licence](https://img.shields.io/github/license/microsoftgraph/msgraph-sdk-javascript.svg)](https://github.com/microsoftgraph/msgraph-sdk-javascript) [![code style: prettier](https://img.shields.io/badge/code_style-prettier-ff69b4.svg)](https://github.com/microsoftgraph/msgraph-sdk-javascript) [![Downloads](https://img.shields.io/npm/dm/@microsoft/microsoft-graph-client.svg?maxAge=86400)](https://www.npmjs.com/package/@microsoft/microsoft-graph-client)
44

55
The Microsoft Graph JavaScript client library is a lightweight wrapper around the Microsoft Graph API that can be used server-side and in the browser.
66

7-
**Looking for IntelliSense on models (Users, Groups, etc.)? Check out the [Microsoft Graph Types](https://github.com/microsoftgraph/msgraph-typescript-typings) repository!**
7+
- [Microsoft Graph JavaScript Client Library](#microsoft-graph-javascript-client-library)
8+
- [Installation](#installation)
9+
- [Via npm](#via-npm)
10+
- [Via Script Tag](#via-script-tag)
11+
- [Getting started](#getting-started)
12+
- [1. Register your application](#1-register-your-application)
13+
- [2. Create a Client Instance](#2-create-a-client-instance)
14+
- [3. Make requests to the graph](#3-make-requests-to-the-graph)
15+
- Documentation
16+
- [HTTP Actions](docs/Actions.md)
17+
- [Chained APIs to call Microsoft Graph](docs/CallingPattern.md)
18+
- [OData system query options - Query Parameters](docs/QueryParameters.md)
19+
- [Batch multiple requests into single HTTP request](docs/content/Batching.md)
20+
- [Configurations to your request](docs/OtherAPIs.md)
21+
- [Query](docs/OtherAPIs.md#QUERY)
22+
- [Version](docs/OtherAPIs.md#VERSION)
23+
- [Headers](docs/OtherAPIs.md#HEADER-AND-HEADERS)
24+
- [Options](docs/OtherAPIs.md#OPTION-AND-OPTIONS)
25+
- [MiddlewareOptions](docs/OtherAPIs.md#MIDDLEWAREOPTIONS)
26+
- [ResponseType](docs/OtherAPIs.md#RESPONSETYPE)
27+
- [Upload large files to OneDrive, Outlook, Print API](docs/tasks/LargeFileUploadTask.md)
28+
- [Page Iteration](docs/tasks/PageIterator.md)
29+
- [Getting Raw Response](docs/GettingRawResponse.md)
30+
- [Creating an instance of TokenCredentialAuthenticationProvider](docs/TokenCredentialAuthenticationProvider.md)
31+
- [Questions and comments](#questions-and-comments)
32+
- [Contributing](#contributing)
33+
- [Additional resources](#additional-resources)
34+
- [Third Party Notices](#third-party-notices)
35+
- [Security Reporting](#security-reporting)
36+
- [License](#license)
37+
- [We Value and Adhere to the Microsoft Open Source Code of Conduct](#we-value-and-adhere-to-the-microsoft-open-source-code-of-conduct)
838

939
[![TypeScript demo](https://raw.githubusercontent.com/microsoftgraph/msgraph-sdk-javascript/master/types-demo.PNG)](https://github.com/microsoftgraph/msgraph-typescript-typings)
1040

@@ -19,10 +49,16 @@ Node.js 10 LTS or higher.
1949
npm install @microsoft/microsoft-graph-client
2050
```
2151

22-
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).
52+
import `@microsoft/microsoft-graph-client` into your module.
53+
54+
Also, you will need to import any fetch polyfill which suits your requirements.
55+
Following are some fetch polyfills -
56+
* [isomorphic-fetch](https://www.npmjs.com/package/isomorphic-fetch).
57+
* [cross-fetch](https://www.npmjs.com/package/cross-fetch)
58+
* [whatwg-fetch](https://www.npmjs.com/package/whatwg-fetch)
2359

2460
```typescript
25-
import "isomorphic-fetch";
61+
import "isomorphic-fetch"; // or import the fetch polyfill you installed
2662
import { Client } from "@microsoft/microsoft-graph-client";
2763
```
2864

@@ -48,60 +84,25 @@ In case your browser doesn't have support for [Fetch](https://developer.mozilla.
4884
```
4985

5086
## Getting started
51-
5287
### 1. Register your application
5388

54-
Register your application to use Microsoft Graph API using one of the following supported authentication portals:
55-
56-
- [Microsoft Application Registration Portal](https://apps.dev.microsoft.com): Register a new application that works with Microsoft Accounts and/or organizational accounts using the unified V2 Authentication Endpoint.
57-
- [Microsoft Azure Active Directory](https://manage.windowsazure.com): Register a new application in your tenant's Active Directory to support work or school users for your tenant or multiple tenants.
58-
59-
### 2. Authenticate for the Microsoft Graph service
60-
61-
The Microsoft Graph JavaScript Client Library has an adapter implementation for the following -
62-
63-
- ([TokenCredentialAuthenticationProvider](src/authentication/TokenCredentialAuthenticationProvider.ts)) to support [Azure Identity TokenCredential](https://github.com/Azure/azure-sdk-for-js/blob/master/sdk/identity/identity/README.md) (Azure Identity client library for JavaScript) which takes care of getting the `accessToken`. @azure/identity library does not ship with this library, user has to include it externally (For including @azure/identity, refer [this](https://www.npmjs.com/package/@azure/identity)).
64-
65-
> Learn how to [create an instance of TokenCredentialAuthenticationProvider](./docs/TokenCredentialAuthenticationProvider.md).
66-
67-
- ([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)).
68-
69-
> Learn how to [create an instance of ImplicitMSALAuthenticationProvider](./docs/ImplicitMSALAuthenticationProvider.md).
70-
71-
User can integrate own preferred authentication library by implementing `IAuthenticationProvider` interface. Refer implementing [Custom Authentication Provider](./docs/CustomAuthenticationProvider.md).
72-
73-
### 3. Initialize a Microsoft Graph Client object with an authentication provider
74-
75-
An instance of the **Client** class handles requests to Microsoft Graph API and processing the responses. To create a new instance of this class, you need to provide an instance of [`IAuthenticationProvider`](src/IAuthenticationProvider.ts) which needs to be passed as a value for `authProvider` key in [`ClientOptions`](src/IClientOptions.ts) to a static initializer method `Client.initWithMiddleware`.
89+
To call Microsoft Graph, your app must acquire an access token from the Microsoft identity platform.
90+
Learn more about this -
91+
- [Authentication and authorization basics for Microsoft Graph](https://docs.microsoft.com/en-us/graph/auth/auth-concepts)
92+
- [Register your app with the Microsoft identity platform](https://docs.microsoft.com/en-us/graph/auth/auth-concepts)
7693

77-
#### For browser environment
94+
### 2. Create a Client Instance
7895

79-
```typescript
80-
const options = {
81-
authProvider, // An instance created from previous step
82-
};
83-
const Client = MicrosoftGraph.Client;
84-
const client = Client.initWithMiddleware(options);
85-
```
86-
87-
#### For node environment
88-
89-
```typescript
90-
import { Client } from "@microsoft/microsoft-graph-client";
96+
The Microsoft Graph client is designed to make it simple to make calls to Microsoft Graph. You can use a single client instance for the lifetime of the application.
9197

92-
const options = {
93-
authProvider, // An instance created from previous step
94-
};
95-
const client = Client.initWithMiddleware(options);
96-
```
98+
For information on how to create a client instance, see [Creating Client Instance](./docs/CreatingClientInstance.md)
9799

98-
For more information on initializing client, refer [this document](./docs/CreatingClientInstance.md).
99100

100-
### 4. Make requests to the graph
101+
### 3. Make requests to the graph
101102

102-
Once you have authentication setup and an instance of Client, you can begin to make calls to the service. All requests should be start with `client.api(path)` and end with an [action](./docs/Actions.md).
103+
Once you have authentication setup and an instance of Client, you can begin to make calls to the service. All requests should start with `client.api(path)` and end with an [action](./docs/Actions.md).
103104

104-
Getting user details
105+
Example of getting user details:
105106

106107
```typescript
107108
try {
@@ -112,7 +113,7 @@ try {
112113
}
113114
```
114115

115-
Sending an email to the recipients
116+
Example of sending an email to the recipients:
116117

117118
```typescript
118119
// Construct email object
@@ -140,16 +141,6 @@ try {
140141

141142
For more information, refer: [Calling Pattern](docs/CallingPattern.md), [Actions](docs/Actions.md), [Query Params](docs/QueryParameters.md), [API Methods](docs/OtherAPIs.md) and [more](docs/).
142143

143-
## Documentation
144-
145-
- [Batching](docs/content/Batching.md)
146-
- [Large File Upload Task](docs/tasks/LargeFileUploadTask.md)
147-
- [Page Iterator](docs/tasks/PageIterator.md)
148-
- [Actions](docs/Actions.md)
149-
- [Query Parameters](docs/QueryParameters.md)
150-
- [Other APIs](docs/OtherAPIs.md)
151-
- [Getting Raw Response](docs/GettingRawResponse.md)
152-
153144
## Questions and comments
154145

155146
We'd love to get your feedback about the Microsoft Graph JavaScript client library. You can send your questions and suggestions to us in the [Issues](https://github.com/microsoftgraph/msgraph-sdk-javascript/issues) section of this repository.
@@ -160,11 +151,16 @@ Please see the [contributing guidelines](CONTRIBUTING.md).
160151

161152
## Additional resources
162153

163-
- [Microsoft Graph website](https://graph.microsoft.io)
164-
- [Microsoft Graph TypeScript types](https://github.com/microsoftgraph/msgraph-typescript-typings/)
165-
- [Build Angular single-page apps with Microsoft Graph](https://github.com/microsoftgraph/msgraph-training-angularspa)
166-
- [Build Node.js Express apps with Microsoft Graph](https://github.com/microsoftgraph/msgraph-training-nodeexpressapp)
167-
- [Office Dev Center](http://dev.office.com/)
154+
- [Microsoft Graph website](https://graph.microsoft.io)
155+
156+
- The Microsoft Graph TypeScript definitions enable editors to provide intellisense on Microsoft Graph objects including users, messages, and groups.
157+
- [@microsoft/microsoft-graph-types](https://www.npmjs.com/package/@microsoft/microsoft-graph-types) or [@types/microsoft-graph](https://www.npmjs.com/package/@types/microsoft-graph)
158+
- [@microsoft/microsoft-graph-types-beta](https://www.npmjs.com/package/@microsoft/microsoft-graph-types-beta)
159+
- [Build React Native apps with Microsoft Graph](https://docs.microsoft.com/en-us/graph/tutorials/react-native)
160+
- [Build Angular single-page apps with Microsoft Graph](https://github.com/microsoftgraph/msgraph-training-angularspa)
161+
- [Build Node.js Express apps with Microsoft Graph](https://github.com/microsoftgraph/msgraph-training-nodeexpressapp)
162+
- [Microsoft Graph Toolkit: UI Components and Authentication Providers for Microsoft Graph](https://docs.microsoft.com/en-us/graph/toolkit/overview)
163+
- [Office Dev Center](http://dev.office.com/)
168164

169165
## Third Party Notices
170166

docs/CreatingClientInstance.md

+30-21
Original file line numberDiff line numberDiff line change
@@ -4,35 +4,43 @@ Initialization of the Client can be done in one of below two ways
44

55
## 1. Create With ClientOptions [Recommended]
66

7+
The Microsoft Graph SDK client configures a default set of middleware that allows the SDK to communicate with the Microsoft Graph endpoints. This default set is customizable, allowing you to change the behavior of the client
8+
79
In order to instantiate a Client object, one has to pass in the `authProvider` or `middleware` chain in [ClientOptions](../src/IClientOptions.ts).
810

911
### Option A. Default Middleware chain
1012

11-
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.
13+
The default middleware chain contains consecutively chained instances of the following:
14+
- [AuthenticationHandler](../src/middleware/AuthenticationHandler.ts)
15+
- [RetryHandler](../src/middleware/RetryHandler.ts)
16+
- [RedirectHandler](../src/middleware/RedirectHandler.ts)
17+
- [TelemetryHandler](../src/middleware/TelemetryHandler.ts)
18+
- [HTTPMessageHandler](../src/middleware/HTTPMessageHandler.ts)
1219

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.
20+
To create a client instance with the default middleware chain:
1421

15-
```typescript
16-
// Instantiating Client with ImplicitMSALAuthenticationProvider
22+
1. Create an instance of a class which implements [AuthenticationProvider](../src/IAuthenticationProvider.ts) interface. This class should contain the logic to get the access token to be passed to the Microsoft Graph API.
1723

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+
2. Pass the instance as `authProvider` in [ClientOptions](../src/IClientOptions.ts) to instantiate the Client which will create and set the default middleware chain.
2425

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
26+
```typescript
2927
let clientOptions: ClientOptions = {
30-
authProvider: new ImplicitMSALAuthenticationProvider(msalApplication, options)
28+
authProvider: new YourAuthProviderClass(),
3129
};
3230
const client = Client.initWithMiddleware(clientOptions);
3331
```
3432

35-
Want to use own preferred authentication library, for which one has to implement [AuthenticationProvider](../src/IAuthenticationProvider.ts) interface and pass in the instance of it as `authProvider` in [ClientOptions](../src/IClientOptions.ts).
33+
The Microsoft Graph JavaScript Client Library has an adapter implementation for the following -
34+
35+
- ([TokenCredentialAuthenticationProvider](src/authentication/TokenCredentialAuthenticationProvider.ts)) to support [Azure Identity TokenCredential](https://github.com/Azure/azure-sdk-for-js/blob/master/sdk/identity/identity/README.md) (Azure Identity client library for JavaScript) which takes care of getting the `accessToken`. @azure/identity library does not ship with this library, user has to include it externally (For including @azure/identity, refer [this](https://www.npmjs.com/package/@azure/identity)).
36+
37+
> Learn how to [create an instance of TokenCredentialAuthenticationProvider](./TokenCredentialAuthenticationProvider.md).
38+
39+
- **DEPRECATED** ([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)).
40+
41+
> Learn how to [create an instance of ImplicitMSALAuthenticationProvider](./ImplicitMSALAuthenticationProvider.md).
42+
43+
**User can integrate any preferred authentication library by implementing `IAuthenticationProvider` interface**. Refer implementing [Custom Authentication Provider](./CustomAuthenticationProvider.md) for more detailed information.
3644

3745
```typescript
3846
let clientOptions: ClientOptions = {
@@ -42,11 +50,14 @@ let clientOptions: ClientOptions = {
4250
const client = Client.initWithMiddleware(clientOptions);
4351
```
4452

45-
Refer, [custom authentication provider](./CustomAuthenticationProvider.md) for more detailed information.
46-
4753
### Option B. Custom Middleware chain
4854

49-
Want to have complete control over the request and the response objects, one can provide his own chain of middleware. Have to pass first middleware in the chain as `middleware` in [ClientOptions](../src/IClientOptions.ts).
55+
The Microsoft Graph SDK client allows configuring custom middleware, allowing you to change the behavior of the client. For example, you can insert customized logging, or add a test handler to simulate specific scenarios.
56+
57+
To create a client instance with the custom middleware chain:
58+
59+
1. Refer to [custom middleware chain](./CustomMiddlewareChain.md) for more detailed information.
60+
2. Create the middleware chain and pass first middleware in the chain as `middleware` in [ClientOptions](../src/IClientOptions.ts).
5061

5162
```typescript
5263
let clientOptions: ClientOptions = {
@@ -56,8 +67,6 @@ let clientOptions: ClientOptions = {
5667
const client = Client.initWithMiddleware(clientOptions);
5768
```
5869

59-
Refer, [custom middleware chain](./CustomMiddlewareChain.md) for more detailed information.
60-
6170
## 2. Create With Options
6271

6372
Pass an [authProvider function](../src/IAuthProvider.ts) in [Options](../src/IOptions.ts) while initializing the Client. In this case, user has to provide his own implementation for getting and refreshing accessToken. A callback will be passed into this authProvider function, accessToken or error needs to be passed in to that callback.

docs/OtherAPIs.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ try {
8181
You can pass in additional request options through `.option()` and `.options()`, either individually or in a dictionary. Options can be [node specific](https://github.com/bitinn/node-fetch#options) or [from fetch standard](https://fetch.spec.whatwg.org/#requestinit)
8282

8383
```typescript
84-
let HttpProxyAgent = require('http-proxy-agent');
84+
let HttpProxyAgent = require('https-proxy-agent');
8585
try {
8686
// HTTP/HTTPS proxy to connect to
8787
let proxy = <YOUR PROXY>;

0 commit comments

Comments
 (0)