From b14b98867ace4fbc287dacab65bb51c60b9f55d0 Mon Sep 17 00:00:00 2001 From: "nikithauc@gmail.com" Date: Thu, 22 Jul 2021 00:12:34 -0700 Subject: [PATCH] Removing implicitmsal --- authProviderOptions/es/msal/index.ts | 9 - authProviderOptions/msal/index.ts | 8 - docs/CreatingClientInstance.md | 4 - docs/ImplicitMSALAuthenticationProvider.md | 56 ---- package.json | 265 +++++++++--------- rollup.config.js | 103 ++++--- .../ImplicitMSALAuthenticationProvider.ts | 99 ------- .../msal/MSALAuthenticationProviderOptions.ts | 24 -- .../ImplicitMSALAuthenticationProvider.ts | 103 ------- src/browser/rollupEntry.ts | 15 - .../AuthenticationHandlerOptions.ts | 11 +- .../MSALAuthenticationProviderOptions.ts | 19 -- tsconfig-sub-cjs.json | 2 +- 13 files changed, 188 insertions(+), 530 deletions(-) delete mode 100644 authProviderOptions/es/msal/index.ts delete mode 100644 authProviderOptions/msal/index.ts delete mode 100644 docs/ImplicitMSALAuthenticationProvider.md delete mode 100644 src/authentication/msal/ImplicitMSALAuthenticationProvider.ts delete mode 100644 src/browser/ImplicitMSALAuthenticationProvider.ts delete mode 100644 src/browser/rollupEntry.ts delete mode 100644 test/common/middleware/MSALAuthenticationProviderOptions.ts diff --git a/authProviderOptions/es/msal/index.ts b/authProviderOptions/es/msal/index.ts deleted file mode 100644 index 985486f63..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/msal/MSALAuthenticationProviderOptions"; diff --git a/authProviderOptions/msal/index.ts b/authProviderOptions/msal/index.ts deleted file mode 100644 index 1f92b662c..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/msal/MSALAuthenticationProviderOptions"; -export * from "../../lib/src/authentication/msal/ImplicitMSALAuthenticationProvider"; diff --git a/docs/CreatingClientInstance.md b/docs/CreatingClientInstance.md index b1bca9fa4..b7098eb10 100644 --- a/docs/CreatingClientInstance.md +++ b/docs/CreatingClientInstance.md @@ -36,10 +36,6 @@ 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)). - - > Learn how to [create an instance of ImplicitMSALAuthenticationProvider](./ImplicitMSALAuthenticationProvider.md). - **User can integrate any preferred authentication library by implementing `IAuthenticationProvider` interface**. Refer implementing [Custom Authentication Provider](./CustomAuthenticationProvider.md) for more detailed information. ```typescript 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/package.json b/package.json index 220c0595e..6dd63e643 100644 --- a/package.json +++ b/package.json @@ -1,135 +1,132 @@ { - "name": "@microsoft/microsoft-graph-client", - "version": "3.0.0-Preview.2", - "description": "Microsoft Graph Client Library", - "keywords": [ - "Microsoft", - "Graph", - "SDK", - "JavaScript", - "Client" - ], - "repository": { - "type": "git", - "url": "https://github.com/microsoftgraph/msgraph-sdk-javascript.git" - }, - "license": "MIT", - "main": "lib/src/index.js", - "module": "lib/es/src/index.js", - "browser": { - "./lib/es/src/index.js": "./lib/es/src/browser/index.js", - "stream": "stream-browserify" - }, - "types": "./lib/src/index.d.ts", - "typings": "lib/src/index", - "files": [ - "lib/", - "src/", - "authProviders/" - ], - "scripts": { - "build": "npm run pre-build && npm run build:sub_cjs && npm run build:sub_es && rollup -c", - "build:cjs": "tsc --p tsconfig-cjs.json", - "build:es": "tsc --p tsconfig-es.json", - "build:sub_cjs": "tsc -b tsconfig-sub-cjs.json", - "build:sub_es": "tsc -b tsconfig-sub-es.json", - "format": "npm run format:css && npm run format:html && npm run format:js && npm run format:json && npm run format:md && npm run format:rc && npm run format:ts", - "format:css": "prettier --write \"**/*.css\"", - "format:html": "prettier --write \"**/*.html\"", - "format:js": "prettier --write \"**/*.js\"", - "format:json": "prettier --write \"**/*.json\"", - "format:md": "prettier --write \"**/*.md\"", - "format:rc": "prettier --write --parser json \"**/.*rc\"", - "format:ts": "prettier --write \"**/*.ts\"", - "karma": "karma start --single-run --browsers ChromeHeadless karma.conf.js", - "lint": "eslint . --ext .ts", - "lint:fix": "eslint . --ext .ts --fix", - "prepack": "npm install && npm run build && npm run test", - "pre-build": "npm run setVersion", - "setVersion": "gulp setVersion", - "test": "npm run test:cjs && npm run test:esm", - "test:cjs": "npm run build:sub_cjs && mocha 'lib/test/common/**/*.js' --require isomorphic-fetch && mocha 'lib/test/node/**/*.js' --require isomorphic-fetch", - "test:coverage": "TS_NODE_PROJECT='./tsconfig-cjs.json' nyc mocha --require isomorphic-fetch -r ts-node/register test/common/**/*.ts && mocha --require isomorphic-fetch -r ts-node/register test/common/**/*.ts", - "test:development": "tsc --p test/tsconfig-test-development.json && mocha 'lib/test/development/**/*.js' --require isomorphic-fetch", - "test:esm": "npm run build:sub_es && mocha 'lib/es/test/common/**/*.js' --require esm --require isomorphic-fetch && mocha 'lib/es/test/node/**/*.js' --require esm --require isomorphic-fetch" - }, - "nyc": { - "all": true, - "cache": false, - "exclude": [ - "samples/", - "*.js", - "lib/" - ], - "include": [ - "src/" - ] - }, - "dependencies": { - "@babel/runtime": "^7.12.5", - "tslib": "^2.2.0" - }, - "devDependencies": { - "@azure/identity": "^1.3.0", - "@babel/core": "^7.12.10", - "@babel/plugin-transform-runtime": "^7.12.10", - "@babel/preset-env": "^7.12.11", - "@istanbuljs/nyc-config-typescript": "^1.0.1", - "@microsoft/microsoft-graph-types": "^1.28.0", - "@rollup/plugin-babel": "^5.2.2", - "@rollup/plugin-commonjs": "^17.0.0", - "@rollup/plugin-node-resolve": "^11.1.0", - "@types/chai": "^4.2.14", - "@types/mocha": "^5.2.7", - "@types/node": "^12.0.10", - "@types/sinon": "^9.0.9", - "@typescript-eslint/eslint-plugin": "^3.8.0", - "@typescript-eslint/parser": "^3.8.0", - "chai": "^4.2.0", - "eslint": "^7.19.0", - "eslint-config-prettier": "^7.2.0", - "eslint-plugin-prettier": "^3.3.1", - "eslint-plugin-simple-import-sort": "^7.0.0", - "esm": "^3.2.25", - "form-data": "^2.3.3", - "gulp": "^4.0.2", - "husky": "^2.2.0", - "isomorphic-fetch": "^3.0.0", - "karma": "^6.3.2", - "karma-chai": "^0.1.0", - "karma-chrome-launcher": "^3.1.0", - "karma-firefox-launcher": "^2.1.0", - "karma-mocha": "^2.0.1", - "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", - "rollup-plugin-terser": "^7.0.2", - "sinon": "^9.2.4", - "source-map-support": "^0.5.19", - "stream-browserify": "^3.0.0", - "ts-node": "^9.0.0", - "typescript": "^4.2.4", - "uglify-es": "^3.3.9" - }, - "peerDependenciesMeta": { - "@azure/identity": { - "optional": true - }, - "buffer": { - "optional": true - }, - "msal": { - "optional": true - }, - "stream-browserify": { - "optional": true - } - }, - "engines": { - "node": ">=10.0.0" - } -} + "name": "@microsoft/microsoft-graph-client", + "version": "3.0.0-Preview.2", + "description": "Microsoft Graph Client Library", + "keywords": [ + "Microsoft", + "Graph", + "SDK", + "JavaScript", + "Client" + ], + "repository": { + "type": "git", + "url": "https://github.com/microsoftgraph/msgraph-sdk-javascript.git" + }, + "license": "MIT", + "main": "lib/src/index.js", + "module": "lib/es/src/index.js", + "browser": { + "./lib/es/src/index.js": "./lib/es/src/browser/index.js", + "stream": "stream-browserify" + }, + "types": "./lib/src/index.d.ts", + "typings": "lib/src/index", + "files": [ + "lib/", + "src/", + "authProviders/" + ], + "scripts": { + "build": "npm run pre-build && npm run build:sub_cjs && npm run build:sub_es && rollup -c", + "build:cjs": "tsc --p tsconfig-cjs.json", + "build:es": "tsc --p tsconfig-es.json", + "build:sub_cjs": "tsc -b tsconfig-sub-cjs.json", + "build:sub_es": "tsc -b tsconfig-sub-es.json", + "format": "npm run format:css && npm run format:html && npm run format:js && npm run format:json && npm run format:md && npm run format:rc && npm run format:ts", + "format:css": "prettier --write \"**/*.css\"", + "format:html": "prettier --write \"**/*.html\"", + "format:js": "prettier --write \"**/*.js\"", + "format:json": "prettier --write \"**/*.json\"", + "format:md": "prettier --write \"**/*.md\"", + "format:rc": "prettier --write --parser json \"**/.*rc\"", + "format:ts": "prettier --write \"**/*.ts\"", + "karma": "karma start --single-run --browsers ChromeHeadless karma.conf.js", + "lint": "eslint . --ext .ts", + "lint:fix": "eslint . --ext .ts --fix", + "prepack": "npm install && npm run build && npm run test", + "pre-build": "npm run setVersion", + "setVersion": "gulp setVersion", + "test": "npm run test:cjs && npm run test:esm", + "test:cjs": "npm run build:sub_cjs && mocha 'lib/test/common/**/*.js' --require isomorphic-fetch && mocha 'lib/test/node/**/*.js' --require isomorphic-fetch", + "test:coverage": "TS_NODE_PROJECT='./tsconfig-cjs.json' nyc mocha --require isomorphic-fetch -r ts-node/register test/common/**/*.ts && mocha --require isomorphic-fetch -r ts-node/register test/common/**/*.ts", + "test:development": "tsc --p test/tsconfig-test-development.json && mocha 'lib/test/development/**/*.js' --require isomorphic-fetch", + "test:esm": "npm run build:sub_es && mocha 'lib/es/test/common/**/*.js' --require esm --require isomorphic-fetch && mocha 'lib/es/test/node/**/*.js' --require esm --require isomorphic-fetch" + }, + "nyc": { + "all": true, + "cache": false, + "exclude": [ + "samples/", + "*.js", + "lib/" + ], + "include": [ + "src/" + ] + }, + "dependencies": { + "@babel/runtime": "^7.12.5", + "tslib": "^2.2.0" + }, + "devDependencies": { + "@azure/identity": "^1.3.0", + "@babel/core": "^7.12.10", + "@babel/plugin-transform-runtime": "^7.12.10", + "@babel/preset-env": "^7.12.11", + "@istanbuljs/nyc-config-typescript": "^1.0.1", + "@microsoft/microsoft-graph-types": "^1.28.0", + "@rollup/plugin-babel": "^5.2.2", + "@rollup/plugin-commonjs": "^17.0.0", + "@rollup/plugin-node-resolve": "^11.1.0", + "@types/chai": "^4.2.14", + "@types/mocha": "^5.2.7", + "@types/node": "^12.0.10", + "@types/sinon": "^9.0.9", + "@typescript-eslint/eslint-plugin": "^3.8.0", + "@typescript-eslint/parser": "^3.8.0", + "chai": "^4.2.0", + "eslint": "^7.19.0", + "eslint-config-prettier": "^7.2.0", + "eslint-plugin-prettier": "^3.3.1", + "eslint-plugin-simple-import-sort": "^7.0.0", + "esm": "^3.2.25", + "form-data": "^2.3.3", + "gulp": "^4.0.2", + "husky": "^2.2.0", + "isomorphic-fetch": "^3.0.0", + "karma": "^6.3.2", + "karma-chai": "^0.1.0", + "karma-chrome-launcher": "^3.1.0", + "karma-firefox-launcher": "^2.1.0", + "karma-mocha": "^2.0.1", + "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", + "rollup-plugin-terser": "^7.0.2", + "sinon": "^9.2.4", + "source-map-support": "^0.5.19", + "stream-browserify": "^3.0.0", + "ts-node": "^9.0.0", + "typescript": "^4.2.4", + "uglify-es": "^3.3.9" + }, + "peerDependenciesMeta": { + "@azure/identity": { + "optional": true + }, + "buffer": { + "optional": true + }, + "stream-browserify": { + "optional": true + } + }, + "engines": { + "node": ">=10.0.0" + } +} \ No newline at end of file diff --git a/rollup.config.js b/rollup.config.js index 210e99a53..c8263d190 100644 --- a/rollup.config.js +++ b/rollup.config.js @@ -17,57 +17,56 @@ const copyRight = `/** * ------------------------------------------------------------------------------------------- */`; -const config = [ - { - input: ["lib/es/src/browser/rollupEntry.js"], - output: { - file: "lib/graph-js-sdk.js", - format: "iife", - name: "MicrosoftGraph", - }, - plugins: [ - resolve({ - browser: true, - preferBuiltins: false, - }), - babel({ - babelHelpers: "runtime", - exclude: "node_modules/**", - }), - commonjs({ include: "node_modules/**" }), - terser({ - format: { - comments: false, - preamble: copyRight, - }, - }), - ], - }, - { - input: ["authProviders/es/azureTokenCredentials/index.js"], - output: { - file: "lib/graph-client-tokenCredentialAuthProvider.js", - format: "iife", - name: "MicrosoftGraph.TokenCredentialAuthProvider", - }, - plugins: [ - resolve({ - browser: true, - preferBuiltins: false, - }), - babel({ - babelHelpers: "runtime", - exclude: "node_modules/**", - }), - commonjs({ include: "node_modules/**" }), - terser({ - format: { - comments: false, - preamble: copyRight, - }, - }), - ], - }, +const config = [{ + input: ["lib/es/src/browser/index.js"], + output: { + file: "lib/graph-js-sdk.js", + format: "iife", + name: "MicrosoftGraph", + }, + plugins: [ + resolve({ + browser: true, + preferBuiltins: false, + }), + babel({ + babelHelpers: "runtime", + exclude: "node_modules/**", + }), + commonjs({ include: "node_modules/**" }), + terser({ + format: { + comments: false, + preamble: copyRight, + }, + }), + ], + }, + { + input: ["authProviders/es/azureTokenCredentials/index.js"], + output: { + file: "lib/graph-client-tokenCredentialAuthProvider.js", + format: "iife", + name: "MicrosoftGraph.TokenCredentialAuthProvider", + }, + plugins: [ + resolve({ + browser: true, + preferBuiltins: false, + }), + babel({ + babelHelpers: "runtime", + exclude: "node_modules/**", + }), + commonjs({ include: "node_modules/**" }), + terser({ + format: { + comments: false, + preamble: copyRight, + }, + }), + ], + }, ]; -export default config; +export default config; \ No newline at end of file diff --git a/src/authentication/msal/ImplicitMSALAuthenticationProvider.ts b/src/authentication/msal/ImplicitMSALAuthenticationProvider.ts deleted file mode 100644 index 4b2034e8d..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 "./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/msal/MSALAuthenticationProviderOptions.ts b/src/authentication/msal/MSALAuthenticationProviderOptions.ts index e8f1ed167..839169979 100644 --- a/src/authentication/msal/MSALAuthenticationProviderOptions.ts +++ b/src/authentication/msal/MSALAuthenticationProviderOptions.ts @@ -10,27 +10,3 @@ */ import { AuthenticationProviderOptions } from "../../IAuthenticationProviderOptions"; - -/** - * @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; - } -} diff --git a/src/browser/ImplicitMSALAuthenticationProvider.ts b/src/browser/ImplicitMSALAuthenticationProvider.ts deleted file mode 100644 index 2fd7e6667..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/msal/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 c3726736e..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/msal/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 25ff21d6c..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/msal/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 f18f79c37..1477a25bb 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/"], + "include": ["authProviderOptions/azureTokenCredentials/"], "references": [ { "path": "./tsconfig-cjs.json"