Skip to content

Commit 550ca06

Browse files
Merge branch 'dev' into Bug_Fixes
2 parents 640e4b5 + c50be7f commit 550ca06

File tree

4 files changed

+32
-33
lines changed

4 files changed

+32
-33
lines changed

README.md

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -60,13 +60,17 @@ Refer devDependencies in [package.json](./package.json) for the compatible msal
6060
```
6161

6262
```typescript
63-
const clientID = "your_client_id"; // Client Id of the registered application
64-
const graphScopes = ["user.read", "mail.send"]; // An array of graph scopes
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
6566
const options = {
66-
// An Optional options for initializing the MSAL @see https://github.com/AzureAD/microsoft-authentication-library-for-js/wiki/MSAL-basics#configuration-options
6767
redirectUri: "Your redirect URI",
6868
};
69-
const authProvider = new MicrosoftGraph.MSALAuthenticationProvider(clientId, graphScopes, options);
69+
const graphScopes = ["user.read", "mail.send"]; // An array of graph scopes
70+
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);
7074
```
7175

7276
#### Creating an instance of MSALAuthenticationProvider in node environment
@@ -78,15 +82,21 @@ npm install msal@<version>
7882
```
7983

8084
```typescript
85+
import { UserAgentApplication } from "msal";
86+
8187
import { MSALAuthenticationProvider } from "./node_modules/@microsoft/microsoft-graph-client/lib/src/MSALAuthenticationProvider";
8288

8389
const clientId = "your_client_id"; // Client Id of the registered application
84-
const graphScopes = ["user.read", "mail.send"]; // An array of graph scopes
90+
const callback = (errorDesc, token, error, tokenType) => {};
91+
// An Optional options for initializing the MSAL @see https://github.com/AzureAD/microsoft-authentication-library-for-js/wiki/MSAL-basics#configuration-options
8592
const options = {
86-
// An Optional options for initializing the MSAL @see https://github.com/AzureAD/microsoft-authentication-library-for-js/wiki/MSAL-basics#configuration-options
8793
redirectUri: "Your redirect URI",
8894
};
89-
const authProvider = new MSALAuthenticationProvider(clientId, scopes, options);
95+
const graphScopes = ["user.read", "mail.send"]; // An array of graph scopes
96+
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, scopes);
90100
```
91101

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

samples/browser/src/main.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,12 @@ let client, scopes;
1010
const init = async () => {
1111
scopes = ["user.read", "profile", "User.ReadWrite", "User.Readwrite.All", "User.Invite.All", "contacts.read", "Notes.ReadWrite", "Notes.Read", "Notes.Create", "Files.Read", "Files.Read.All", "Files.ReadWrite", "Files.ReadWrite.All", "Mail.Read", "Mail.ReadWrite", "Mail.Send"];
1212

13-
let msalProvider = new MicrosoftGraph.MSALAuthenticationProvider(Secrets.clientId, scopes, {
13+
const callback = (errorDesc, token, error, tokenType) => {};
14+
const options = {
1415
redirectUri: "http://localhost:8080",
15-
});
16+
};
17+
const userAgentApplication = new Msal.UserAgentApplication(Secrets.clientId, undefined, callback, options);
18+
let msalProvider = new MicrosoftGraph.MSALAuthenticationProvider(userAgentApplication, scopes);
1619
client = new MicrosoftGraph.Client({
1720
debugLogging: true,
1821
authProvider: msalProvider,

src/MSALAuthenticationProvider.ts

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -21,38 +21,31 @@ import { MSALAuthenticationProviderOptions } from "./MSALAuthenticationProviderO
2121
* @extends AuthenticationProvider
2222
*/
2323
export class MSALAuthenticationProvider implements AuthenticationProvider {
24-
/**
25-
* @private
26-
* A member holding the clientId of an application
27-
*/
28-
private clientId: string;
29-
3024
/**
3125
* @private
3226
* A member holding the list of graph scopes
3327
*/
3428
private scopes: string[];
3529

3630
/**
37-
* @private
31+
* @public
3832
* A member holding an instance of UserAgentApplication returned from MSAL
3933
*/
40-
private userAgentApplication: UserAgentApplication;
34+
public userAgentApplication: UserAgentApplication;
4135

4236
/**
4337
* @public
4438
* @constructor
4539
* Creates an instance of MSALAuthenticationProvider
46-
* @param {string} clientId - The clientId value of an application
40+
* @param {string | UserAgentApplication} clientIdOrUserAgentApplication - The clientId value of an application or an instance of UserAgentApplication
4741
* @param {string[]} scopes - An array of graph scopes
4842
* @param {any} [options] - An options object for MSAL initialization
4943
* @returns An instance of MSALAuthenticationProvider
5044
*/
51-
public constructor(clientId: string, scopes: string[], options?: any) {
45+
public constructor(clientIdOrUserAgentApplication: string | UserAgentApplication, scopes: string[], options?: any) {
5246
const callback = (errorDesc, token, error, tokenType) => {}; // tslint:disable-line: no-empty
53-
this.clientId = clientId;
5447
this.scopes = scopes;
55-
this.userAgentApplication = new UserAgentApplication(this.clientId, undefined, callback, options);
48+
this.userAgentApplication = typeof clientIdOrUserAgentApplication === "string" ? new UserAgentApplication(clientIdOrUserAgentApplication, undefined, callback, options) : clientIdOrUserAgentApplication;
5649
}
5750

5851
/**

src/browser/MSALAuthenticationProvider.ts

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -25,40 +25,33 @@ declare const Msal: any;
2525
* @extends AuthenticationProvider
2626
*/
2727
export class MSALAuthenticationProvider implements AuthenticationProvider {
28-
/**
29-
* @private
30-
* A member holding the clientId of an application
31-
*/
32-
private clientId: string;
33-
3428
/**
3529
* @private
3630
* A member holding the list of graph scopes
3731
*/
3832
private scopes: string[];
3933

4034
/**
41-
* @private
35+
* @public
4236
* A member holding an instance of UserAgentApplication returned from MSAL
4337
*/
44-
private userAgentApplication: any;
38+
public userAgentApplication: any;
4539

4640
/**
4741
* @public
4842
* @constructor
4943
* Creates an instance of MSALAuthenticationProvider
50-
* @param {string} clientId - The clientId value of an application
44+
* @param {string | any} clientIdOrUserAgentApplication - The clientId value of an application or an instance of UserAgentApplication
5145
* @param {string[]} scopes - An array of graph scopes
5246
* @param {any} [options] - An options object for MSAL initialization
5347
* @returns An instance of MSALAuthenticationProvider
5448
*/
55-
public constructor(clientId: string, scopes: string[], options?: any) {
49+
public constructor(clientIdOrUserAgentApplication: string | any, scopes: string[], options?: any) {
5650
const callback = (errorDesc, token, error, tokenType) => {
5751
// tslint:disable-line: no-empty
5852
};
59-
this.clientId = clientId;
6053
this.scopes = scopes;
61-
this.userAgentApplication = new Msal.UserAgentApplication(this.clientId, undefined, callback, options);
54+
this.userAgentApplication = typeof clientIdOrUserAgentApplication === "string" ? new Msal.UserAgentApplication(clientIdOrUserAgentApplication, undefined, callback, options) : clientIdOrUserAgentApplication;
6255
}
6356

6457
/**

0 commit comments

Comments
 (0)