-
Notifications
You must be signed in to change notification settings - Fork 3
[UID-159] Better handle RTR callback; handle new token expiration format #438
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
Open
ncovercash
wants to merge
14
commits into
master
Choose a base branch
from
uid-159
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
ccb194e
[UID-159] Additional RTR debugging and configuration options
ncovercash 72fb50a
typo
ncovercash a2fd73d
Merge branch 'master' into uid-159
ncovercash f975913
cleanup
ncovercash d217687
Merge branch 'uid-159' of github.com:folio-org/ui-developer into uid-159
ncovercash e9fffe4
Merge branch 'master' into uid-159
ncovercash 8dcd604
add fixedLengthSessionWarningTTL
ncovercash d45d3fb
Merge branch 'uid-159' of github.com:folio-org/ui-developer into uid-159
ncovercash da591d4
[UID-159] Better handle RTR callback; handle new token expiration format
ncovercash 8213efe
Merge branch 'master' into uid-159
ncovercash ff5cfc0
upgrade stripes
ncovercash 616a4ce
[UID-159] pull back scope
ncovercash 6a59ac2
Merge branch 'uid-159' of github.com:folio-org/ui-developer into uid-159
ncovercash 764e60e
Merge branch 'master' into uid-159
ncovercash File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,53 +1,50 @@ | ||
| import { merge } from 'lodash'; | ||
| import PropTypes from 'prop-types'; | ||
| import { useCallback, useEffect, useState } from 'react'; | ||
| import { Field, Form } from 'react-final-form'; | ||
| import { FormattedMessage } from 'react-intl'; | ||
|
|
||
| import { getTokenExpiry } from '@folio/stripes/core'; | ||
| import { Button, LoadingPane, Pane, PaneHeader, TextField } from '@folio/stripes/components'; | ||
| import { getTokenExpiry, RTR_CONSTANTS } from '@folio/stripes/core'; | ||
| import { Button, LoadingPane, Pane, PaneHeader } from '@folio/stripes/components'; | ||
|
|
||
| /** | ||
| * manipulate AT/RT expiration dates in storage in order to test RTR. | ||
| * @returns | ||
| */ | ||
| const RefreshTokenRotation = ({ stripes }) => { | ||
| // why WHY copy this string here instead of importing it from stripes-core? | ||
| // | ||
| // RTR_FORCE_REFRESH_EVENT will be present in stripes-core 10.2.0 (stripes | ||
| // 9.2.0). Importing it would force the stripes peer depedency to bump from | ||
| // ^9.1.0 to ^9.2.0.If we copy the string instead of importing it, we can | ||
| // remain compatible with 9.1.0. | ||
| // | ||
| // OK, compatibility is nice. But it's still gross, right? Yep, super gross. | ||
| // Aren't you nauseated? Yes, yes I am. 🤢🧼🛁 | ||
| const RTR_FORCE_REFRESH_EVENT = '@folio/stripes/core::RTRForceRefresh'; | ||
|
|
||
| const RefreshTokenRotation = () => { | ||
| const [isLoading, setIsLoading] = useState(true); | ||
| const [tokenExpiration, setTokenExpiration] = useState({}); | ||
| const [tokenExpiration, setTokenExpiration] = useState({ atExpires: -1, rtExpires: -1 }); | ||
|
|
||
| useEffect(() => { | ||
| setIsLoading(true); | ||
| getTokenExpiry().then((te) => { | ||
| setTokenExpiration(te ?? { atExpires: -1, rtExpires: -1 }); | ||
| setIsLoading(false); | ||
| }); | ||
| const callback = () => { | ||
| setIsLoading(true); | ||
| getTokenExpiry().then((te) => { | ||
| setTokenExpiration({ | ||
| atExpires: te.atExpires ?? te.accessTokenExpiration ?? -1, | ||
| rtExpires: te.rtExpires ?? te.refreshTokenExpiration ?? -1, | ||
|
Comment on lines
+20
to
+21
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. safely handles old and new style |
||
| }); | ||
| setIsLoading(false); | ||
| }); | ||
| }; | ||
|
|
||
| callback(); | ||
|
|
||
| window.addEventListener(RTR_CONSTANTS.RTR_SUCCESS_EVENT, callback); | ||
|
|
||
| return () => window.removeEventListener(RTR_CONSTANTS.RTR_SUCCESS_EVENT, callback); | ||
| }, []); | ||
|
|
||
| /** | ||
| * forceRefresh | ||
| * dispatch an event to force a token rotation | ||
| */ | ||
| const forceRefresh = useCallback( | ||
| () => window.dispatchEvent(new Event(RTR_FORCE_REFRESH_EVENT)), | ||
| () => window.dispatchEvent(new Event(RTR_CONSTANTS.RTR_FORCE_REFRESH_EVENT)), | ||
| [], | ||
| ); | ||
|
|
||
| /** | ||
| * saveRtrConfig | ||
| * update stripes.config.rtr from form | ||
| */ | ||
| const saveRtrConfig = useCallback( | ||
| /* const saveRtrConfig = useCallback( | ||
| (values) => { | ||
| merge(stripes.config.rtr, { | ||
| idleSessionTTL: values.idleSessionTTL, | ||
|
|
@@ -60,7 +57,7 @@ const RefreshTokenRotation = ({ stripes }) => { | |
| forceRefresh(); | ||
| }, | ||
| [stripes, forceRefresh], | ||
| ); | ||
| ); */ | ||
|
|
||
| if (!isLoading) { | ||
| return ( | ||
|
|
@@ -88,7 +85,7 @@ const RefreshTokenRotation = ({ stripes }) => { | |
| <FormattedMessage id="ui-developer.rtr.forceRefresh" /> | ||
| </Button> | ||
|
|
||
| <Form | ||
| {/* <Form | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this form currently doesn't configure anything, due to that being pulled from STCOR-888, so let's hide it. |
||
| onSubmit={saveRtrConfig} | ||
| initialValues={{ | ||
| ...stripes.config.rtr, | ||
|
|
@@ -130,7 +127,7 @@ const RefreshTokenRotation = ({ stripes }) => { | |
| </Button> | ||
| </form> | ||
| )} | ||
| </Form> | ||
| </Form> */} | ||
| </div> | ||
| </Pane> | ||
| ); | ||
|
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Now that ui-developer 9.0.0 is out, we should be safe to do 9.2.0 for R release.