Skip to content

Commit e8d6784

Browse files
committed
fix(module-msal): handle both v2 and v4 request formats in proxy provider
Add request format detection to support both v2 format ({ scopes, account }) and v4 format ({ request: { scopes, account } }) in acquireToken and acquireAccessToken methods.
1 parent a768715 commit e8d6784

File tree

2 files changed

+33
-6
lines changed

2 files changed

+33
-6
lines changed
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
---
2+
"@equinor/fusion-framework-module-msal": patch
3+
---
4+
5+
Fix request format handling in v2 proxy provider to support both v2 and v4 request formats.
6+
7+
The `acquireToken` and `acquireAccessToken` methods in the v2 proxy provider now correctly detect and handle requests in both v2 format (`{ scopes, account }`) and v4 format (`{ request: { scopes, account } }`), ensuring compatibility with both API versions.
8+

packages/modules/msal/src/v2/create-proxy-provider.ts

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,31 @@
11
import type { IMsalProvider } from '../MsalProvider.interface';
22
import type { IMsalProvider as IMsalProvider_v2 } from './MsalProvider.interface';
33
import type { AccountInfo as AccountInfo_v2 } from './types';
4+
import type { AcquireTokenOptions } from '../MsalClient.interface';
45
import { createProxyClient } from './create-proxy-client';
56
import { mapAccountInfo } from './map-account-info';
67
import { MsalModuleVersion } from '../static';
78

9+
/**
10+
* Checks if a request is in MSAL v4 format.
11+
*
12+
* @param req - The request object to check
13+
* @returns True if the request is in v4 format (has a `request` property with `scopes` and `account`)
14+
*/
15+
function isRequestV4(
16+
req: unknown,
17+
): req is AcquireTokenOptions {
18+
if (typeof req !== 'object' || req === null) {
19+
return false;
20+
}
21+
const requestV4 = req as AcquireTokenOptions;
22+
return (
23+
typeof requestV4.request === 'object' &&
24+
requestV4.request !== null &&
25+
'request' in requestV4
26+
);
27+
}
28+
829
/**
930
* Creates a proxy provider for MSAL v2 compatibility.
1031
*
@@ -74,9 +95,8 @@ export function createProxyProvider(provider: IMsalProvider): IMsalProvider_v2 {
7495
scopes: string[];
7596
account?: AccountInfo_v2;
7697
}) => {
77-
const result = await target.acquireToken({
78-
request: { scopes: req.scopes, account: req.account },
79-
});
98+
const request = isRequestV4(req) ? req : { scopes: req.scopes, account: req.account };
99+
const result = await target.acquireToken(request as AcquireTokenOptions);
80100

81101
// Convert null to undefined for v2 compatibility
82102
return result || undefined;
@@ -89,9 +109,8 @@ export function createProxyProvider(provider: IMsalProvider): IMsalProvider_v2 {
89109
scopes: string[];
90110
account?: AccountInfo_v2;
91111
}) => {
92-
return await target.acquireAccessToken({
93-
request: { scopes: req.scopes, account: req.account },
94-
});
112+
const request = isRequestV4(req) ? req : { scopes: req.scopes, account: req.account };
113+
return await target.acquireAccessToken(request as AcquireTokenOptions);
95114
};
96115
return acquireAccessToken;
97116
}

0 commit comments

Comments
 (0)