@cognite/sdk-core
Advanced tools
Comparing version 1.1.0 to 1.2.0
@@ -6,2 +6,13 @@ # Change Log | ||
# [1.2.0](https://github.com/cognitedata/cognite-sdk-js/compare/@cognite/sdk-core@1.1.0...@cognite/sdk-core@1.2.0) (2021-03-05) | ||
### Features | ||
* **aad:** use LS state as source of truth ([#493](https://github.com/cognitedata/cognite-sdk-js/issues/493)) ([a03404c](https://github.com/cognitedata/cognite-sdk-js/commit/a03404c084d73c55ab22aeb29cd6724772c079a5)) | ||
# [1.1.0](https://github.com/cognitedata/cognite-sdk-js/compare/@cognite/sdk-core@1.0.6...@cognite/sdk-core@1.1.0) (2021-03-02) | ||
@@ -8,0 +19,0 @@ |
@@ -12,3 +12,2 @@ import { Configuration, AccountInfo, BrowserSystemOptions, CacheOptions } from '@azure/msal-browser'; | ||
private msalApplication; | ||
private account?; | ||
private userScopes; | ||
@@ -25,3 +24,3 @@ private cluster; | ||
*/ | ||
getAccount(): AccountInfo | null; | ||
getAccount(): AccountInfo | undefined; | ||
/** | ||
@@ -28,0 +27,0 @@ * Checks whether we are in the middle of a redirect and handles state accordingly. |
@@ -9,3 +9,3 @@ { | ||
"types": "dist/src/index.d.js", | ||
"version": "1.1.0", | ||
"version": "1.2.0", | ||
"scripts": { | ||
@@ -37,3 +37,3 @@ "clean": "rm -rf dist/ docs/", | ||
}, | ||
"gitHead": "67ba3382eef6cfbe045d31f1a3b43b194e7e4001" | ||
"gitHead": "c5b2a6722dc553a32fa85dfeef80e17e2e56d325" | ||
} |
@@ -71,3 +71,3 @@ import { AzureAD } from '../aad'; | ||
test('should return `null` in case any accounts in localstorage', () => { | ||
expect(azureAdClient.getAccount()).toEqual(null); | ||
expect(azureAdClient.getAccount()).toEqual(undefined); | ||
expect(getAccountByLocalId).toHaveBeenCalledTimes(0); | ||
@@ -92,3 +92,3 @@ }); | ||
}); | ||
test('should get account from localstorage as a fallback if its possible', async () => { | ||
test('should get account from localstorage', async () => { | ||
const localAccountId = 'some-local-account-id'; | ||
@@ -137,2 +137,5 @@ | ||
localStorageGetItem.mockReturnValueOnce(account.localAccountId); | ||
getAccountByLocalId.mockReturnValueOnce(account); | ||
await azureAdClient.login('loginPopup'); | ||
@@ -139,0 +142,0 @@ const token = await azureAdClient.getCDFToken(); |
@@ -50,3 +50,2 @@ // Copyright 2020 Cognite AS | ||
private msalApplication: PublicClientApplication; | ||
private account?: AccountInfo; | ||
private userScopes = ['User.Read']; | ||
@@ -83,8 +82,8 @@ private cluster: string = ''; | ||
*/ | ||
getAccount(): AccountInfo | null { | ||
getAccount(): AccountInfo | undefined { | ||
const localAccountId = this.getLocalAccountIdFromLocalStorage(); | ||
return localAccountId | ||
? this.msalApplication.getAccountByLocalId(localAccountId) | ||
: null; | ||
? this.msalApplication.getAccountByLocalId(localAccountId) || undefined | ||
: undefined; | ||
} | ||
@@ -131,3 +130,3 @@ | ||
const logOutRequest: EndSessionRequest = { | ||
account: this.account || undefined, | ||
account: this.getAccount(), | ||
}; | ||
@@ -138,4 +137,2 @@ | ||
this.setLocalAccountIdToLocalStorage(); | ||
this.account = undefined; | ||
} | ||
@@ -147,3 +144,3 @@ | ||
async getCDFToken(): Promise<string | null> { | ||
if (!this.account) return null; | ||
if (!this.getAccount()) return null; | ||
@@ -164,3 +161,3 @@ const { | ||
async getAccountToken(): Promise<string | null> { | ||
if (this.account) return null; | ||
if (!this.getAccount()) return null; | ||
@@ -200,3 +197,3 @@ const { | ||
return { | ||
account: this.account, | ||
account: this.getAccount(), | ||
scopes: this.getCDFScopes(), | ||
@@ -208,3 +205,3 @@ }; | ||
return { | ||
account: this.account, | ||
account: this.getAccount(), | ||
scopes: this.userScopes, | ||
@@ -220,3 +217,2 @@ }; | ||
if (account) { | ||
this.account = account; | ||
this.setLocalAccountIdToLocalStorage(account.localAccountId); | ||
@@ -223,0 +219,0 @@ |
Sorry, the diff of this file is too big to display
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
387541
8488