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

PORTALS-3299: proposed solution for oauth sign in app when prompt is … #1328

Merged
merged 4 commits into from
Oct 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
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
8 changes: 7 additions & 1 deletion apps/synapse-oauth-signin/src/AppInitializer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,18 @@ 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.
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,
Copy link
Collaborator

@nickgros nickgros Oct 29, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This may not work on dev (which is OK for now, since we don't have a dev OAuth app or accounts site)

})

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
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.

Loading