Skip to content

Commit 8316ee5

Browse files
authored
Add extraQueryParams for api calls (#7974)
1 parent 3c2bf55 commit 8316ee5

File tree

12 files changed

+281
-33
lines changed

12 files changed

+281
-33
lines changed
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"type": "minor",
3+
"comment": "Add extraQueryParams for api calls #7974",
4+
"packageName": "@azure/msal-browser",
5+
"email": "yongdiwang@microsoft.com",
6+
"dependentChangeType": "minor"
7+
}

lib/msal-browser/src/custom_auth/configuration/CustomAuthConfiguration.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import {
1111
export type CustomAuthOptions = {
1212
challengeTypes?: Array<string>;
1313
authApiProxyUrl: string;
14+
customAuthApiQueryParams?: Record<string, string>;
1415
capabilities?: Array<string>;
1516
};
1617

lib/msal-browser/src/custom_auth/controller/CustomAuthStandardController.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,8 @@ export class CustomAuthStandardController
113113
this.authority.getCustomAuthApiDomain(),
114114
this.customAuthConfig.auth.clientId,
115115
new FetchHttpClient(this.logger),
116-
this.customAuthConfig.customAuth?.capabilities?.join(" ")
116+
this.customAuthConfig.customAuth?.capabilities?.join(" "),
117+
this.customAuthConfig.customAuth?.customAuthApiQueryParams
117118
),
118119
this.authority
119120
);

lib/msal-browser/src/custom_auth/core/interaction_client/CustomAuthInteractionClientBase.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ export abstract class CustomAuthInteractionClientBase extends StandardInteractio
6464

6565
protected getScopes(scopes: string[] | undefined): string[] {
6666
if (!!scopes && scopes.length > 0) {
67-
scopes;
67+
return scopes;
6868
}
6969

7070
return [

lib/msal-browser/src/custom_auth/core/network_client/custom_auth_api/BaseApiClient.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@ export abstract class BaseApiClient {
2727
constructor(
2828
baseUrl: string,
2929
private readonly clientId: string,
30-
private httpClient: IHttpClient
30+
private httpClient: IHttpClient,
31+
private customAuthApiQueryParams?: Record<string, string>
3132
) {
3233
this.baseRequestUrl = parseUrl(
3334
!baseUrl.endsWith("/") ? `${baseUrl}/` : baseUrl
@@ -45,7 +46,11 @@ export abstract class BaseApiClient {
4546
...data,
4647
});
4748
const headers = this.getCommonHeaders(correlationId, telemetryManager);
48-
const url = buildUrl(this.baseRequestUrl.href, endpoint);
49+
const url = buildUrl(
50+
this.baseRequestUrl.href,
51+
endpoint,
52+
this.customAuthApiQueryParams
53+
);
4954

5055
let response: Response;
5156

lib/msal-browser/src/custom_auth/core/network_client/custom_auth_api/CustomAuthApiClient.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,25 +18,29 @@ export class CustomAuthApiClient implements ICustomAuthApiClient {
1818
customAuthApiBaseUrl: string,
1919
clientId: string,
2020
httpClient: IHttpClient,
21-
capabilities?: string
21+
capabilities?: string,
22+
customAuthApiQueryParams?: Record<string, string>
2223
) {
2324
this.signInApi = new SignInApiClient(
2425
customAuthApiBaseUrl,
2526
clientId,
2627
httpClient,
27-
capabilities
28+
capabilities,
29+
customAuthApiQueryParams
2830
);
2931
this.signUpApi = new SignupApiClient(
3032
customAuthApiBaseUrl,
3133
clientId,
3234
httpClient,
33-
capabilities
35+
capabilities,
36+
customAuthApiQueryParams
3437
);
3538
this.resetPasswordApi = new ResetPasswordApiClient(
3639
customAuthApiBaseUrl,
3740
clientId,
3841
httpClient,
39-
capabilities
42+
capabilities,
43+
customAuthApiQueryParams
4044
);
4145
}
4246
}

lib/msal-browser/src/custom_auth/core/network_client/custom_auth_api/ResetPasswordApiClient.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,15 @@ export class ResetPasswordApiClient extends BaseApiClient {
3434
customAuthApiBaseUrl: string,
3535
clientId: string,
3636
httpClient: IHttpClient,
37-
capabilities?: string
37+
capabilities?: string,
38+
customAuthApiQueryParams?: Record<string, string>
3839
) {
39-
super(customAuthApiBaseUrl, clientId, httpClient);
40+
super(
41+
customAuthApiBaseUrl,
42+
clientId,
43+
httpClient,
44+
customAuthApiQueryParams
45+
);
4046
this.capabilities = capabilities;
4147
}
4248

lib/msal-browser/src/custom_auth/core/network_client/custom_auth_api/SignInApiClient.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,15 @@ export class SignInApiClient extends BaseApiClient {
3030
customAuthApiBaseUrl: string,
3131
clientId: string,
3232
httpClient: IHttpClient,
33-
capabilities?: string
33+
capabilities?: string,
34+
customAuthApiQueryParams?: Record<string, string>
3435
) {
35-
super(customAuthApiBaseUrl, clientId, httpClient);
36+
super(
37+
customAuthApiBaseUrl,
38+
clientId,
39+
httpClient,
40+
customAuthApiQueryParams
41+
);
3642
this.capabilities = capabilities;
3743
}
3844

lib/msal-browser/src/custom_auth/core/network_client/custom_auth_api/SignupApiClient.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,15 @@ export class SignupApiClient extends BaseApiClient {
2727
customAuthApiBaseUrl: string,
2828
clientId: string,
2929
httpClient: IHttpClient,
30-
capabilities?: string
30+
capabilities?: string,
31+
customAuthApiQueryParams?: Record<string, string>
3132
) {
32-
super(customAuthApiBaseUrl, clientId, httpClient);
33+
super(
34+
customAuthApiBaseUrl,
35+
clientId,
36+
httpClient,
37+
customAuthApiQueryParams
38+
);
3339
this.capabilities = capabilities;
3440
}
3541

lib/msal-browser/src/custom_auth/core/utils/UrlUtils.ts

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,23 @@ export function parseUrl(url: string): URL {
1717
}
1818
}
1919

20-
export function buildUrl(baseUrl: string, path: string): URL {
20+
export function buildUrl(
21+
baseUrl: string,
22+
path: string,
23+
queryParams?: Record<string, string>
24+
): URL {
2125
const newBaseUrl = !baseUrl.endsWith("/") ? `${baseUrl}/` : baseUrl;
2226
const newPath = path.startsWith("/") ? path.slice(1) : path;
2327
const url = new URL(newPath, newBaseUrl);
28+
29+
// Add query parameters if provided
30+
if (queryParams) {
31+
Object.entries(queryParams).forEach(([key, value]) => {
32+
if (value !== undefined && value !== null) {
33+
url.searchParams.set(key, String(value));
34+
}
35+
});
36+
}
37+
2438
return url;
2539
}

0 commit comments

Comments
 (0)