Skip to content

Commit 9939c27

Browse files
Make account info mandatory for AuthenticationResult and CacheRecord types. (#6156)
- Make account info mandatory for `AuthenticationResult` type. - Make account info mandatory for `CacheRecord` type.
1 parent 533afa1 commit 9939c27

27 files changed

+83
-39
lines changed
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"type": "prerelease",
3+
"comment": "Make account info mandatory for AuthenticationResult and CacheRecord types #6156",
4+
"packageName": "@azure/msal-browser",
5+
"email": "[email protected]",
6+
"dependentChangeType": "prerelease"
7+
}

lib/msal-browser/src/app/IPublicClientApplication.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
*/
55

66
import {
7-
AuthenticationResult,
87
AccountInfo,
98
Logger,
109
PerformanceCallbackFunction,
@@ -21,6 +20,7 @@ import { EndSessionPopupRequest } from "../request/EndSessionPopupRequest";
2120
import { ITokenCache } from "../cache/ITokenCache";
2221
import { AuthorizationCodeRequest } from "../request/AuthorizationCodeRequest";
2322
import { BrowserConfiguration } from "../config/Configuration";
23+
import { AuthenticationResult } from "../response/AuthenticationResult";
2424

2525
export interface IPublicClientApplication {
2626
initialize(): Promise<void>;

lib/msal-browser/src/app/PublicClientApplication.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ import { WrapperSKU } from "../utils/BrowserConstants";
1313
import { IPublicClientApplication } from "./IPublicClientApplication";
1414
import { IController } from "../controllers/IController";
1515
import {
16-
AuthenticationResult,
1716
PerformanceCallbackFunction,
1817
AccountInfo,
1918
Logger,
@@ -24,6 +23,7 @@ import { ControllerFactory } from "../controllers/ControllerFactory";
2423
import { StandardController } from "../controllers/StandardController";
2524
import { BrowserConfiguration, Configuration } from "../config/Configuration";
2625
import { StandardOperatingContext } from "../operatingcontext/StandardOperatingContext";
26+
import { AuthenticationResult } from "../response/AuthenticationResult";
2727

2828
/**
2929
* The PublicClientApplication class is the object exposed by the library to perform authentication and authorization functions in Single Page Applications

lib/msal-browser/src/cache/ITokenCache.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@
44
*/
55

66
import {
7-
ExternalTokenResponse,
8-
AuthenticationResult,
7+
ExternalTokenResponse
98
} from "@azure/msal-common";
109
import { SilentRequest } from "../request/SilentRequest";
1110
import { LoadTokenOptions } from "./TokenCache";
11+
import { AuthenticationResult } from "../response/AuthenticationResult";
1212

1313
export interface ITokenCache {
1414
/**

lib/msal-browser/src/cache/TokenCache.ts

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,15 @@ import {
1616
AuthToken,
1717
RefreshTokenEntity,
1818
AuthorityType,
19-
CacheRecord,
20-
AuthenticationResult,
2119
Constants,
2220
} from "@azure/msal-common";
2321
import { BrowserConfiguration } from "../config/Configuration";
2422
import { SilentRequest } from "../request/SilentRequest";
2523
import { BrowserCacheManager } from "./BrowserCacheManager";
2624
import { ITokenCache } from "./ITokenCache";
2725
import { BrowserAuthError } from "../error/BrowserAuthError";
26+
import { AuthenticationResult } from "../response/AuthenticationResult";
27+
import { CacheRecord } from "./entities/CacheRecord";
2828

2929
export type LoadTokenOptions = {
3030
clientInfo?: string;
@@ -84,7 +84,7 @@ export class TokenCache implements ITokenCache {
8484

8585
const idToken = new AuthToken(response.id_token, this.cryptoObj);
8686

87-
let cacheRecord: CacheRecord | undefined;
87+
let cacheRecord: CacheRecord;
8888
let authority: Authority | undefined;
8989

9090
if (request.account) {
@@ -435,7 +435,7 @@ export class TokenCache implements ITokenCache {
435435
private generateAuthenticationResult(
436436
request: SilentRequest,
437437
idTokenObj: AuthToken,
438-
cacheRecord?: CacheRecord,
438+
cacheRecord: CacheRecord,
439439
authority?: Authority
440440
): AuthenticationResult {
441441
let accessToken: string = Constants.EMPTY_STRING;
@@ -469,9 +469,7 @@ export class TokenCache implements ITokenCache {
469469
uniqueId: uid,
470470
tenantId: tid,
471471
scopes: responseScopes,
472-
account: cacheRecord?.account
473-
? cacheRecord.account.getAccountInfo()
474-
: null,
472+
account: cacheRecord.account.getAccountInfo(),
475473
idToken: idTokenObj ? idTokenObj.rawToken : Constants.EMPTY_STRING,
476474
idTokenClaims: idTokenObj ? idTokenObj.claims : {},
477475
accessToken: accessToken,
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
/*
2+
* Copyright (c) Microsoft Corporation. All rights reserved.
3+
* Licensed under the MIT License.
4+
*/
5+
6+
import {
7+
AccessTokenEntity,
8+
AccountEntity,
9+
AppMetadataEntity,
10+
CacheRecord as CommonCacheRecord,
11+
IdTokenEntity,
12+
RefreshTokenEntity
13+
} from "@azure/msal-common";
14+
15+
export class CacheRecord extends CommonCacheRecord {
16+
account: AccountEntity;
17+
18+
constructor(
19+
accountEntity: AccountEntity,
20+
idTokenEntity?: IdTokenEntity | null,
21+
accessTokenEntity?: AccessTokenEntity | null,
22+
refreshTokenEntity?: RefreshTokenEntity | null,
23+
appMetadataEntity?: AppMetadataEntity | null
24+
) {
25+
super(accountEntity, idTokenEntity, accessTokenEntity, refreshTokenEntity, appMetadataEntity);
26+
this.account = accountEntity;
27+
}
28+
}

lib/msal-browser/src/controllers/IController.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
*/
55

66
import {
7-
AuthenticationResult,
87
AccountInfo,
98
Logger,
109
PerformanceCallbackFunction,
@@ -28,6 +27,7 @@ import { NativeMessageHandler } from "../broker/nativeBroker/NativeMessageHandle
2827
import { EventHandler } from "../event/EventHandler";
2928
import { PopupClient } from "../interaction_client/PopupClient";
3029
import { SilentIframeClient } from "../interaction_client/SilentIframeClient";
30+
import { AuthenticationResult } from "../response/AuthenticationResult";
3131

3232
export interface IController {
3333
initialize(): Promise<void>;

lib/msal-browser/src/controllers/StandardController.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import {
99
AccountInfo,
1010
Constants,
1111
INetworkModule,
12-
AuthenticationResult,
1312
Logger,
1413
CommonSilentFlowRequest,
1514
ICrypto,
@@ -72,6 +71,7 @@ import { StandardOperatingContext } from "../operatingcontext/StandardOperatingC
7271
import { BaseOperatingContext } from "../operatingcontext/BaseOperatingContext";
7372
import { version, name } from "../packageMetadata";
7473
import { IController } from "./IController";
74+
import { AuthenticationResult } from "../response/AuthenticationResult";
7575

7676
export class StandardController implements IController {
7777
// OperatingContext

lib/msal-browser/src/event/EventMessage.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
*/
55

66
import {
7-
AuthenticationResult,
87
AuthError,
98
AccountInfo,
109
} from "@azure/msal-common";
@@ -16,6 +15,7 @@ import {
1615
SilentRequest,
1716
SsoSilentRequest,
1817
EndSessionRequest,
18+
AuthenticationResult,
1919
} from "..";
2020

2121
export type EventMessage = {

lib/msal-browser/src/index.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ export { EndSessionRequest } from "./request/EndSessionRequest";
6666
export { EndSessionPopupRequest } from "./request/EndSessionPopupRequest";
6767
export { AuthorizationUrlRequest } from "./request/AuthorizationUrlRequest";
6868
export { AuthorizationCodeRequest } from "./request/AuthorizationCodeRequest";
69+
export { AuthenticationResult } from "./response/AuthenticationResult";
6970

7071
// Cache
7172
export { LoadTokenOptions } from "./cache/TokenCache";
@@ -94,8 +95,6 @@ export {
9495
// Account
9596
AccountInfo,
9697
AccountEntity,
97-
// Response
98-
AuthenticationResult,
9998
IdTokenClaims,
10099
// Error
101100
AuthError,

0 commit comments

Comments
 (0)