Skip to content

Add config option to not encode extra params #7694

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 11 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "patch",
"comment": "Add config option to not encode extra params",
"packageName": "@azure/msal-browser",
"email": "[email protected]",
"dependentChangeType": "patch"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "patch",
"comment": "Add config option to not encode extra params",
"packageName": "@azure/msal-common",
"email": "[email protected]",
"dependentChangeType": "patch"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "patch",
"comment": "Add config option to not encode extra params",
"packageName": "@azure/msal-node",
"email": "[email protected]",
"dependentChangeType": "patch"
}
3 changes: 2 additions & 1 deletion lib/msal-browser/apiReview/msal-browser.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -446,6 +446,7 @@ export type BrowserAuthOptions = {
supportsNestedAppAuth?: boolean;
onRedirectNavigate?: (url: string) => boolean | void;
instanceAware?: boolean;
encodeExtraQueryParams?: boolean;
};

// Warning: (ae-missing-release-tag) "BrowserCacheLocation" is part of the package's API, but it is missing a release tag (@alpha, @beta, @public, or @internal)
Expand Down Expand Up @@ -1785,7 +1786,7 @@ export type WrapperSKU = (typeof WrapperSKU)[keyof typeof WrapperSKU];
// src/cache/LocalStorage.ts:296:8 - (tsdoc-param-tag-missing-hyphen) The @param block should be followed by a parameter name and then a hyphen
// src/cache/LocalStorage.ts:354:8 - (tsdoc-param-tag-missing-hyphen) The @param block should be followed by a parameter name and then a hyphen
// src/cache/LocalStorage.ts:385:8 - (tsdoc-param-tag-missing-hyphen) The @param block should be followed by a parameter name and then a hyphen
// src/config/Configuration.ts:247:5 - (ae-forgotten-export) The symbol "InternalAuthOptions" needs to be exported by the entry point index.d.ts
// src/config/Configuration.ts:252:5 - (ae-forgotten-export) The symbol "InternalAuthOptions" needs to be exported by the entry point index.d.ts
// src/event/EventHandler.ts:113:8 - (tsdoc-param-tag-missing-hyphen) The @param block should be followed by a parameter name and then a hyphen
// src/event/EventHandler.ts:139:8 - (tsdoc-param-tag-missing-hyphen) The @param block should be followed by a parameter name and then a hyphen
// src/index.ts:8:12 - (tsdoc-characters-after-block-tag) The token "@azure" looks like a TSDoc tag but contains an invalid character "/"; if it is not a tag, use a backslash to escape the "@"
Expand Down
6 changes: 6 additions & 0 deletions lib/msal-browser/src/config/Configuration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,11 @@ export type BrowserAuthOptions = {
* Flag of whether the STS will send back additional parameters to specify where the tokens should be retrieved from.
*/
instanceAware?: boolean;
/**
* Flag of whether to encode query parameters
* @deprecated This flag is deprecated and will be removed in the next major version where all extra query params will be encoded by default.
*/
encodeExtraQueryParams?: boolean;
};

/** @internal */
Expand Down Expand Up @@ -296,6 +301,7 @@ export function buildConfiguration(
skipAuthorityMetadataCache: false,
supportsNestedAppAuth: false,
instanceAware: false,
encodeExtraQueryParams: false,
};

// Default cache options for browser
Expand Down
14 changes: 12 additions & 2 deletions lib/msal-browser/src/protocol/Authorize.ts
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,12 @@ export async function getAuthCodeRequestUrl(
request.extraQueryParameters || {}
);

return AuthorizeProtocol.getAuthorizeUrl(authority, parameters);
return AuthorizeProtocol.getAuthorizeUrl(
authority,
parameters,
config.auth.encodeExtraQueryParams,
request.extraQueryParameters
);
}

/**
Expand Down Expand Up @@ -195,7 +200,12 @@ export async function getEARForm(
queryParams,
request.extraQueryParameters || {}
);
const url = AuthorizeProtocol.getAuthorizeUrl(authority, queryParams);
const url = AuthorizeProtocol.getAuthorizeUrl(
authority,
queryParams,
config.auth.encodeExtraQueryParams,
request.extraQueryParameters
);

return createForm(frame, url, parameters);
}
Expand Down
5 changes: 3 additions & 2 deletions lib/msal-common/apiReview/msal-common.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -628,6 +628,7 @@ export type AuthOptions = {
azureCloudOptions?: AzureCloudOptions;
skipAuthorityMetadataCache?: boolean;
instanceAware?: boolean;
encodeExtraQueryParams?: boolean;
};

// Warning: (ae-internal-missing-underscore) The name "Authority" should be prefixed with an underscore because the declaration is marked as @internal
Expand Down Expand Up @@ -2312,7 +2313,7 @@ function getAuthorizationCodePayload(serverParams: AuthorizeResponse, cachedStat
// Warning: (ae-missing-release-tag) "getAuthorizeUrl" is part of the package's API, but it is missing a release tag (@alpha, @beta, @public, or @internal)
//
// @public
function getAuthorizeUrl(authority: Authority, requestParameters: Map<string, string>): string;
function getAuthorizeUrl(authority: Authority, requestParameters: Map<string, string>, encodeParams?: boolean, extraQueryParameters?: StringDict | undefined): string;

// Warning: (ae-missing-release-tag) "getClientAssertion" is part of the package's API, but it is missing a release tag (@alpha, @beta, @public, or @internal)
//
Expand Down Expand Up @@ -2949,7 +2950,7 @@ const logoutRequestEmpty = "logout_request_empty";
// Warning: (ae-missing-release-tag) "mapToQueryString" is part of the package's API, but it is missing a release tag (@alpha, @beta, @public, or @internal)
//
// @public
function mapToQueryString(parameters: Map<string, string>): string;
function mapToQueryString(parameters: Map<string, string>, encodeExtraParams?: boolean, extraQueryParameters?: StringDict): string;

// Warning: (ae-missing-release-tag) "maxAgeTranspired" is part of the package's API, but it is missing a release tag (@alpha, @beta, @public, or @internal)
//
Expand Down
6 changes: 5 additions & 1 deletion lib/msal-common/src/client/AuthorizationCodeClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -507,6 +507,10 @@ export class AuthorizationCodeClient extends BaseClient {
RequestParameterBuilder.addInstanceAware(parameters);
}

return UrlUtils.mapToQueryString(parameters);
return UrlUtils.mapToQueryString(
parameters,
this.config.authOptions.encodeExtraQueryParams,
request.extraQueryParameters
);
}
}
6 changes: 6 additions & 0 deletions lib/msal-common/src/config/ClientConfiguration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ export type CommonClientConfiguration = {
* - skipAuthorityMetadataCache - A flag to choose whether to use or not use the local metadata cache during authority initialization. Defaults to false.
* - instanceAware - A flag of whether the STS will send back additional parameters to specify where the tokens should be retrieved from.
* - redirectUri - The redirect URI where authentication responses can be received by your application. It must exactly match one of the redirect URIs registered in the Azure portal.
* - encodeExtraQueryParams - A flag to choose whether to encode the extra query parameters or not. Defaults to false.
* @internal
*/
export type AuthOptions = {
Expand All @@ -93,6 +94,10 @@ export type AuthOptions = {
azureCloudOptions?: AzureCloudOptions;
skipAuthorityMetadataCache?: boolean;
instanceAware?: boolean;
/**
* @deprecated This flag is deprecated and will be removed in the next major version where all extra query params will be encoded by default.
*/
encodeExtraQueryParams?: boolean;
};

/**
Expand Down Expand Up @@ -276,6 +281,7 @@ function buildAuthOptions(authOptions: AuthOptions): Required<AuthOptions> {
azureCloudOptions: DEFAULT_AZURE_CLOUD_OPTIONS,
skipAuthorityMetadataCache: false,
instanceAware: false,
encodeExtraQueryParams: false,
...authOptions,
};
}
Expand Down
12 changes: 9 additions & 3 deletions lib/msal-common/src/protocol/Authorize.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import {
isInteractionRequiredError,
} from "../error/InteractionRequiredAuthError.js";
import { ServerError } from "../error/ServerError.js";
import { StringDict } from "../utils/MsalTypes.js";

/**
* Returns map of parameters that are applicable to all calls to /authorize whether using PKCE or EAR
Expand Down Expand Up @@ -264,10 +265,15 @@ export function getStandardAuthorizeRequestParameters(
*/
export function getAuthorizeUrl(
authority: Authority,
requestParameters: Map<string, string>
requestParameters: Map<string, string>,
encodeParams?: boolean,
extraQueryParameters?: StringDict | undefined
): string {
const queryString = mapToQueryString(requestParameters);

const queryString = mapToQueryString(
requestParameters,
encodeParams,
extraQueryParameters
);
return UrlString.appendQueryString(
authority.authorizationEndpoint,
queryString
Expand Down
17 changes: 15 additions & 2 deletions lib/msal-common/src/utils/UrlUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
ClientAuthErrorCodes,
createClientAuthError,
} from "../error/ClientAuthError.js";
import { StringDict } from "./MsalTypes.js";

/**
* Parses hash string from given string. Returns empty string if no hash symbol is found.
Expand Down Expand Up @@ -64,11 +65,23 @@ export function getDeserializedResponse(
/**
* Utility to create a URL from the params map
*/
export function mapToQueryString(parameters: Map<string, string>): string {
export function mapToQueryString(
parameters: Map<string, string>,
encodeExtraParams: boolean = true,
extraQueryParameters?: StringDict
): string {
const queryParameterArray: Array<string> = new Array<string>();

parameters.forEach((value, key) => {
queryParameterArray.push(`${key}=${encodeURIComponent(value)}`);
if (
!encodeExtraParams &&
extraQueryParameters &&
key in extraQueryParameters
) {
queryParameterArray.push(`${key}=${value}`);
} else {
queryParameterArray.push(`${key}=${encodeURIComponent(value)}`);
}
});

return queryParameterArray.join("&");
Expand Down
Loading
Loading