Skip to content

Commit

Permalink
Fix OIDC callback query params
Browse files Browse the repository at this point in the history
- Value of namespace was getting stripped from the state query param
- Used native URL search param api to fetch the values
  • Loading branch information
arnav28 committed May 12, 2022
1 parent 854a6f4 commit 3b3b646
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion ui/app/routes/vault/cluster/oidc-callback.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,18 @@ export default Route.extend({
// left blank so we render the template immediately
},
afterModel() {
let { auth_path: path, code, state } = this.paramsFor(this.routeName);
let queryString = window.location.search;
// Check if url is encoded
if (this.containsEncodedComponents(queryString)) {
queryString = decodeURIComponent(queryString);
}
// 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');
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
Expand All @@ -17,4 +28,8 @@ export default Route.extend({
this._super(...arguments);
controller.set('pageContainer', document.querySelector('.page-container'));
},
// Helper function to check if url is encoded
containsEncodedComponents(x) {
return decodeURI(x) !== decodeURIComponent(x);
},
});

0 comments on commit 3b3b646

Please sign in to comment.