diff --git a/authProviderOptions/es/msal/index.ts b/authProviderOptions/es/msal/index.ts deleted file mode 100644 index a7b087cad..000000000 --- a/authProviderOptions/es/msal/index.ts +++ /dev/null @@ -1,9 +0,0 @@ -/** - * ------------------------------------------------------------------------------------------- - * 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/ImplicitMSALAuthenticationProvider"; -export * from "../../../lib/es/src/authentication/msalOptions/MSALAuthenticationProviderOptions"; diff --git a/authProviderOptions/msal/index.ts b/authProviderOptions/msal/index.ts deleted file mode 100644 index 18598825e..000000000 --- a/authProviderOptions/msal/index.ts +++ /dev/null @@ -1,8 +0,0 @@ -/** - * ------------------------------------------------------------------------------------------- - * 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/msalOptions/MSALAuthenticationProviderOptions"; -export * from "../../lib/src/authentication/msal/ImplicitMSALAuthenticationProvider"; diff --git a/docs/ImplicitMSALAuthenticationProvider.md b/docs/ImplicitMSALAuthenticationProvider.md deleted file mode 100644 index 68d3fe81d..000000000 --- a/docs/ImplicitMSALAuthenticationProvider.md +++ /dev/null @@ -1,56 +0,0 @@ -#### 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. - -**Important Note:** MSAL is supported only for frontend applications, for server-side authentication you either can use [TokenCredentialAuthenticationProvider](./TokenCredentialAuthenticationProvider.md) or implement your own AuthenticationProvider. Learn how you can create a [Custom Authentication Provider](./docs/CustomAuthenticationProvider.md). - -```html - -``` - -```typescript -// 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 - -// 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 ImplicitMSALAuthenticationProvider in node environment - -Refer devDependencies in [package.json](./package.json) for the compatible msal version and update that version in below. - -```cmd -npm install msal@ -``` - -```typescript -import { UserAgentApplication } from "msal"; - -import { ImplicitMSALAuthenticationProvider, MSALAuthenticationProviderOptions } from "@microsoft/microsoft-graph-client/authProviders/msal"; - -// 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: "your_client_id", // Client Id of the registered application - redirectUri: "your_redirect_uri", - }, -}; -const graphScopes = ["user.read", "mail.send"]; // An array of graph scopes - -// 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 MSALAuthenticationProviderOptions(graphScopes); -const authProvider = new ImplicitMSALAuthenticationProvider(msalApplication, options); -``` diff --git a/lib/.npmignore b/lib/.npmignore new file mode 100644 index 000000000..aacdf47e7 --- /dev/null +++ b/lib/.npmignore @@ -0,0 +1,4 @@ +.npmignore +test/ +**/*.tsbuildinfo +es/test/ \ No newline at end of file diff --git a/package.json b/package.json index 6b0b2018d..f2b4d86cb 100644 --- a/package.json +++ b/package.json @@ -104,7 +104,6 @@ "karma-typescript": "^5.2.0", "lint-staged": "^11.0.0", "mocha": "^6.2.3", - "msal": "^1.0.0", "nyc": "^15.1.0", "prettier": "^1.17.0", "rollup": "^2.36.2", @@ -123,9 +122,6 @@ "buffer": { "optional": true }, - "msal": { - "optional": true - }, "stream-browserify": { "optional": true }, diff --git a/rollup.config.js b/rollup.config.js index a2e3ad09e..02e1686b5 100644 --- a/rollup.config.js +++ b/rollup.config.js @@ -19,7 +19,7 @@ const copyRight = `/** const config = [ { - input: ["lib/es/src/browser/rollupEntry.js"], + input: ["lib/es/src/browser/index.js"], output: { file: "lib/graph-js-sdk.js", format: "iife", diff --git a/src/authentication/msal/ImplicitMSALAuthenticationProvider.ts b/src/authentication/msal/ImplicitMSALAuthenticationProvider.ts deleted file mode 100644 index e75516299..000000000 --- a/src/authentication/msal/ImplicitMSALAuthenticationProvider.ts +++ /dev/null @@ -1,99 +0,0 @@ -/** - * ------------------------------------------------------------------------------------------- - * Copyright (c) Microsoft Corporation. All Rights Reserved. Licensed under the MIT License. - * See License in the project root for license information. - * ------------------------------------------------------------------------------------------- - */ - -/** - * @module ImplicitMSALAuthenticationProvider - */ - -import { AuthenticationParameters, AuthResponse, InteractionRequiredAuthError, UserAgentApplication } from "msal"; - -import { AuthenticationProvider } from "../../IAuthenticationProvider"; -import { AuthenticationProviderOptions } from "../../IAuthenticationProviderOptions"; -import { MSALAuthenticationProviderOptions } from "../msalOptions/MSALAuthenticationProviderOptions"; - -/** - * @deprecated Use of ImplicitMSALAuthenticationProvider, that is, - * using the implicit authorization flow is not recommended. - * Use the TokenCredentialAuthenticationProvider with azure/identity library or - * a CustomAuthenticationProvider with msal-browser library instead. - * @class - * Class representing ImplicitMSALAuthenticationProvider - * @extends AuthenticationProvider - */ -export class ImplicitMSALAuthenticationProvider implements AuthenticationProvider { - /** - * @private - * A member holding an instance of MSALAuthenticationProviderOptions - */ - private options: MSALAuthenticationProviderOptions; - - /** - * @private - * A member holding an instance of MSAL UserAgentApplication - */ - private msalApplication: UserAgentApplication; - - /** - * @public - * @constructor - * Creates an instance of ImplicitMSALAuthenticationProvider - * @param {UserAgentApplication} msalApplication - An instance of MSAL UserAgentApplication - * @param {MSALAuthenticationProviderOptions} options - An instance of MSALAuthenticationProviderOptions - * @returns An instance of ImplicitMSALAuthenticationProvider - */ - public constructor(msalApplication: UserAgentApplication, options: MSALAuthenticationProviderOptions) { - this.options = options; - this.msalApplication = msalApplication; - } - - /** - * @public - * @async - * To get the access token - * @param {AuthenticationProviderOptions} authenticationProviderOptions - The authentication provider options object - * @returns The promise that resolves to an access token - */ - public async getAccessToken(authenticationProviderOptions?: AuthenticationProviderOptions): Promise { - const options: MSALAuthenticationProviderOptions = authenticationProviderOptions as MSALAuthenticationProviderOptions; - let scopes: string[]; - if (typeof options !== "undefined") { - scopes = options.scopes; - } - if (typeof scopes === "undefined" || scopes.length === 0) { - scopes = this.options.scopes; - } - if (scopes.length === 0) { - const error = new Error(); - error.name = "EmptyScopes"; - error.message = "Scopes cannot be empty, Please provide a scopes"; - throw error; - } - if (this.msalApplication.getAccount()) { - const tokenRequest: AuthenticationParameters = { - scopes, - }; - try { - const authResponse: AuthResponse = await this.msalApplication.acquireTokenSilent(tokenRequest); - return authResponse.accessToken; - } catch (error) { - if (error instanceof InteractionRequiredAuthError) { - const authResponse: AuthResponse = await this.msalApplication.acquireTokenPopup(tokenRequest); - return authResponse.accessToken; - } else { - throw error; - } - } - } else { - const tokenRequest: AuthenticationParameters = { - scopes, - }; - await this.msalApplication.loginPopup(tokenRequest); - const authResponse: AuthResponse = await this.msalApplication.acquireTokenSilent(tokenRequest); - return authResponse.accessToken; - } - } -} diff --git a/src/authentication/msalOptions/MSALAuthenticationProviderOptions.ts b/src/authentication/msalOptions/MSALAuthenticationProviderOptions.ts index 4889ef721..5e70cbd18 100644 --- a/src/authentication/msalOptions/MSALAuthenticationProviderOptions.ts +++ b/src/authentication/msalOptions/MSALAuthenticationProviderOptions.ts @@ -13,36 +13,8 @@ import { AccountInfo, InteractionType } from "@azure/msal-browser"; import { AuthenticationProviderOptions } from "../../IAuthenticationProviderOptions"; -/** - * @deprecated - * @class - * @implements AuthenticationProviderOptions - * Class representing MSALAuthenticationProviderOptions - */ -export class MSALAuthenticationProviderOptions implements AuthenticationProviderOptions { - /** - * @public - * A member holding array of scopes - */ - public scopes: string[]; - - /** - * @public - * @constructor - * To create an instance of MSALAuthenticationProviderOptions - * @param {string[]} scopes - An array of scopes - * @returns An instance of MSALAuthenticationProviderOptions - */ - public constructor(scopes: string[]) { - this.scopes = scopes; - } -} - -export interface MSALAuthenticationProviderSharedOptions extends AuthenticationProviderOptions { +export interface AuthCodeMSALBrowserAuthenticationProviderOptions extends AuthenticationProviderOptions { scopes: string[]; -} - -export interface AuthCodeMSALBrowserAuthenticationProviderOptions extends MSALAuthenticationProviderSharedOptions { account: AccountInfo; interactionType: InteractionType; } diff --git a/src/browser/ImplicitMSALAuthenticationProvider.ts b/src/browser/ImplicitMSALAuthenticationProvider.ts deleted file mode 100644 index 97dccbf50..000000000 --- a/src/browser/ImplicitMSALAuthenticationProvider.ts +++ /dev/null @@ -1,103 +0,0 @@ -/** - * ------------------------------------------------------------------------------------------- - * Copyright (c) Microsoft Corporation. All Rights Reserved. Licensed under the MIT License. - * See License in the project root for license information. - * ------------------------------------------------------------------------------------------- - */ - -/** - * @module ImplicitMSALAuthenticationProvider - */ -import { MSALAuthenticationProviderOptions } from "../authentication/msalOptions/MSALAuthenticationProviderOptions"; -import { AuthenticationProvider } from "../IAuthenticationProvider"; -import { AuthenticationProviderOptions } from "../IAuthenticationProviderOptions"; - -/** - * @constant - * A declaration of a Msal library - */ -declare const Msal: any; - -/** - * @deprecated Use of ImplicitMSALAuthenticationProvider, that is, - * using the implicit authorization flow is not recommended. - * Use the TokenCredentialAuthenticationProvider with azure/identity library or - * a CustomAuthenticationProvider with msal-browser library instead. - * @class - * Class representing ImplicitMSALAuthenticationProvider - * @extends AuthenticationProvider - */ -export class ImplicitMSALAuthenticationProvider implements AuthenticationProvider { - /** - * @private - * A member holding an instance of MSALAuthenticationProviderOptions - */ - private options: MSALAuthenticationProviderOptions; - - /** - * @private - * A member holding an instance of MSAL - */ - private msalApplication: any; - - /** - * @public - * @constructor - * Creates an instance of ImplicitMSALAuthenticationProvider - * @param {any} msalApplication - An instance of MSAL UserAgentApplication - * @param {MSALAuthenticationProviderOptions} options - An instance of MSALAuthenticationProviderOptions - * @returns An instance of ImplicitMSALAuthenticationProvider - */ - public constructor(msalApplication: any, options: MSALAuthenticationProviderOptions) { - this.options = options; - this.msalApplication = msalApplication; - } - - /** - * @public - * @async - * To get the access token - * @param {AuthenticationProviderOptions} authenticationProviderOptions - The authentication provider options object - * @returns The promise that resolves to an access token - */ - public async getAccessToken(authenticationProviderOptions?: AuthenticationProviderOptions): Promise { - const options: MSALAuthenticationProviderOptions = authenticationProviderOptions as MSALAuthenticationProviderOptions; - let scopes: string[]; - if (typeof options !== "undefined") { - scopes = options.scopes; - } - if (typeof scopes === "undefined" || scopes.length === 0) { - scopes = this.options.scopes; - } - if (scopes.length === 0) { - const error = new Error(); - error.name = "EmptyScopes"; - error.message = "Scopes cannot be empty, Please provide a scopes"; - throw error; - } - - if (this.msalApplication.getAccount()) { - const tokenRequest = { - scopes, - }; - try { - const authResponse = await this.msalApplication.acquireTokenSilent(tokenRequest); - return authResponse.accessToken; - } catch (error) { - if (error.name === "InteractionRequiredAuthError") { - const authResponse = await this.msalApplication.acquireTokenPopup(tokenRequest); - return authResponse.accessToken; - } else { - throw error; - } - } - } else { - const tokenRequest = { - scopes, - }; - await this.msalApplication.loginPopup(tokenRequest); - const authResponse = await this.msalApplication.acquireTokenSilent(tokenRequest); - return authResponse.accessToken; - } - } -} diff --git a/src/browser/rollupEntry.ts b/src/browser/rollupEntry.ts deleted file mode 100644 index 82522107a..000000000 --- a/src/browser/rollupEntry.ts +++ /dev/null @@ -1,15 +0,0 @@ -/** - * ------------------------------------------------------------------------------------------- - * Copyright (c) Microsoft Corporation. All Rights Reserved. Licensed under the MIT License. - * See License in the project root for license information. - * ------------------------------------------------------------------------------------------- - */ -/** - * The purpose of this file is to export from src/browser/index.ts - * and the src/browser/ImplicitMSALAuthenticationProvider. - * No separate rollup entry point and bundled file is added for ImplicitMSALAuthenticationProvider as it is deprecated. - * After the ImplicitMSALAuthenticationProvider feature is removed, - * the entry point for rollup should point to src/browser/index.ts. - */ -export * from "./index"; -export * from "./ImplicitMSALAuthenticationProvider"; diff --git a/test/common/middleware/AuthenticationHandlerOptions.ts b/test/common/middleware/AuthenticationHandlerOptions.ts index 87a0b3bdb..1a0554388 100644 --- a/test/common/middleware/AuthenticationHandlerOptions.ts +++ b/test/common/middleware/AuthenticationHandlerOptions.ts @@ -7,22 +7,21 @@ import { assert } from "chai"; -import { MSALAuthenticationProviderOptions } from "../../../src/authentication/msalOptions/MSALAuthenticationProviderOptions"; import { AuthenticationHandlerOptions } from "../../../src/middleware/options/AuthenticationHandlerOptions"; import { DummyAuthenticationProvider } from "../../DummyAuthenticationProvider"; describe("AuthenticationHandlerOptions.ts", () => { const dummyAuthProvider = new DummyAuthenticationProvider(); - const msalAuthProviderOptions = new MSALAuthenticationProviderOptions([]); + const authOptions = { scopes: ["test"] }; it("Should create an instance with all the given options", () => { - const options = new AuthenticationHandlerOptions(dummyAuthProvider, msalAuthProviderOptions); + const options = new AuthenticationHandlerOptions(dummyAuthProvider, authOptions); assert.equal(options.authenticationProvider, dummyAuthProvider); - assert.equal(options.authenticationProviderOptions, msalAuthProviderOptions); + assert.equal(options.authenticationProviderOptions, authOptions); }); it("Should be undefined value if no value is passed", () => { - const options = new AuthenticationHandlerOptions(undefined, msalAuthProviderOptions); + const options = new AuthenticationHandlerOptions(undefined, authOptions); assert.isUndefined(options.authenticationProvider); - assert.equal(options.authenticationProviderOptions, msalAuthProviderOptions); + assert.equal(options.authenticationProviderOptions, authOptions); }); }); diff --git a/test/common/middleware/MSALAuthenticationProviderOptions.ts b/test/common/middleware/MSALAuthenticationProviderOptions.ts deleted file mode 100644 index 493e37488..000000000 --- a/test/common/middleware/MSALAuthenticationProviderOptions.ts +++ /dev/null @@ -1,19 +0,0 @@ -/** - * ------------------------------------------------------------------------------------------- - * Copyright (c) Microsoft Corporation. All Rights Reserved. Licensed under the MIT License. - * See License in the project root for license information. - * ------------------------------------------------------------------------------------------- - */ - -import { assert } from "chai"; - -import { MSALAuthenticationProviderOptions } from "../../../src/authentication/msalOptions/MSALAuthenticationProviderOptions"; - -describe("MSALAuthenticationProviderOptions.ts", () => { - it("Should create an instance with all the given options", () => { - const scopes = ["dummy.scope"]; - const options = new MSALAuthenticationProviderOptions(scopes); - assert.isDefined(options.scopes); - assert.equal(options.scopes, scopes); - }); -}); diff --git a/tsconfig-sub-cjs.json b/tsconfig-sub-cjs.json index c07b05c75..8809ef20f 100644 --- a/tsconfig-sub-cjs.json +++ b/tsconfig-sub-cjs.json @@ -7,7 +7,7 @@ "outDir": "authProviders" }, "exclude": ["node_modules", "lib", "samples", "test/", "src"], - "include": ["authProviderOptions/azureTokenCredentials/", "authProviderOptions/msal/", "authProviderOptions/authCodeMsalBrowser"], + "include": ["authProviderOptions/azureTokenCredentials/", "authProviderOptions/authCodeMsalBrowser"], "references": [ { "path": "./tsconfig-cjs.json"