Hi all,
I've been adapting the purecloud-premium-app sample wizard for our ISV submission and ran into a behavior I'd like to confirm.
When using PKCE Grant (which the docs now recommend over the deprecated Implicit Grant), Genesys redirects back to the wizard with ?code=...&state=... in the search string. After this redirect, in docs/wizard/scripts/utils.js, the getQueryParameters() function falls into:
} else if (window.location.search) {
let urlParams = new URLSearchParams(window.location.search);
let language = urlParams.get(config.languageQueryParam);
let environment = urlParams.get(config.genesysCloudEnvironmentQueryParam);
let hostOrigin = urlParams.get(config.genesysCloudHostOriginQueryParam);
let targetEnv = urlParams.get(config.genesysCloudTargetEnvQueryParam);
// ...
}
This branch only knows how to parse the original langTag/hostOrigin/targetEnv query params from a first invocation and it does not decode the state param, that is sent by the OAuth authorization service.
As a result appParams is empty, and setup() falls back to gcEnvironment = config.defaultGcEnvironment. The PKCE token exchange is then attempted on the wrong region's login.<env> endpoint.
When wizard used to authenticate using implicit grant, the URL was built with a hash (#). Since code has beed adapted to PKCE, the URL is no longer built with a hash, but with a question mark (?). The getQueryParameters method has not beed adapted to this new kind of URL, and as a result it does not decode the state.
Here is my workaround:
} else if (window.location.search) {
let urlParams = new URLSearchParams(window.location.search);
if (urlParams.has('code')) {
// PKCE Grant success: state contains the original appParams
let stateParam = urlParams.get('state');
if (stateParam) {
ret = JSON.parse(decodeURIComponent(stateParam));
} else {
ret.errorCode = "400";
ret.errorDescription = "Missing state";
ret.error = true;
}
} else if (urlParams.has('error')) {
// PKCE Grant error
let stateParam = urlParams.get('state');
if (stateParam) {
ret = JSON.parse(decodeURIComponent(stateParam));
}
ret.error = true;
ret.errorCode = urlParams.get('error');
ret.errorDescription = urlParams.get('error_description');
} else {
// First invocation: params provided directly in URL
let language = urlParams.get(config.languageQueryParam);
let environment = urlParams.get(config.genesysCloudEnvironmentQueryParam);
let hostOrigin = urlParams.get(config.genesysCloudHostOriginQueryParam);
let targetEnv = urlParams.get(config.genesysCloudTargetEnvQueryParam);
let uninstall = urlParams.get('uninstall');
if (language) ret.language = language;
if (environment) ret.environment = environment;
if (hostOrigin) ret.hostOrigin = hostOrigin;
if (targetEnv) ret.targetEnv = targetEnv;
if (uninstall) ret.uninstall = uninstall;
}
}
This is essentialy the same process as with hash mark.
Has anyone else encountered this?
Note that in our case, the issue would have gone unnoticed if our defaultGcEnvironment had matched our test org's region.
Regards,
Sylvain.
#Integrations
------------------------------
Sylvain RIBEYRON
------------------------------