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 3 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/es/msal-browser/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/MSALBrowserAuthenticationProvider";
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";
8 changes: 8 additions & 0 deletions authProviderOptions/msal-browser/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/MSALBrowserAuthenticationProvider";
export * from "../../lib/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";
64 changes: 64 additions & 0 deletions docs/MSALBrowserAuthenticationProvider.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
#### Creating an instance of MSALBrowserAuthenticationProvider for a browser application

**Note**: The `MSALBrowserAuthenticationProvider` 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 `MSALBrowserAuthenticationProvider`;

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

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

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 { MSALBrowserAuthenticationProvider, MSALBrowserAuthenticationProviderOptions } from "@microsoft/microsoft-graph-client/authProviders/msal-browser";

const options:MSALBrowserAuthenticationProviderOptions: {
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 MSALBrowserAuthenticationProvider instance
const authProvider: new MSALBrowserAuthenticationProvider(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 MicrosoftGraphMSALBrowserAuthProvider.MSALBrowserAuthenticationProvider(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 });
```
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