-
Notifications
You must be signed in to change notification settings - Fork 2
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
[ENH] Implemented OIDC flow that results in a query sent to the f-API #205
Conversation
✅ Deploy Preview for neurobagel-query ready!
To edit notification comments on pull requests, go to your Netlify site configuration. |
Interesting behaviour for the oauth prompt: it is written in the local language from where the request is sent. So from Germany it's in German. I changed the string check and also the login prompt language
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.
Very cool PR @rmanaem! 🎉 Very exciting new functionality!
I read through it and it looks and feels really nice. As you said, there are some things we can refactor / clean up soon, but the logic is really clear and the functionality works cleanly for me. I left some comments here so we can go back and look at them together. But for now I will merge this!
🧑🍳
<GoogleOAuthProvider clientId="mock-client-id"> | ||
{' '} | ||
<AuthDialog isLoggedIn={props.isLoggedIn} onAuth={props.onAuth} /> | ||
</GoogleOAuthProvider> | ||
); |
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.
Is this a special trick to get the auth provider to run inside the e2e test? Shouldn't hold up the PR, but we should note that down in our notes
cypress/component/AuthDialog.cy.tsx
Outdated
'Please login using one of the following before proceeding' | ||
); | ||
cy.get('[data-cy="auth-dialog"]').within(() => { | ||
cy.contains('Sign in with Google'); |
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.
function login(credential: string | undefined) { | ||
setIsLoggedIn(true); | ||
const jwt: GoogleJWT = credential ? jwtDecode(credential) : ({} as GoogleJWT); | ||
setIDToken(credential); | ||
setName(jwt.given_name); | ||
setProfilePic(jwt.picture); | ||
} |
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.
That'd be a good candidate for a custom hook in the future afaict - so we can subscribe to the global "logged in" status with all components that need it.
|
||
const handleClick = (event: React.MouseEvent<HTMLElement>) => { | ||
setAnchorEl(event.currentTarget); | ||
}; | ||
const handleClose = () => { | ||
setAnchorEl(null); | ||
}; |
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.
We should revisit this bit soon and see if by refactoring the whole login section into its own component we can get rid of the custom click handling. Could you open an issue please.
|
||
ReactDOM.createRoot(document.getElementById('root')!).render( | ||
enableAuth ? <GoogleOAuthProvider clientId={clientID}>{app}</GoogleOAuthProvider> : app | ||
); |
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.
neat!
const [isLoggedIn, setIsLoggedIn] = useState<boolean>(false); | ||
const [name, setName] = useState<string>(''); | ||
const [profilePic, setProfilePic] = useState<string>(''); | ||
const [IDToken, setIDToken] = useState<string | undefined>(''); | ||
|
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.
could be good candidate for single state object and reducer
const action = (snackbarId: SnackbarKey) => ( | ||
<IconButton | ||
onClick={() => { | ||
closeSnackbar(snackbarId); | ||
}} | ||
> | ||
<CloseIcon className="text-white" /> | ||
</IconButton> | ||
); | ||
|
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.
nice - we probably want to also refactor this soon into it's own component though
|
||
function logout() { | ||
googleLogout(); | ||
setIsLoggedIn(false); | ||
setIDToken(''); | ||
setName(''); | ||
setProfilePic(''); | ||
} | ||
|
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.
I think that's also a good reducer candidate for a cleanup / refactor
const jwt: GoogleJWT = credential ? jwtDecode(credential) : ({} as GoogleJWT); | ||
setIDToken(credential); | ||
setName(jwt.given_name); | ||
setProfilePic(jwt.picture); |
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.
really cool!
const response = await axios.get(url, { | ||
headers: { | ||
Authorization: `Bearer ${IDToken}`, | ||
'Content-Type': 'application/json', | ||
}, | ||
}); | ||
// TODO: remove this branch once there is no more non-federation option |
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.
If auth is NOT enabled, does this just send the header anyway, but with an empty ID token? That's probably alright for now, but we should revisit!
🚀 PR was released in |
Changes proposed in this pull request:
Checklist
This section is for the PR reviewer
[ENH]
,[FIX]
,[REF]
,[TST]
,[CI]
,[MNT]
,[INF]
,[MODEL]
,[DOC]
) (see our Contributing Guidelines for more info)skip-release
(to be applied by maintainers only)Closes #XXXX
For new features:
For bug fixes: