@microsoft/mgt-msal2-provider
Advanced tools
Comparing version 2.3.0-preview.ef38de5 to 3.0.0-next.fluentui.cef0a0b
@@ -25,21 +25,21 @@ /** | ||
* | ||
* @memberof MgtMsalProvider | ||
* @memberof MgtMsal2Provider | ||
*/ | ||
loginType: any; | ||
/** | ||
* Comma separated list of scopes | ||
* The authority to use. | ||
* | ||
* @memberof MgtMsalProvider | ||
* @memberof MgtMsal2Provider | ||
*/ | ||
scopes: any; | ||
authority: any; | ||
/** | ||
* The authority to use. | ||
* Comma separated list of scopes | ||
* | ||
* @memberof MgtMsalProvider | ||
* @memberof MgtMsal2Provider | ||
*/ | ||
authority: any; | ||
scopes: any; | ||
/** | ||
* The redirect uri to use | ||
* | ||
* @memberof MgtMsalProvider | ||
* @memberof MgtMsal2Provider | ||
*/ | ||
@@ -54,6 +54,12 @@ redirectUri: any; | ||
/** | ||
* Disables multiple account capability | ||
* | ||
* @memberof MgtMsal2Provider | ||
*/ | ||
isMultiAccountDisabled: any; | ||
/** | ||
* Gets whether this provider can be used in this environment | ||
* | ||
* @readonly | ||
* @memberof MgtMsalProvider | ||
* @memberof MgtMsal2Provider | ||
*/ | ||
@@ -65,3 +71,3 @@ get isAvailable(): boolean; | ||
* @protected | ||
* @memberof MgtMsalProvider | ||
* @memberof MgtMsal2Provider | ||
*/ | ||
@@ -68,0 +74,0 @@ protected initializeProvider(): void; |
@@ -40,3 +40,3 @@ /** | ||
* @readonly | ||
* @memberof MgtMsalProvider | ||
* @memberof MgtMsal2Provider | ||
*/ | ||
@@ -50,3 +50,3 @@ get isAvailable() { | ||
* @protected | ||
* @memberof MgtMsalProvider | ||
* @memberof MgtMsal2Provider | ||
*/ | ||
@@ -81,6 +81,4 @@ initializeProvider() { | ||
} | ||
if (this.prompt) { | ||
let prompt = this.prompt.toUpperCase(); | ||
const promptEnum = PromptType[prompt]; | ||
config.prompt = promptEnum; | ||
if (this.isMultiAccountDisabled) { | ||
config.isMultiAccountDisabled = true; | ||
} | ||
@@ -107,2 +105,6 @@ this.provider = new Msal2Provider(config); | ||
__decorate([ | ||
property(), | ||
__metadata("design:type", Object) | ||
], MgtMsal2Provider.prototype, "authority", void 0); | ||
__decorate([ | ||
property({ | ||
@@ -116,9 +118,2 @@ attribute: 'scopes', | ||
property({ | ||
attribute: 'authority', | ||
type: String | ||
}), | ||
__metadata("design:type", Object) | ||
], MgtMsal2Provider.prototype, "authority", void 0); | ||
__decorate([ | ||
property({ | ||
attribute: 'redirect-uri', | ||
@@ -136,2 +131,9 @@ type: String | ||
], MgtMsal2Provider.prototype, "prompt", void 0); | ||
__decorate([ | ||
property({ | ||
attribute: 'multi-account-disabled', | ||
type: Boolean | ||
}), | ||
__metadata("design:type", Object) | ||
], MgtMsal2Provider.prototype, "isMultiAccountDisabled", void 0); | ||
MgtMsal2Provider = __decorate([ | ||
@@ -138,0 +140,0 @@ customElement('mgt-msal2-provider') |
@@ -5,10 +5,10 @@ import { IProvider, LoginType, IProviderAccount } from '@microsoft/mgt-element'; | ||
/** | ||
* Config for MSAL2.0 Authentication | ||
* base config for MSAL 2.0 authentication | ||
* | ||
* @export | ||
* @interface Msal2Config | ||
* @interface Msal2ConfigBase | ||
*/ | ||
export interface Msal2Config { | ||
interface Msal2ConfigBase { | ||
/** | ||
* Client ID of app registration | ||
* Redirect URI | ||
* | ||
@@ -18,36 +18,43 @@ * @type {string} | ||
*/ | ||
clientId: string; | ||
redirectUri?: string; | ||
/** | ||
* LoginType | ||
* Authority URL | ||
* | ||
* @type {LoginType} | ||
* @type {string} | ||
* @memberof Msal2Config | ||
*/ | ||
loginType?: LoginType; | ||
authority?: string; | ||
/** | ||
* Other options | ||
* | ||
* @type {Configuration} | ||
* @memberof Msal2Config | ||
*/ | ||
options?: Configuration; | ||
/** | ||
* List of scopes required | ||
* | ||
* @type {string[]} | ||
* @memberof Msal2Config | ||
* @memberof Msal2ConfigBase | ||
*/ | ||
scopes?: string[]; | ||
/** | ||
* LoginHint | ||
* loginType if login uses popup | ||
* | ||
* @type {string} | ||
* @memberof Msal2Config | ||
* @type {LoginType} | ||
* @memberof Msal2ConfigBase | ||
*/ | ||
loginHint?: string; | ||
loginType?: LoginType; | ||
/** | ||
* Session ID | ||
* login hint value | ||
* | ||
* @type {string} | ||
* @memberof Msal2Config | ||
* @memberof Msal2ConfigBase | ||
*/ | ||
sid?: string; | ||
loginHint?: string; | ||
/** | ||
* Domain hint | ||
* Domain hint value | ||
* | ||
* @type {string} | ||
* @memberof Msal2Config | ||
* @memberof Msal2ConfigBase | ||
*/ | ||
@@ -58,8 +65,8 @@ domainHint?: string; | ||
* | ||
* @type {Prompt} | ||
* @memberof Msal2Config | ||
* @type {string} | ||
* @memberof Msal2ConfigBase | ||
*/ | ||
prompt?: PromptType; | ||
/** | ||
* Redirect URI | ||
* Session ID | ||
* | ||
@@ -69,19 +76,42 @@ * @type {string} | ||
*/ | ||
redirectUri?: string; | ||
sid?: string; | ||
} | ||
/** | ||
* Config for MSAL2.0 Authentication | ||
* | ||
* @export | ||
* @interface Msal2Config | ||
*/ | ||
export interface Msal2Config extends Msal2ConfigBase { | ||
/** | ||
* Authority URL | ||
* Client ID of app registration | ||
* | ||
* @type {string} | ||
* @type {boolean} | ||
* @memberof Msal2Config | ||
*/ | ||
authority?: string; | ||
clientId: string; | ||
/** | ||
* Other options | ||
* Disable multi account functionality | ||
* | ||
* @type {Configuration} | ||
* @type {boolean} | ||
* @memberof Msal2Config | ||
*/ | ||
options?: Configuration; | ||
isMultiAccountDisabled?: boolean; | ||
} | ||
/** | ||
* Config for MSAL 2.0 Authentication where a PublicClientApplication already exists | ||
* | ||
* @export | ||
* @interface Msal2PublicClientApplicationConfig | ||
*/ | ||
export interface Msal2PublicClientApplicationConfig extends Msal2ConfigBase { | ||
/** | ||
* Existing PublicClientApplication instance to use | ||
* | ||
* @type {PublicClientApplication} | ||
* @memberof Msal2PublicClientApplicationConfig | ||
*/ | ||
publicClientApplication: PublicClientApplication; | ||
} | ||
/** | ||
* Prompt type enum | ||
@@ -173,6 +203,15 @@ * | ||
scopes: string[]; | ||
/** | ||
* | ||
* Disables multi account functionality | ||
* @private | ||
* @type {boolean} | ||
* @memberof Msal2Provider | ||
*/ | ||
private _isMultipleAccountDisabled; | ||
get isMultiAccountSupported(): boolean; | ||
private sessionStorageRequestedScopesKey; | ||
private sessionStorageDeniedScopesKey; | ||
private homeAccountKey; | ||
constructor(config: Msal2Config); | ||
constructor(config: Msal2Config | Msal2PublicClientApplicationConfig); | ||
/** | ||
@@ -214,2 +253,9 @@ * Initialize provider with configuration details | ||
/** | ||
* Gets active account | ||
* | ||
* @return {*} | ||
* @memberof Msal2Provider | ||
*/ | ||
getActiveAccount(): IProviderAccount; | ||
/** | ||
* Once a succesful login occurs, set the active account and store it | ||
@@ -290,3 +336,3 @@ * | ||
*/ | ||
private getAccount; | ||
protected getAccount(): AccountInfo | null; | ||
/** | ||
@@ -307,2 +353,3 @@ * Logs out user | ||
} | ||
export {}; | ||
//# sourceMappingURL=Msal2Provider.d.ts.map |
@@ -34,2 +34,10 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
super(); | ||
/** | ||
* | ||
* Disables multi account functionality | ||
* @private | ||
* @type {boolean} | ||
* @memberof Msal2Provider | ||
*/ | ||
this._isMultipleAccountDisabled = false; | ||
this.sessionStorageRequestedScopesKey = 'mgt-requested-scopes'; | ||
@@ -59,2 +67,5 @@ this.sessionStorageDeniedScopesKey = 'mgt-denied-scopes'; | ||
} | ||
get isMultiAccountSupported() { | ||
return !this._isMultipleAccountDisabled; | ||
} | ||
/** | ||
@@ -69,46 +80,61 @@ * Initialize provider with configuration details | ||
return __awaiter(this, void 0, void 0, function* () { | ||
if (config.clientId) { | ||
const msalConfig = config.options || { auth: { clientId: config.clientId } }; | ||
this.ms_config = msalConfig; | ||
this.ms_config.auth.clientId = config.clientId; | ||
if (config.authority) { | ||
this.ms_config.auth.authority = config.authority; | ||
const msalConfig = config.options || { auth: { clientId: '' } }; | ||
this.ms_config = msalConfig; | ||
this.ms_config.cache = msalConfig.cache || {}; | ||
this.ms_config.cache.cacheLocation = msalConfig.cache.cacheLocation || 'localStorage'; | ||
if (typeof this.ms_config.cache.storeAuthStateInCookie === 'undefined' || | ||
this.ms_config.cache.storeAuthStateInCookie === null) { | ||
this.ms_config.cache.storeAuthStateInCookie = true; | ||
} | ||
this.ms_config.system = msalConfig.system || {}; | ||
this.ms_config.system.iframeHashTimeout = msalConfig.system.iframeHashTimeout || 10000; | ||
if (config.authority) { | ||
this.ms_config.auth.authority = config.authority; | ||
} | ||
if (config.redirectUri) { | ||
this.ms_config.auth.redirectUri = config.redirectUri; | ||
} | ||
if ('clientId' in config) { | ||
if (config.clientId) { | ||
this.ms_config.auth.clientId = config.clientId; | ||
this._publicClientApplication = new PublicClientApplication(this.ms_config); | ||
} | ||
if (config.redirectUri) { | ||
this.ms_config.auth.redirectUri = config.redirectUri; | ||
else { | ||
throw new Error('clientId must be provided'); | ||
} | ||
this.ms_config.cache = msalConfig.cache || {}; | ||
this.ms_config.cache.cacheLocation = msalConfig.cache.cacheLocation || 'localStorage'; | ||
if (typeof this.ms_config.cache.storeAuthStateInCookie === 'undefined' || | ||
this.ms_config.cache.storeAuthStateInCookie === null) { | ||
this.ms_config.cache.storeAuthStateInCookie = true; | ||
} | ||
else if ('publicClientApplication' in config) { | ||
if (config.publicClientApplication) { | ||
this._publicClientApplication = config.publicClientApplication; | ||
} | ||
if (config.redirectUri) { | ||
this.ms_config.auth.redirectUri = config.redirectUri; | ||
else { | ||
throw new Error('publicClientApplication must be provided'); | ||
} | ||
this.ms_config.system = msalConfig.system || {}; | ||
this.ms_config.system.iframeHashTimeout = msalConfig.system.iframeHashTimeout || 10000; | ||
this._loginType = typeof config.loginType !== 'undefined' ? config.loginType : LoginType.Redirect; | ||
this._loginHint = typeof config.loginHint !== 'undefined' ? config.loginHint : null; | ||
this._sid = typeof config.sid !== 'undefined' ? config.sid : null; | ||
this._domainHint = typeof config.domainHint !== 'undefined' ? config.domainHint : null; | ||
this.scopes = typeof config.scopes !== 'undefined' ? config.scopes : ['user.read']; | ||
this._publicClientApplication = new PublicClientApplication(this.ms_config); | ||
this._prompt = typeof config.prompt !== 'undefined' ? config.prompt : PromptType.SELECT_ACCOUNT; | ||
this.graph = createFromProvider(this); | ||
try { | ||
const tokenResponse = yield this._publicClientApplication.handleRedirectPromise(); | ||
if (tokenResponse !== null) { | ||
this.handleResponse(tokenResponse === null || tokenResponse === void 0 ? void 0 : tokenResponse.account); | ||
} | ||
else { | ||
this.trySilentSignIn(); | ||
} | ||
} | ||
else { | ||
throw new Error('either clientId or publicClientApplication must be provided'); | ||
} | ||
this.ms_config.system = msalConfig.system || {}; | ||
this.ms_config.system.iframeHashTimeout = msalConfig.system.iframeHashTimeout || 10000; | ||
this._loginType = typeof config.loginType !== 'undefined' ? config.loginType : LoginType.Redirect; | ||
this._loginHint = typeof config.loginHint !== 'undefined' ? config.loginHint : null; | ||
this._sid = typeof config.sid !== 'undefined' ? config.sid : null; | ||
this._domainHint = typeof config.domainHint !== 'undefined' ? config.domainHint : null; | ||
this.scopes = typeof config.scopes !== 'undefined' ? config.scopes : ['user.read']; | ||
this._prompt = typeof config.prompt !== 'undefined' ? config.prompt : PromptType.SELECT_ACCOUNT; | ||
const msal2config = config; | ||
this._isMultipleAccountDisabled = | ||
typeof msal2config.isMultiAccountDisabled !== 'undefined' ? msal2config.isMultiAccountDisabled : false; | ||
this.graph = createFromProvider(this); | ||
try { | ||
const tokenResponse = yield this._publicClientApplication.handleRedirectPromise(); | ||
if (tokenResponse !== null) { | ||
this.handleResponse(tokenResponse === null || tokenResponse === void 0 ? void 0 : tokenResponse.account); | ||
} | ||
catch (e) { | ||
throw e; | ||
else { | ||
this.trySilentSignIn(); | ||
} | ||
} | ||
else { | ||
throw new Error('clientId must be provided'); | ||
catch (e) { | ||
throw e; | ||
} | ||
@@ -187,3 +213,3 @@ }); | ||
this._publicClientApplication.getAllAccounts().forEach((account) => { | ||
usernames.push({ username: account.username, id: account.homeAccountId }); | ||
usernames.push({ name: account.name, mail: account.username, id: account.homeAccountId }); | ||
}); | ||
@@ -204,2 +230,12 @@ return usernames; | ||
/** | ||
* Gets active account | ||
* | ||
* @return {*} | ||
* @memberof Msal2Provider | ||
*/ | ||
getActiveAccount() { | ||
const account = this._publicClientApplication.getActiveAccount(); | ||
return { name: account.name, mail: account.username, id: account.homeAccountId }; | ||
} | ||
/** | ||
* Once a succesful login occurs, set the active account and store it | ||
@@ -213,4 +249,5 @@ * | ||
this.setActiveAccount({ | ||
username: account.name, | ||
id: account.homeAccountId | ||
name: account.name, | ||
id: account.homeAccountId, | ||
mail: account.username | ||
}); | ||
@@ -361,3 +398,8 @@ this.setState(ProviderState.SignedIn); | ||
yield this._publicClientApplication.logoutPopup(Object.assign({}, logOutRequest)); | ||
this.setState(ProviderState.SignedOut); | ||
if (this._publicClientApplication.getAllAccounts.length == 1 || this._isMultipleAccountDisabled) { | ||
this.setState(ProviderState.SignedOut); | ||
} | ||
else { | ||
this.trySilentSignIn(); | ||
} | ||
} | ||
@@ -364,0 +406,0 @@ }); |
{ | ||
"name": "@microsoft/mgt-msal2-provider", | ||
"version": "2.3.0-preview.ef38de5", | ||
"version": "3.0.0-next.fluentui.cef0a0b", | ||
"description": "The Microsoft Graph Toolkit Msal 2.0 Provider", | ||
@@ -42,5 +42,5 @@ "keywords": [ | ||
"dependencies": { | ||
"@microsoft/mgt-element": "2.3.0-preview.ef38de5", | ||
"@microsoft/mgt-element": "3.0.0-next.fluentui.cef0a0b", | ||
"@microsoft/microsoft-graph-client": "^2.2.1", | ||
"@azure/msal-browser": "^2.14.1" | ||
"@azure/msal-browser": "^2.14.2" | ||
}, | ||
@@ -47,0 +47,0 @@ "publishConfig": { |
@@ -18,3 +18,3 @@ # Microsoft Graph Toolkit MSAL 2.0 Provider | ||
2. Initialize the provider in code | ||
2. Initialize the provider in code with `Msal2Config` | ||
@@ -40,4 +40,26 @@ ```ts | ||
3. Alternatively, initialize the provider in html (only `client-id` is required): | ||
3. Initialize the provider in code with `Msal2PublicClientApplicationConfig` if a `PublicClientApplication` is already instantiated. For example, `msal-angular` instantiates `PublicClientApplication` on startup. | ||
```ts | ||
import {Providers, LoginType} from '@microsoft/mgt-element'; | ||
import {Msal2Provider, PromptType} from '@microsoft/mgt-msal2-provider'; | ||
import {PublicClientApplication} from '@azure/msal-browser'; | ||
// initialize the auth provider globally | ||
Providers.globalProvider = new Msal2Provider({ | ||
publicClientApplication: PublicClientApplication, | ||
scopes?: string[], | ||
authority?: string, | ||
redirectUri?: string, | ||
loginType?: LoginType, // LoginType.Popup or LoginType.Redirect (redirect is default) | ||
prompt?: PromptType, // PromptType.CONSENT, PromptType.LOGIN or PromptType.SELECT_ACCOUNT | ||
sid?: string, // Session ID | ||
loginHint?: string, | ||
domainHint?: string, | ||
options?: Configuration // msal js Configuration object | ||
}); | ||
``` | ||
4. Alternatively, initialize the provider in html (only `client-id` is required): | ||
```html | ||
@@ -44,0 +66,0 @@ <script type="module" src="../node_modules/@microsoft/mgt-msal2-provider/dist/es6/index.js" /> |
@@ -34,3 +34,3 @@ /** | ||
* | ||
* @memberof MgtMsalProvider | ||
* @memberof MgtMsal2Provider | ||
*/ | ||
@@ -44,22 +44,18 @@ @property({ | ||
/** | ||
* Comma separated list of scopes | ||
* The authority to use. | ||
* | ||
* @memberof MgtMsalProvider | ||
* @memberof MgtMsal2Provider | ||
*/ | ||
@property({ | ||
attribute: 'scopes', | ||
type: String | ||
}) | ||
public scopes; | ||
@property() public authority; | ||
/** | ||
* The authority to use. | ||
* Comma separated list of scopes | ||
* | ||
* @memberof MgtMsalProvider | ||
* @memberof MgtMsal2Provider | ||
*/ | ||
@property({ | ||
attribute: 'authority', | ||
attribute: 'scopes', | ||
type: String | ||
}) | ||
public authority; | ||
public scopes; | ||
@@ -69,3 +65,3 @@ /** | ||
* | ||
* @memberof MgtMsalProvider | ||
* @memberof MgtMsal2Provider | ||
*/ | ||
@@ -90,6 +86,17 @@ @property({ | ||
/** | ||
* Disables multiple account capability | ||
* | ||
* @memberof MgtMsal2Provider | ||
*/ | ||
@property({ | ||
attribute: 'multi-account-disabled', | ||
type: Boolean | ||
}) | ||
public isMultiAccountDisabled; | ||
/** | ||
* Gets whether this provider can be used in this environment | ||
* | ||
* @readonly | ||
* @memberof MgtMsalProvider | ||
* @memberof MgtMsal2Provider | ||
*/ | ||
@@ -104,3 +111,3 @@ public get isAvailable() { | ||
* @protected | ||
* @memberof MgtMsalProvider | ||
* @memberof MgtMsal2Provider | ||
*/ | ||
@@ -141,6 +148,4 @@ protected initializeProvider() { | ||
if (this.prompt) { | ||
let prompt: string = this.prompt.toUpperCase(); | ||
const promptEnum = PromptType[prompt]; | ||
config.prompt = promptEnum; | ||
if (this.isMultiAccountDisabled) { | ||
config.isMultiAccountDisabled = true; | ||
} | ||
@@ -147,0 +152,0 @@ |
@@ -23,10 +23,10 @@ import { | ||
/** | ||
* Config for MSAL2.0 Authentication | ||
* base config for MSAL 2.0 authentication | ||
* | ||
* @export | ||
* @interface Msal2Config | ||
* @interface Msal2ConfigBase | ||
*/ | ||
export interface Msal2Config { | ||
interface Msal2ConfigBase { | ||
/** | ||
* Client ID of app registration | ||
* Redirect URI | ||
* | ||
@@ -36,41 +36,46 @@ * @type {string} | ||
*/ | ||
clientId: string; | ||
redirectUri?: string; | ||
/** | ||
* LoginType | ||
* Authority URL | ||
* | ||
* @type {LoginType} | ||
* @type {string} | ||
* @memberof Msal2Config | ||
*/ | ||
loginType?: LoginType; | ||
authority?: string; | ||
/** | ||
* Other options | ||
* | ||
* @type {Configuration} | ||
* @memberof Msal2Config | ||
*/ | ||
options?: Configuration; | ||
/** | ||
* List of scopes required | ||
* | ||
* @type {string[]} | ||
* @memberof Msal2Config | ||
* @memberof Msal2ConfigBase | ||
*/ | ||
scopes?: string[]; | ||
/** | ||
* LoginHint | ||
* loginType if login uses popup | ||
* | ||
* @type {string} | ||
* @memberof Msal2Config | ||
* @type {LoginType} | ||
* @memberof Msal2ConfigBase | ||
*/ | ||
loginHint?: string; | ||
loginType?: LoginType; | ||
/** | ||
* Session ID | ||
* login hint value | ||
* | ||
* @type {string} | ||
* @memberof Msal2Config | ||
* @memberof Msal2ConfigBase | ||
*/ | ||
sid?: string; | ||
loginHint?: string; | ||
/** | ||
* Domain hint | ||
* Domain hint value | ||
* | ||
* @type {string} | ||
* @memberof Msal2Config | ||
* @memberof Msal2ConfigBase | ||
*/ | ||
@@ -82,4 +87,4 @@ domainHint?: string; | ||
* | ||
* @type {Prompt} | ||
* @memberof Msal2Config | ||
* @type {string} | ||
* @memberof Msal2ConfigBase | ||
*/ | ||
@@ -89,3 +94,3 @@ prompt?: PromptType; | ||
/** | ||
* Redirect URI | ||
* Session ID | ||
* | ||
@@ -95,22 +100,46 @@ * @type {string} | ||
*/ | ||
redirectUri?: string; | ||
sid?: string; | ||
} | ||
/** | ||
* Config for MSAL2.0 Authentication | ||
* | ||
* @export | ||
* @interface Msal2Config | ||
*/ | ||
export interface Msal2Config extends Msal2ConfigBase { | ||
/** | ||
* Authority URL | ||
* Client ID of app registration | ||
* | ||
* @type {string} | ||
* @type {boolean} | ||
* @memberof Msal2Config | ||
*/ | ||
authority?: string; | ||
clientId: string; | ||
/** | ||
* Other options | ||
* Disable multi account functionality | ||
* | ||
* @type {Configuration} | ||
* @type {boolean} | ||
* @memberof Msal2Config | ||
*/ | ||
options?: Configuration; | ||
isMultiAccountDisabled?: boolean; | ||
} | ||
/** | ||
* Config for MSAL 2.0 Authentication where a PublicClientApplication already exists | ||
* | ||
* @export | ||
* @interface Msal2PublicClientApplicationConfig | ||
*/ | ||
export interface Msal2PublicClientApplicationConfig extends Msal2ConfigBase { | ||
/** | ||
* Existing PublicClientApplication instance to use | ||
* | ||
* @type {PublicClientApplication} | ||
* @memberof Msal2PublicClientApplicationConfig | ||
*/ | ||
publicClientApplication: PublicClientApplication; | ||
} | ||
/** | ||
* Prompt type enum | ||
@@ -217,2 +246,14 @@ * | ||
/** | ||
* | ||
* Disables multi account functionality | ||
* @private | ||
* @type {boolean} | ||
* @memberof Msal2Provider | ||
*/ | ||
private _isMultipleAccountDisabled: boolean = false; | ||
public get isMultiAccountSupported(): boolean { | ||
return !this._isMultipleAccountDisabled; | ||
} | ||
private sessionStorageRequestedScopesKey = 'mgt-requested-scopes'; | ||
@@ -222,3 +263,3 @@ private sessionStorageDeniedScopesKey = 'mgt-denied-scopes'; | ||
public constructor(config: Msal2Config) { | ||
public constructor(config: Msal2Config | Msal2PublicClientApplicationConfig) { | ||
super(); | ||
@@ -235,49 +276,65 @@ this.initProvider(config); | ||
*/ | ||
private async initProvider(config: Msal2Config) { | ||
if (config.clientId) { | ||
const msalConfig: Configuration = config.options || { auth: { clientId: config.clientId } }; | ||
this.ms_config = msalConfig; | ||
this.ms_config.auth.clientId = config.clientId; | ||
if (config.authority) { | ||
this.ms_config.auth.authority = config.authority; | ||
} | ||
if (config.redirectUri) { | ||
this.ms_config.auth.redirectUri = config.redirectUri; | ||
} | ||
private async initProvider(config: Msal2Config | Msal2PublicClientApplicationConfig) { | ||
const msalConfig: Configuration = config.options || { auth: { clientId: '' } }; | ||
this.ms_config = msalConfig; | ||
this.ms_config.cache = msalConfig.cache || {}; | ||
this.ms_config.cache.cacheLocation = msalConfig.cache.cacheLocation || 'localStorage'; | ||
if ( | ||
typeof this.ms_config.cache.storeAuthStateInCookie === 'undefined' || | ||
this.ms_config.cache.storeAuthStateInCookie === null | ||
) { | ||
this.ms_config.cache.storeAuthStateInCookie = true; | ||
} | ||
this.ms_config.cache = msalConfig.cache || {}; | ||
this.ms_config.cache.cacheLocation = msalConfig.cache.cacheLocation || 'localStorage'; | ||
if ( | ||
typeof this.ms_config.cache.storeAuthStateInCookie === 'undefined' || | ||
this.ms_config.cache.storeAuthStateInCookie === null | ||
) { | ||
this.ms_config.cache.storeAuthStateInCookie = true; | ||
} | ||
this.ms_config.system = msalConfig.system || {}; | ||
this.ms_config.system.iframeHashTimeout = msalConfig.system.iframeHashTimeout || 10000; | ||
if (config.redirectUri) { | ||
this.ms_config.auth.redirectUri = config.redirectUri; | ||
if (config.authority) { | ||
this.ms_config.auth.authority = config.authority; | ||
} | ||
if (config.redirectUri) { | ||
this.ms_config.auth.redirectUri = config.redirectUri; | ||
} | ||
if ('clientId' in config) { | ||
if (config.clientId) { | ||
this.ms_config.auth.clientId = config.clientId; | ||
this._publicClientApplication = new PublicClientApplication(this.ms_config); | ||
} else { | ||
throw new Error('clientId must be provided'); | ||
} | ||
this.ms_config.system = msalConfig.system || {}; | ||
this.ms_config.system.iframeHashTimeout = msalConfig.system.iframeHashTimeout || 10000; | ||
this._loginType = typeof config.loginType !== 'undefined' ? config.loginType : LoginType.Redirect; | ||
this._loginHint = typeof config.loginHint !== 'undefined' ? config.loginHint : null; | ||
this._sid = typeof config.sid !== 'undefined' ? config.sid : null; | ||
this._domainHint = typeof config.domainHint !== 'undefined' ? config.domainHint : null; | ||
this.scopes = typeof config.scopes !== 'undefined' ? config.scopes : ['user.read']; | ||
this._publicClientApplication = new PublicClientApplication(this.ms_config); | ||
this._prompt = typeof config.prompt !== 'undefined' ? config.prompt : PromptType.SELECT_ACCOUNT; | ||
this.graph = createFromProvider(this); | ||
try { | ||
const tokenResponse = await this._publicClientApplication.handleRedirectPromise(); | ||
if (tokenResponse !== null) { | ||
this.handleResponse(tokenResponse?.account); | ||
} else { | ||
this.trySilentSignIn(); | ||
} | ||
} catch (e) { | ||
throw e; | ||
} else if ('publicClientApplication' in config) { | ||
if (config.publicClientApplication) { | ||
this._publicClientApplication = config.publicClientApplication; | ||
} else { | ||
throw new Error('publicClientApplication must be provided'); | ||
} | ||
} else { | ||
throw new Error('clientId must be provided'); | ||
throw new Error('either clientId or publicClientApplication must be provided'); | ||
} | ||
this.ms_config.system = msalConfig.system || {}; | ||
this.ms_config.system.iframeHashTimeout = msalConfig.system.iframeHashTimeout || 10000; | ||
this._loginType = typeof config.loginType !== 'undefined' ? config.loginType : LoginType.Redirect; | ||
this._loginHint = typeof config.loginHint !== 'undefined' ? config.loginHint : null; | ||
this._sid = typeof config.sid !== 'undefined' ? config.sid : null; | ||
this._domainHint = typeof config.domainHint !== 'undefined' ? config.domainHint : null; | ||
this.scopes = typeof config.scopes !== 'undefined' ? config.scopes : ['user.read']; | ||
this._prompt = typeof config.prompt !== 'undefined' ? config.prompt : PromptType.SELECT_ACCOUNT; | ||
const msal2config = config as Msal2Config; | ||
this._isMultipleAccountDisabled = | ||
typeof msal2config.isMultiAccountDisabled !== 'undefined' ? msal2config.isMultiAccountDisabled : false; | ||
this.graph = createFromProvider(this); | ||
try { | ||
const tokenResponse = await this._publicClientApplication.handleRedirectPromise(); | ||
if (tokenResponse !== null) { | ||
this.handleResponse(tokenResponse?.account); | ||
} else { | ||
this.trySilentSignIn(); | ||
} | ||
} catch (e) { | ||
throw e; | ||
} | ||
} | ||
@@ -350,3 +407,3 @@ | ||
this._publicClientApplication.getAllAccounts().forEach((account: AccountInfo) => { | ||
usernames.push({ username: account.username, id: account.homeAccountId } as IProviderAccount); | ||
usernames.push({ name: account.name, mail: account.username, id: account.homeAccountId } as IProviderAccount); | ||
}); | ||
@@ -369,2 +426,13 @@ return usernames; | ||
/** | ||
* Gets active account | ||
* | ||
* @return {*} | ||
* @memberof Msal2Provider | ||
*/ | ||
public getActiveAccount() { | ||
const account = this._publicClientApplication.getActiveAccount(); | ||
return { name: account.name, mail: account.username, id: account.homeAccountId } as IProviderAccount; | ||
} | ||
/** | ||
* Once a succesful login occurs, set the active account and store it | ||
@@ -378,4 +446,5 @@ * | ||
this.setActiveAccount({ | ||
username: account.name, | ||
id: account.homeAccountId | ||
name: account.name, | ||
id: account.homeAccountId, | ||
mail: account.username | ||
} as IProviderAccount); | ||
@@ -513,3 +582,3 @@ this.setState(ProviderState.SignedIn); | ||
*/ | ||
private getAccount(): AccountInfo | null { | ||
protected getAccount(): AccountInfo | null { | ||
const account = this.getStoredAccount(); | ||
@@ -540,3 +609,7 @@ if (account) { | ||
await this._publicClientApplication.logoutPopup({ ...logOutRequest }); | ||
this.setState(ProviderState.SignedOut); | ||
if (this._publicClientApplication.getAllAccounts.length == 1 || this._isMultipleAccountDisabled) { | ||
this.setState(ProviderState.SignedOut); | ||
} else { | ||
this.trySilentSignIn(); | ||
} | ||
} | ||
@@ -543,0 +616,0 @@ } |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
939152
1739
80
+ Added@microsoft/mgt-element@3.0.0-next.fluentui.cef0a0b(transitive)
- Removed@microsoft/mgt-element@2.3.0-preview.ef38de5(transitive)
Updated@azure/msal-browser@^2.14.2