@microsoft/mgt-msal2-provider
Advanced tools
Comparing version 2.2.0-next.msal2provider.d842c5b to 2.2.0-next.multi-accounts.1078dff
import { IProvider, LoginType, IProviderAccount } from '@microsoft/mgt-element'; | ||
import { Configuration, PublicClientApplication, AuthenticationResult } from '@azure/msal-browser'; | ||
import { Configuration, PublicClientApplication, AccountInfo } from '@azure/msal-browser'; | ||
import { AuthenticationProviderOptions } from '@microsoft/microsoft-graph-client/lib/es/IAuthenticationProviderOptions'; | ||
@@ -211,6 +211,6 @@ /** | ||
* | ||
* @param {(AuthenticationResult | null)} response | ||
* @param {(AuthenticationResult | null)} account | ||
* @memberof Msal2Provider | ||
*/ | ||
handleResponse(response: AuthenticationResult | null): void; | ||
handleResponse(account: AccountInfo): void; | ||
/** | ||
@@ -217,0 +217,0 @@ * Store the currently signed in account in storage |
@@ -99,3 +99,3 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
if (tokenResponse !== null) { | ||
this.handleResponse(tokenResponse); | ||
this.handleResponse(tokenResponse === null || tokenResponse === void 0 ? void 0 : tokenResponse.account); | ||
} | ||
@@ -129,11 +129,2 @@ else { | ||
silentRequest.loginHint = this._loginHint; | ||
} | ||
else { | ||
const account = this.getAccount(); | ||
if (account) { | ||
silentRequest.sid = account.idTokenClaims.sid || null; | ||
silentRequest.loginHint = account.idTokenClaims.preferred_username; | ||
} | ||
} | ||
if (silentRequest.sid || silentRequest.loginHint) { | ||
try { | ||
@@ -143,3 +134,3 @@ this.setState(ProviderState.Loading); | ||
if (response) { | ||
this.handleResponse(response); | ||
this.handleResponse(response === null || response === void 0 ? void 0 : response.account); | ||
} | ||
@@ -152,2 +143,9 @@ } | ||
else { | ||
const account = this.getAccount(); | ||
if (account) { | ||
if (yield this.getAccessToken(null)) { | ||
this.handleResponse(account); | ||
return; | ||
} | ||
} | ||
this.setState(ProviderState.SignedOut); | ||
@@ -173,3 +171,3 @@ } | ||
const response = yield this._publicClientApplication.loginPopup(loginRequest); | ||
this.handleResponse(response); | ||
this.handleResponse(response === null || response === void 0 ? void 0 : response.account); | ||
} | ||
@@ -209,10 +207,10 @@ else { | ||
* | ||
* @param {(AuthenticationResult | null)} response | ||
* @param {(AuthenticationResult | null)} account | ||
* @memberof Msal2Provider | ||
*/ | ||
handleResponse(response) { | ||
if (response !== null) { | ||
handleResponse(account) { | ||
if (account !== null) { | ||
this.setActiveAccount({ | ||
username: response.account.name, | ||
id: response.account.homeAccountId | ||
username: account.name, | ||
id: account.homeAccountId | ||
}); | ||
@@ -379,4 +377,3 @@ this.setState(ProviderState.SignedIn); | ||
scopes: scopes, | ||
loginHint: this._loginHint, | ||
domainHint: this._domainHint | ||
account: this.getAccount() | ||
}; | ||
@@ -383,0 +380,0 @@ try { |
{ | ||
"name": "@microsoft/mgt-msal2-provider", | ||
"version": "2.2.0-next.msal2provider.d842c5b", | ||
"version": "2.2.0-next.multi-accounts.1078dff", | ||
"description": "The Microsoft Graph Toolkit Msal 2.0 Provider", | ||
@@ -42,3 +42,3 @@ "keywords": [ | ||
"dependencies": { | ||
"@microsoft/mgt-element": "2.2.0-next.msal2provider.d842c5b", | ||
"@microsoft/mgt-element": "2.2.0-next.multi-accounts.1078dff", | ||
"@microsoft/microsoft-graph-client": "^2.2.1", | ||
@@ -45,0 +45,0 @@ "@azure/msal-browser": "^2.13.0" |
@@ -265,3 +265,3 @@ import { | ||
if (tokenResponse !== null) { | ||
this.handleResponse(tokenResponse); | ||
this.handleResponse(tokenResponse?.account); | ||
} else { | ||
@@ -291,10 +291,2 @@ this.trySilentSignIn(); | ||
silentRequest.loginHint = this._loginHint; | ||
} else { | ||
const account: any = this.getAccount(); | ||
if (account) { | ||
silentRequest.sid = account.idTokenClaims.sid || null; | ||
silentRequest.loginHint = account.idTokenClaims.preferred_username; | ||
} | ||
} | ||
if (silentRequest.sid || silentRequest.loginHint) { | ||
try { | ||
@@ -304,3 +296,3 @@ this.setState(ProviderState.Loading); | ||
if (response) { | ||
this.handleResponse(response); | ||
this.handleResponse(response?.account); | ||
} | ||
@@ -311,2 +303,9 @@ } catch (e) { | ||
} else { | ||
const account: AccountInfo = this.getAccount(); | ||
if (account) { | ||
if (await this.getAccessToken(null)) { | ||
this.handleResponse(account); | ||
return; | ||
} | ||
} | ||
this.setState(ProviderState.SignedOut); | ||
@@ -331,3 +330,3 @@ } | ||
const response = await this._publicClientApplication.loginPopup(loginRequest); | ||
this.handleResponse(response); | ||
this.handleResponse(response?.account); | ||
} else { | ||
@@ -368,10 +367,10 @@ const loginRedirectRequest: RedirectRequest = { ...loginRequest }; | ||
* | ||
* @param {(AuthenticationResult | null)} response | ||
* @param {(AuthenticationResult | null)} account | ||
* @memberof Msal2Provider | ||
*/ | ||
handleResponse(response: AuthenticationResult | null) { | ||
if (response !== null) { | ||
handleResponse(account: AccountInfo) { | ||
if (account !== null) { | ||
this.setActiveAccount({ | ||
username: response.account.name, | ||
id: response.account.homeAccountId | ||
username: account.name, | ||
id: account.homeAccountId | ||
} as IProviderAccount); | ||
@@ -548,6 +547,5 @@ this.setState(ProviderState.SignedIn); | ||
const scopes = options ? options.scopes || this.scopes : this.scopes; | ||
const accessTokenRequest = { | ||
const accessTokenRequest: SilentRequest = { | ||
scopes: scopes, | ||
loginHint: this._loginHint, | ||
domainHint: this._domainHint | ||
account: this.getAccount() | ||
}; | ||
@@ -554,0 +552,0 @@ try { |
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
917265
1570
+ Added@microsoft/mgt-element@2.2.0-next.multi-accounts.1078dff(transitive)
+ Addedidb@6.1.5(transitive)
- Removed@microsoft/mgt-element@2.2.0-next.msal2provider.d842c5b(transitive)
- Removedidb@5.0.8(transitive)
Updated@microsoft/mgt-element@2.2.0-next.multi-accounts.1078dff