Skip to content

Commit

Permalink
UID-121 conservatively handle x-okapi-token (#400)
Browse files Browse the repository at this point in the history
Handle cookie-based authorization conservatively: provide the
`x-okapi-token` HTTP request header if the token is present in
`stripes`; omit it otherwise.

Refs UID-121
  • Loading branch information
zburke authored Nov 28, 2023
1 parent 3ea8476 commit a670e04
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 1 deletion.
3 changes: 3 additions & 0 deletions src/settings/CanIUse.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,14 @@ class CanIUse extends React.Component {
componentDidMount() {
const { stripes } = this.props;

const token = stripes.store.getState().okapi.token;

const options = {
credentials: 'include',
method: 'GET',
headers: {
'X-Okapi-Tenant': stripes.okapi.tenant,
...(token && { 'X-Okapi-Token': token }),
'Content-Type': 'application/json',
},
};
Expand Down
3 changes: 2 additions & 1 deletion src/settings/OkapiPaths.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,13 @@ class OkapiPaths extends React.Component {
const { stripes } = this.props;

const paths = this.state.paths;
const token = stripes.store.getState().okapi.token;

const options = {
method: 'GET',
headers: {
'X-Okapi-Tenant': stripes.okapi.tenant,
'X-Okapi-Token': stripes.store.getState().okapi.token,
...(token && { 'X-Okapi-Token': token }),
'Content-Type': 'application/json',
},
};
Expand Down
2 changes: 2 additions & 0 deletions src/settings/Passwd.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ class Passwd extends React.Component {
password: values.password,
userId,
};
const token = stripes.store.getState().okapi.token;

if (!res.credentialsExist) {
return mutator.passwd.POST(credentials);
Expand All @@ -114,6 +115,7 @@ class Passwd extends React.Component {
method: 'DELETE',
headers: {
'X-Okapi-Tenant': stripes.okapi.tenant,
...(token && { 'X-Okapi-Token': token }),
'Content-Type': 'application/json',
},
};
Expand Down

0 comments on commit a670e04

Please sign in to comment.