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

STCOR-671 handle access-control via cookies and RTR 👋 🔄 🔒 😅 #1376

Merged
merged 51 commits into from
Jan 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
51 commits
Select commit Hold shift + click to select a range
cfc03c7
Release v10.0.0 (#1349)
zburke Oct 12, 2023
90272ec
STCOR-749: Allow to import validateUser function from @folio/stripes/…
OleksandrHladchenko1 Oct 18, 2023
ef1e8c3
Release v10.0.1
zburke Oct 25, 2023
93b35bc
STCOR-671 handle access-control via cookies (#1364)
zburke Nov 6, 2023
6a67e9b
Release v10.0.2 (#1365)
zburke Nov 6, 2023
4dc1161
Revert "STCOR-671 handle access-control via cookies (#1364)" (#1368)
zburke Nov 9, 2023
8ecbd31
[STCOR-752]: Ensure <AppIcon> is not cut off (for real this time) (#1…
ncovercash Oct 26, 2023
8ea3189
Release v10.0.3 (#1370)
zburke Nov 10, 2023
b232eee
STCOR-671 provide empty service worker (#1373)
zburke Nov 13, 2023
276cb94
Release v10.0.4 (#1374)
zburke Nov 13, 2023
9201784
STCOR-671 handle access control via cookies
zburke Nov 15, 2023
229e212
add request handling to isOkapiRequest, replace localstorage usage wi…
JohnC-80 Nov 15, 2023
998b9cb
clean up comments and resource handling
zburke Nov 16, 2023
b299fa3
implement fake XHR class
JohnC-80 Nov 16, 2023
7146c84
Merge branch 'STCOR-671-nkotb' of https://github.com/folio-org/stripe…
JohnC-80 Nov 16, 2023
d3019b6
add implementation of XHR override, move functions to token-util
JohnC-80 Nov 16, 2023
d9d4cdf
tests, comments
zburke Nov 17, 2023
be7520b
rtr() tests
zburke Nov 17, 2023
69a03c1
tests and comments; rtr() refactor handles inner exceptions
zburke Nov 17, 2023
08900bb
put RTR behind stripes-config.useSecureTokens
zburke Nov 17, 2023
20b6c49
add FFetch tests
JohnC-80 Nov 17, 2023
299f23a
add FFetch tests
JohnC-80 Nov 17, 2023
2bade29
Merge branch 'STCOR-671-nkotb' of https://github.com/folio-org/stripe…
JohnC-80 Nov 17, 2023
73dd604
FFetch tests at 100% coverage
JohnC-80 Nov 17, 2023
d8cedc3
STCOR-762 disable login when cookies are disabled
zburke Nov 18, 2023
13c6e3d
linty mclintface
zburke Nov 19, 2023
e532cbf
when config.useSecureTokens is absent, restore token access
zburke Nov 19, 2023
367707b
restore token-based endpoints since BTOG isn't configured with useSec…
zburke Nov 19, 2023
f0fae4c
replace polling; replace 403+inspection with 400 detection
zburke Nov 21, 2023
3f04f16
add test for FXHR
JohnC-80 Nov 21, 2023
bef4154
restore tokenExpiration checking
zburke Nov 21, 2023
6558323
mock localforage to always return valid expiration data
zburke Nov 21, 2023
b5ea9bd
FFetch coverage
JohnC-80 Nov 21, 2023
056f1f0
lint
JohnC-80 Nov 21, 2023
31e029c
backward compatibility: include x-okapi-token header when token is pr…
zburke Nov 27, 2023
6284e38
apply same settings to withOkapiKy as useOkapiKy
JohnC-80 Nov 27, 2023
30859de
include mode and credentials flags in all okapi calls
JohnC-80 Nov 27, 2023
6bfc5a8
handle cross-tab communication during rotation with localStorage
JohnC-80 Nov 30, 2023
6554cb5
log correctly
JohnC-80 Nov 30, 2023
d3b3728
don't worry about checking to see if context.rtrPromise exists
JohnC-80 Nov 30, 2023
0da7077
correctly handle single-window and multi-window rotation
zburke Dec 6, 2023
130e958
ignore stale rotation requests
zburke Dec 8, 2023
8b06801
lint. it's always lint.
zburke Dec 8, 2023
aaea28b
backward compat with http-header token authz
zburke Jan 3, 2024
8d4265a
Merge branch 'master' into STCOR-671-nkotb
zburke Jan 3, 2024
0df9163
Merge branch 'hulk-smash' into STCOR-671-nkotb
zburke Jan 10, 2024
c831b61
manually revert 0df9163da8dd38230737864492e1072825169ff5
zburke Jan 10, 2024
1c79d85
ECS backwards compatibility: include token in tenant-update requests
zburke Jan 10, 2024
beb9455
inspect 400, not 403, responses for missing tokens
zburke Jan 16, 2024
52bfdab
Merge branch 'master' into STCOR-671-nkotb
zburke Jan 16, 2024
c8f9d8c
update tests in concert with updated missing-token response expectati…
zburke Jan 16, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
* Fix duplicated "FOLIO" in document title in some cases. Refs STCOR-767.
* Refactor away from `color()` function. Refs STCOR-768.
* Export `getEventHandler` to be able to create events in other modules. Refs STCOR-770.
* Opt-in: handle access-control via cookies. Refs STCOR-671.
* Opt-in: disable login when cookies are disabled. Refs STCOR-762.

## [10.0.0](https://github.com/folio-org/stripes-core/tree/v10.0.0) (2023-10-11)
[Full Changelog](https://github.com/folio-org/stripes-core/compare/v9.0.0...v10.0.0)
Expand Down
3 changes: 3 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ export * from './src/consortiaServices';
export { default as queryLimit } from './src/queryLimit';
export { default as init } from './src/init';

/* localforage wrappers hide the session key */
export { getOkapiSession, getTokenExpiry, setTokenExpiry } from './src/loginServices';

export { registerServiceWorker, unregisterServiceWorker } from './src/serviceWorkerRegistration';

export { getEventHandler } from './src/handlerService';
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
"@formatjs/cli": "^6.1.3",
"chai": "^4.1.2",
"eslint": "^7.32.0",
"jest-fetch-mock": "^3.0.3",
"miragejs": "^0.1.32",
"moment": "^2.29.0",
"react": "^18.2.0",
Expand Down
5 changes: 0 additions & 5 deletions src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import configureLogger from './configureLogger';
import configureStore from './configureStore';
import gatherActions from './gatherActions';
import { destroyStore } from './mainActions';
import { unregisterServiceWorker } from './serviceWorkerRegistration';

import Root from './components/Root';

Expand All @@ -31,10 +30,6 @@ export default class StripesCore extends Component {
this.epics = configureEpics(connectErrorEpic);
this.store = configureStore(initialState, this.logger, this.epics);
this.actionNames = gatherActions();

// unregister any zombie service workers left over from RTR work
// prior to disabling RTR in PR #1371
unregisterServiceWorker();
}

componentWillUnmount() {
Expand Down
5 changes: 4 additions & 1 deletion src/RootWithIntl.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,14 @@ class RootWithIntl extends React.Component {
clone: PropTypes.func.isRequired,
}).isRequired,
token: PropTypes.string,
isAuthenticated: PropTypes.bool,
disableAuth: PropTypes.bool.isRequired,
history: PropTypes.shape({}),
};

static defaultProps = {
token: '',
isAuthenticated: false,
history: {},
};

Expand All @@ -67,6 +69,7 @@ class RootWithIntl extends React.Component {
render() {
const {
token,
isAuthenticated,
disableAuth,
history,
} = this.props;
Expand All @@ -85,7 +88,7 @@ class RootWithIntl extends React.Component {
>
<Provider store={stripes.store}>
<Router history={history}>
{ token || disableAuth ?
{ isAuthenticated || token || disableAuth ?
<>
<MainContainer>
<AppCtxMenuProvider>
Expand Down
2 changes: 2 additions & 0 deletions src/Stripes.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,15 @@ export const stripesShape = PropTypes.shape({
okapiReady: PropTypes.bool,
tenant: PropTypes.string.isRequired,
token: PropTypes.string,
isAuthenticated: PropTypes.bool,
translations: PropTypes.object,
url: PropTypes.string.isRequired,
withoutOkapi: PropTypes.bool,
}).isRequired,
plugins: PropTypes.object,
setBindings: PropTypes.func.isRequired,
setCurrency: PropTypes.func.isRequired,
setIsAuthenticated: PropTypes.func.isRequired,
setLocale: PropTypes.func.isRequired,
setSinglePlugin: PropTypes.func.isRequired,
setTimezone: PropTypes.func.isRequired,
Expand Down
17 changes: 16 additions & 1 deletion src/components/Login/Login.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,28 @@ class Login extends Component {
onSubmit,
} = this.props;

const cookieMessage = navigator.cookieEnabled ?
'' :
(
<Row center="xs">
<Col xs={6}>
<Headline
size="large"
tag="h3"
>
<FormattedMessage id="stripes-core.title.cookieEnabled" />
</Headline>
</Col>
</Row>);

return (
<Form
onSubmit={onSubmit}
subscription={{ values: true }}
render={({ form, submitting, handleSubmit, submitSucceeded, values }) => {
const { username } = values;
const submissionStatus = submitting || submitSucceeded;
const buttonDisabled = submissionStatus || !(username);
const buttonDisabled = submissionStatus || !(username) || !(navigator.cookieEnabled);
const buttonLabel = submissionStatus ? 'loggingIn' : 'login';
return (
<main>
Expand Down Expand Up @@ -82,6 +96,7 @@ class Login extends Component {
</Headline>
</Col>
</Row>
{ cookieMessage }
<div data-test-new-username-field>
<Row center="xs">
<Col xs={6}>
Expand Down
13 changes: 3 additions & 10 deletions src/components/MainNav/MainNav.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,14 @@ import { isEqual, find } from 'lodash';
import { compose } from 'redux';
import { injectIntl } from 'react-intl';
import { withRouter } from 'react-router';
import localforage from 'localforage';

import { branding, config } from 'stripes-config';

import { Icon } from '@folio/stripes-components';

import { withModules } from '../Modules';
import { LastVisitedContext } from '../LastVisited';
import { clearOkapiToken, clearCurrentUser } from '../../okapiActions';
import { resetStore } from '../../mainActions';
import { getLocale } from '../../loginServices';
import { getLocale, logout as sessionLogout } from '../../loginServices';
import {
updateQueryResource,
getLocationQuery,
Expand Down Expand Up @@ -123,12 +120,8 @@ class MainNav extends Component {
returnToLogin() {
const { okapi } = this.store.getState();

return getLocale(okapi.url, this.store, okapi.tenant).then(() => {
this.store.dispatch(clearOkapiToken());
this.store.dispatch(clearCurrentUser());
this.store.dispatch(resetStore());
localforage.removeItem('okapiSess');
});
return getLocale(okapi.url, this.store, okapi.tenant)
.then(sessionLogout(okapi.url, this.store));
}

// return the user to the login screen, but after logging in they will be brought to the default screen.
Expand Down
27 changes: 27 additions & 0 deletions src/components/Root/Errors.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/* eslint-disable import/prefer-default-export */
/* eslint-disable max-classes-per-file */

/**
* RTRError
* Error occured during rotation
*/
export class RTRError extends Error {
constructor(message) {
super(message ?? 'Unknown Refresh Token Error');

this.name = 'RTRError';
}
}

/**
* UnexpectedResourceError
* Thrown when
*/
export class UnexpectedResourceError extends Error {
constructor(resource) {
super('Expected a string, URL, or Request but did not receive one.');

this.name = 'UnexpectedResourceError';
this.resource = resource;
}
}
5 changes: 5 additions & 0 deletions src/components/Root/Events.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
/** dispatched during RTR when it is successful */
export const RTR_SUCCESS_EVENT = '@folio/stripes/core::RTRSuccess';

/** dispatched during RTR if RTR itself fails */
export const RTR_ERROR_EVENT = '@folio/stripes/core::RTRError';
Loading
Loading