Skip to content

MsalBrowserAuthenticationProvider #484

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Jul 26, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
8 changes: 8 additions & 0 deletions authProviderOptions/authCodeMsalBrowser/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/**
* -------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All Rights Reserved. Licensed under the MIT License.
* See License in the project root for license information.
* -------------------------------------------------------------------------------------------
*/
export * from "../../lib/src/authentication/msal-browser/AuthCodeMSALBrowserAuthenticationProvider";
export * from "../../lib/src/authentication/msalOptions/MSALAuthenticationProviderOptions";
8 changes: 8 additions & 0 deletions authProviderOptions/es/authCodeMsalBrowser/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/**
* -------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All Rights Reserved. Licensed under the MIT License.
* See License in the project root for license information.
* -------------------------------------------------------------------------------------------
*/
export * from "../../../lib/es/src/authentication/msal-browser/AuthCodeMSALBrowserAuthenticationProvider";
export * from "../../../lib/es/src/authentication/msalOptions/MSALAuthenticationProviderOptions";
2 changes: 1 addition & 1 deletion authProviderOptions/es/msal/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@
*/

export * from "../../../lib/es/src/authentication/msal/ImplicitMSALAuthenticationProvider";
export * from "../../../lib/es/src/authentication/msal/MSALAuthenticationProviderOptions";
export * from "../../../lib/es/src/authentication/msalOptions/MSALAuthenticationProviderOptions";
2 changes: 1 addition & 1 deletion authProviderOptions/msal/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@
* See License in the project root for license information.
* -------------------------------------------------------------------------------------------
*/
export * from "../../lib/src/authentication/msal/MSALAuthenticationProviderOptions";
export * from "../../lib/src/authentication/msalOptions/MSALAuthenticationProviderOptions";
export * from "../../lib/src/authentication/msal/ImplicitMSALAuthenticationProvider";
66 changes: 66 additions & 0 deletions docs/AuthCodeMSALBrowserAuthenticationProvider.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
#### Creating an instance of AuthCodeMSALBrowserAuthenticationProvider for a browser application

**Note**: The `AuthCodeMSALBrowserAuthenticationProvider` is introduced in version 3.0.0 of Microsoft Graph Client Library

###### Links for more information -

- [npm - @azure/msal-browser](https://www.npmjs.com/package/@azure/msal-browser)
- [github - @azure/msal-browser](https://github.com/AzureAD/microsoft-authentication-library-for-js/blob/dev/lib/msal-browser/README.md)

Steps to use `AuthCodeMSALBrowserAuthenticationProvider`;

1. Using npm: `npm install @azure/msal-browser @microsoft/microsoft-graph-client`

Using html:

```html
<!--Using script tag to include the bundled file or the CDN source-->
<script type="text/javascript" src="https://alcdn.msauth.net/browser/2.15.0/js/msal-browser.min.js"></script>
<script src="graph-js-sdk.js"></script>
<script src="graph-client-msalBrowserAuthProvider.js"></script>
```

Reference : [MSAL Browser CDN usage](https://github.com/AzureAD/microsoft-authentication-library-for-js/blob/dev/lib/msal-browser/docs/cdn-usage.md)

2. Initialize the `msal-browser` `PublicClientApplication` instance: Learn more [how to initialize msal](https://github.com/AzureAD/microsoft-authentication-library-for-js/blob/dev/lib/msal-browser/docs/initialization.md)

3. Following sample shows how to initialize a Microsoft Graph SDK `Client` instance,

Using npm:

```typescript
import { PublicClientApplication, InteractionType, AccountInfo } from "@azure/msal-browser";

import { AuthCodeMSALBrowserAuthenticationProvider, AuthCodeMSALBrowserAuthenticationProviderOptions } from "@microsoft/microsoft-graph-client/authProviders/authCodeMsalBrowser";

const options:AuthCodeMSALBrowserAuthenticationProviderOptions: {
account: account, // the AccountInfo instance to acquire the token for.
interactionType: InteractionType.PopUp , // msal-browser InteractionType
scopes: ["user.read", "mail.send"] // example of the scopes to be passed
}

// Pass the PublicClientApplication instance from step 2 to create AuthCodeMSALBrowserAuthenticationProvider instance
const authProvider: new AuthCodeMSALBrowserAuthenticationProvider(publicClientApplication, options),


// Initialize the Graph client
const graphClient = Client.initWithMiddleware({
authprovider
});

```

Using CDN or script:

```javascript
const msalClient = new msal.PublicClientApplication(msalConfig);

const authProvider = new MSGraphAuthCodeMSALBrowserAuthProvider.AuthCodeMSALBrowserAuthenticationProvider(msalClient, {
account, // the AccountInfo instance to acquire the token for
scopes: ["user.read", "mail.send"],
interactionType: msal.InteractionType.Popup,
});

// Initialize the Graph client
const graphClient = MicrosoftGraph.Client.initWithMiddleware({ authProvider });
```
15 changes: 8 additions & 7 deletions docs/CreatingClientInstance.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,12 @@ In order to instantiate a Client object, one has to pass in the `authProvider` o
### Option A. Default Middleware chain

The default middleware chain contains consecutively chained instances of the following:
- [AuthenticationHandler](../src/middleware/AuthenticationHandler.ts)
- [RetryHandler](../src/middleware/RetryHandler.ts)
- [RedirectHandler](../src/middleware/RedirectHandler.ts)
- [TelemetryHandler](../src/middleware/TelemetryHandler.ts)
- [HTTPMessageHandler](../src/middleware/HTTPMessageHandler.ts)

- [AuthenticationHandler](../src/middleware/AuthenticationHandler.ts)
- [RetryHandler](../src/middleware/RetryHandler.ts)
- [RedirectHandler](../src/middleware/RedirectHandler.ts)
- [TelemetryHandler](../src/middleware/TelemetryHandler.ts)
- [HTTPMessageHandler](../src/middleware/HTTPMessageHandler.ts)

To create a client instance with the default middleware chain:

Expand All @@ -36,9 +37,9 @@ The Microsoft Graph JavaScript Client Library has an adapter implementation for

> Learn how to [create an instance of TokenCredentialAuthenticationProvider](./TokenCredentialAuthenticationProvider.md).

- **DEPRECATED** ([ImplicitMSALAuthenticationProvider](../src/authentication/msal/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)).
- ([AuthCodeMSALBrowserAuthenticationProvider](../src/authentication/msal/ImplicitMSALAuthenticationProvider.ts)) for [msal-browser](https://github.com/AzureAD/microsoft-authentication-library-for-js/tree/dev/lib/msal-browser) (Microsoft Authentication Library) which takes care of getting the `accessToken`. `msal-browser` library does not ship with this library, user has to include it externally.

> Learn how to [create an instance of ImplicitMSALAuthenticationProvider](./ImplicitMSALAuthenticationProvider.md).
> Learn how to [create an instance of AuthCodeMSALBrowserAuthenticationProvider](./AuthCodeMSALBrowserAuthenticationProvider.md).

**User can integrate any preferred authentication library by implementing `IAuthenticationProvider` interface**. Refer implementing [Custom Authentication Provider](./CustomAuthenticationProvider.md) for more detailed information.

Expand Down
4 changes: 3 additions & 1 deletion docs/TokenCredentialAuthenticationProvider.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#### Creating an instance of TokenCredentialAuthentication

**Note**: The `TokenCredentialAuthentication` is introduced in version 3.0.0 of Microsoft Graph Client Library

###### Links for more information -

- [GitHub - Azure Identity client library for JavaScript ](https://github.com/Azure/azure-sdk-for-js/blob/master/sdk/identity/identity/README.md)
Expand Down Expand Up @@ -60,5 +62,5 @@ The browser use of the file is as follows:
```html
<!-- include the script -->
<script type="text/javascript" src="<PATH_TO_SCRIPT>/graph-client-tokenCredentialAuthProvider.js"></script>
; // create an authProvider var authProvider = new MicrosoftGraph.TokenCredentialAuthProvider.TokenCredentialAuthenticationProvider(tokenCred, { scopes: scopes }); client = MicrosoftGraph.Client.initWithMiddleware({ authProvider: authProvider, });
; // create an authProvider var authProvider = new MicrosoftGraphTokenCredentialAuthProvider.TokenCredentialAuthenticationProvider(tokenCred, { scopes: scopes }); client = MicrosoftGraph.Client.initWithMiddleware({ authProvider: authProvider, });
```
4 changes: 0 additions & 4 deletions lib/.npmignore

This file was deleted.

Loading