Skip to content

Commit

Permalink
Merge branch 'main' into PORTALS-3269
Browse files Browse the repository at this point in the history
  • Loading branch information
kianamcc authored Oct 30, 2024
2 parents ee2034a + dc17deb commit 15fdc74
Show file tree
Hide file tree
Showing 12 changed files with 42 additions and 24 deletions.
10 changes: 2 additions & 8 deletions apps/SageAccountWeb/src/components/ChangePasswordPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,10 @@ import { LeftRightPanel } from './LeftRightPanel'
import { SourceAppLogo } from './SourceApp'
import { SetPasswordInstructions } from './ResetPassword'
import { ChangePassword } from 'synapse-react-client'
import { useLocation } from 'react-router-dom'

export const ChangePasswordPage = () => {
const { search } = useLocation()
const urlSearchParams = new URLSearchParams(search)
const errorCode = urlSearchParams.get('errorCode') ?? ''
const instructions =
errorCode == 'PASSWORD_RESET_VIA_EMAIL_REQUIRED'
? 'Your current password does not meet Synapse security requirements'
: 'Set a new password'
// previously, if the errorCode was PASSWORD_RESET_VIA_EMAIL_REQUIRED then this page would tell the user that their current password does not meet Synapse security requirements. But this is not necessarily true.
const instructions = 'Set a new password'
return (
<>
<LeftRightPanel
Expand Down
2 changes: 1 addition & 1 deletion apps/portals-e2e/src/configs/exploreConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ const exploreConfig: ExploreConfig = {
'Projects',
'Studies',
'Publications',
'Computational Tools',
// 'Computational Tools', // empty - known data curation issue
],
people_charts: ['People'],
},
Expand Down
1 change: 1 addition & 0 deletions apps/synapse-oauth-signin/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
"react-dom": "^18.2.0",
"react-router-dom": "^5.3.4",
"sass": "^1.71.1",
"universal-cookie": "^4.0.4",
"synapse-react-client": "workspace:*"
},
"devDependencies": {
Expand Down
9 changes: 7 additions & 2 deletions apps/synapse-oauth-signin/src/AppInitializer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,23 @@ import {
SynapseConstants,
} from 'synapse-react-client'
import { handleErrorRedirect } from './URLUtils'
import UniversalCookies from 'universal-cookie'

const cookies = new UniversalCookies()
function AppInitializer(
props: React.PropsWithChildren<Record<string, unknown>>,
) {
const accountSitePrompted =
cookies.get(SynapseConstants.ACCOUNT_SITE_PROMPTED_FOR_LOGIN_COOKIE_KEY) ==
'true' // short-lived cookie
const urlSearchParams = new URLSearchParams(window.location.search)
const prompt = urlSearchParams.get('prompt')
const prompt = accountSitePrompted ? 'none' : urlSearchParams.get('prompt')

let maxAge = undefined
// check max age when re-establishing the session, not to auto-consent.
const maxAgeURLParam = urlSearchParams.get('max_age')
// SWC-5597: if max_age is defined, then return if the user last authenticated more than max_age seconds ago
if (maxAgeURLParam && parseInt(maxAgeURLParam)) {
if (!accountSitePrompted && maxAgeURLParam && parseInt(maxAgeURLParam)) {
maxAge = parseInt(maxAgeURLParam)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,11 @@ export const synapseRedirectInstructions = (

const isSynapseURL = (url: string) => {
if (!url) return false
return new URL(url).hostname.toLowerCase() === 'www.synapse.org'
const parsedURL = new URL(url)
return (
parsedURL.hostname.toLowerCase() === 'www.synapse.org' &&
parsedURL.pathname.startsWith('/Synapse')
)
}

const getInitialCountdownSeconds = (redirectURL: string) => {
Expand Down Expand Up @@ -106,7 +110,7 @@ const RedirectDialog = (props: RedirectDialogProps) => {
className="RedirectDialog"
PaperProps={{ sx: { padding: 0 } }}
>
<DialogContent>
<DialogContent sx={{ p: 0, ml: 0, mr: 0 }}>
<div className="redirect-dialog-body">
<Typography
variant="headline1"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ describe('StandaloneLoginForm', () => {
)
expect(callback).not.toHaveBeenCalled()
expect(window.location.assign).toHaveBeenCalledWith(
'http://localhost:3000/changePassword?errorCode=PASSWORD_RESET_VIA_EMAIL_REQUIRED',
'http://localhost:3000/changePassword',
)
})
})
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ describe('TableColumnSchemaEditorUtils', () => {
ColumnTypeEnum.BOOLEAN_LIST,
ColumnTypeEnum.DATE_LIST,
ColumnTypeEnum.INTEGER_LIST,
ColumnTypeEnum.ENTITYID_LIST,
]

Object.values(ColumnTypeEnum).forEach((key: ColumnType) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@ export function canHaveMaxListLength(
case ColumnTypeEnum.BOOLEAN_LIST:
case ColumnTypeEnum.DATE_LIST:
case ColumnTypeEnum.INTEGER_LIST:
case ColumnTypeEnum.ENTITYID_LIST:
return true
default:
// all others are false
Expand Down
15 changes: 14 additions & 1 deletion packages/synapse-react-client/src/utils/AppUtils/AppUtils.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import { useHistory } from 'react-router-dom'
import { LAST_PLACE_LOCALSTORAGE_KEY } from '../SynapseConstants'
import {
ACCOUNT_SITE_PROMPTED_FOR_LOGIN_COOKIE_KEY,
LAST_PLACE_LOCALSTORAGE_KEY,
} from '../SynapseConstants'
import { useEffect, useState } from 'react'
import UniversalCookies from 'universal-cookie'

Expand Down Expand Up @@ -33,6 +36,16 @@ export function storeRedirectURLForOneSageLoginAndGotoURL(href: string) {
}

export function processRedirectURLInOneSage() {
// PORTALS-3299 : Indicate that we have completed the login workflow (cookie expires in a minute) to break out of a cycle
const expireDate = new Date()
expireDate.setMinutes(expireDate.getMinutes() + 1)
const hostname = window.location.hostname.toLowerCase()
cookies.set(ACCOUNT_SITE_PROMPTED_FOR_LOGIN_COOKIE_KEY, 'true', {
path: '/',
expires: expireDate,
domain: hostname.endsWith('.synapse.org') ? 'synapse.org' : undefined,
})

if (cookies.get(ONE_SAGE_REDIRECT_COOKIE_KEY)) {
const href = cookies.get(ONE_SAGE_REDIRECT_COOKIE_KEY)
cookies.remove(ONE_SAGE_REDIRECT_COOKIE_KEY)
Expand Down
3 changes: 3 additions & 0 deletions packages/synapse-react-client/src/utils/SynapseConstants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,9 @@ export const ACCESS_TOKEN_COOKIE_KEY =
'org.sagebionetworks.security.user.login.token'
export const LAST_PLACE_LOCALSTORAGE_KEY = 'last_place_url'

export const ACCOUNT_SITE_PROMPTED_FOR_LOGIN_COOKIE_KEY =
'org.sagebionetworks.account.promptedforlogin'

/* Persistent localStorage keys on SWC logout */
export const PERSISTENT_LOCAL_STORAGE_KEYS = [
...ORIENTATION_BANNER_KEYS,
Expand Down
11 changes: 2 additions & 9 deletions packages/synapse-react-client/src/utils/hooks/useLogin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,15 +71,8 @@ export default function useLogin(opts: UseLoginOptions): UseLoginReturn {
const [twoFaErrorResponse, setTwoFaErrorResponse] = useState<
TwoFactorAuthErrorResponse | undefined
>()
const changePasswordSearchParams = new URLSearchParams()
changePasswordSearchParams.set(
'errorCode',
ErrorResponseCode.PASSWORD_RESET_VIA_EMAIL_REQUIRED,
)
const changePasswordUrl = useOneSageURL(
'/changePassword',
changePasswordSearchParams,
)

const changePasswordUrl = useOneSageURL('/changePassword')
/**
* Update state variable if optional prop changes
*/
Expand Down
3 changes: 3 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 15fdc74

Please sign in to comment.