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
This commit is contained in:
Arnav Palnitkar 2022-05-13 09:58:56 -07:00 committed by GitHub
parent d2bc5b5e3d
commit a0a67e671f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 21 additions and 1 deletions

3
changelog/15378.txt Normal file
View File

@ -0,0 +1,3 @@
```release-note:improvement
ui: Allow namespace param to be parsed from state queryParam
```

View File

@ -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) {