Skip to content
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

UI/OIDC auth bug for cloud ui HCP namespace flag #16886

Merged
23 changes: 7 additions & 16 deletions ui/app/routes/vault/cluster/oidc-callback.js
Expand Up @@ -5,29 +5,20 @@ export default Route.extend({
model() {
// left blank so we render the template immediately
},
// const queryString = decodeURIComponent(window.location.search);
hellobontempo marked this conversation as resolved.
Show resolved Hide resolved
// 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
afterModel() {
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.
hellobontempo marked this conversation as resolved.
Show resolved Hide resolved
let urlParams = new URLSearchParams(queryString);
let state = urlParams.get('state'),
code = urlParams.get('code'),
ns;
if (state.includes(',ns=')) {
let { auth_path: path, code, state } = this.paramsFor(this.routeName);
let { namespaceQueryParam: namespace } = this.paramsFor('vault.cluster');
if (namespace === '' && state?.includes(',ns=')) {
let arrayParams = state.split(',ns=');
state = arrayParams[0];
ns = arrayParams[1];
namespace = 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 };
Copy link
Collaborator

@hashishaw hashishaw Aug 26, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One more cleanup task (follow-on) is, if namespace doesn't exist don't include it. So remove from queryParams here and then below do
if (namespace) queryParams.namespace = namespace

// 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) {
Expand Down