From a0a67e671f8614d17234c421173f395703d97b19 Mon Sep 17 00:00:00 2001 From: Arnav Palnitkar Date: Fri, 13 May 2022 09:58:56 -0700 Subject: [PATCH] Fix OIDC callback query params (#15378) * Fix OIDC callback query params - Value of namespace was getting stripped from the state query param - Used native URL search param api to fetch the values * Add changelog * Remove unnecessary check for url encoding * Extract ns value and pass as namespace param * Update changelog --- changelog/15378.txt | 3 +++ ui/app/routes/vault/cluster/oidc-callback.js | 19 ++++++++++++++++++- 2 files changed, 21 insertions(+), 1 deletion(-) create mode 100644 changelog/15378.txt diff --git a/changelog/15378.txt b/changelog/15378.txt new file mode 100644 index 000000000..bb752e691 --- /dev/null +++ b/changelog/15378.txt @@ -0,0 +1,3 @@ +```release-note:improvement +ui: Allow namespace param to be parsed from state queryParam +``` \ No newline at end of file diff --git a/ui/app/routes/vault/cluster/oidc-callback.js b/ui/app/routes/vault/cluster/oidc-callback.js index c26ac6e55..27a2f3b58 100644 --- a/ui/app/routes/vault/cluster/oidc-callback.js +++ b/ui/app/routes/vault/cluster/oidc-callback.js @@ -6,11 +6,28 @@ export default Route.extend({ // left blank so we render the template immediately }, afterModel() { - let { auth_path: path, code, state } = this.paramsFor(this.routeName); + const queryString = decodeURIComponent(window.location.search); + // Since state param can also contain namespace, fetch the values using native url api. + // For instance, state params value can be state=st_123456,ns=d4fq + // Ember paramsFor used to strip out the value after the "=" sign. In short ns value was not being passed along. + let urlParams = new URLSearchParams(queryString); + let state = urlParams.get('state'), + code = urlParams.get('code'), + ns; + if (state.includes(',ns=')) { + let arrayParams = state.split(',ns='); + state = arrayParams[0]; + ns = arrayParams[1]; + } + let { auth_path: path } = this.paramsFor(this.routeName); let { namespaceQueryParam: namespace } = this.paramsFor('vault.cluster'); path = window.decodeURIComponent(path); const source = 'oidc-callback'; // required by event listener in auth-jwt component let queryParams = { source, namespace, path, code, state }; + // If state had ns value, send it as part of namespace param + if (ns) { + queryParams.namespace = ns; + } window.opener.postMessage(queryParams, window.origin); }, setupController(controller) {