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

[ENH] Implemented OIDC flow that results in a query sent to the f-API #205

Merged
merged 22 commits into from
Jul 14, 2024

Conversation

rmanaem
Copy link
Contributor

@rmanaem rmanaem commented Jul 14, 2024

Changes proposed in this pull request:

Checklist

This section is for the PR reviewer

  • PR has an interpretable title with a prefix ([ENH], [FIX], [REF], [TST], [CI], [MNT], [INF], [MODEL], [DOC]) (see our Contributing Guidelines for more info)
  • PR has a label for the release changelog or skip-release (to be applied by maintainers only)
  • PR links to GitHub issue with mention Closes #XXXX
  • Tests pass
  • Checks pass

For new features:

  • Tests have been added

For bug fixes:

  • There is at least one test that would fail under the original bug conditions.

@rmanaem rmanaem added the pr-minor-breaking Feature or enhancement that breaks compatibility, will increment minor version (0.+1.0) label Jul 14, 2024
@rmanaem rmanaem requested a review from surchs July 14, 2024 15:19
Copy link

netlify bot commented Jul 14, 2024

Deploy Preview for neurobagel-query ready!

Name Link
🔨 Latest commit 06aff79
🔍 Latest deploy log https://app.netlify.com/sites/neurobagel-query/deploys/66940c5da1fb1300086eddef
😎 Deploy Preview https://deploy-preview-205--neurobagel-query.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

rmanaem and others added 3 commits July 14, 2024 11:24
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
Copy link
Contributor

@surchs surchs left a 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!

🧑‍🍳

Comment on lines +12 to +16
<GoogleOAuthProvider clientId="mock-client-id">
{' '}
<AuthDialog isLoggedIn={props.isLoggedIn} onAuth={props.onAuth} />
</GoogleOAuthProvider>
);
Copy link
Contributor

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

'Please login using one of the following before proceeding'
);
cy.get('[data-cy="auth-dialog"]').within(() => {
cy.contains('Sign in with Google');
Copy link
Contributor

Choose a reason for hiding this comment

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

Pretty interesting error I ran into here: The "Sign in with Google" uses the language of the country from where you make the request. So the test would fail in Germany because here the string will be
image

Something to keep in mind for e2e tests. For now I'll switch the check to just "Google"

Comment on lines +346 to +352
function login(credential: string | undefined) {
setIsLoggedIn(true);
const jwt: GoogleJWT = credential ? jwtDecode(credential) : ({} as GoogleJWT);
setIDToken(credential);
setName(jwt.given_name);
setProfilePic(jwt.picture);
}
Copy link
Contributor

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.

Comment on lines 42 to +48

const handleClick = (event: React.MouseEvent<HTMLElement>) => {
setAnchorEl(event.currentTarget);
};
const handleClose = () => {
setAnchorEl(null);
};
Copy link
Contributor

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.

Comment on lines +25 to +28

ReactDOM.createRoot(document.getElementById('root')!).render(
enableAuth ? <GoogleOAuthProvider clientId={clientID}>{app}</GoogleOAuthProvider> : app
);
Copy link
Contributor

Choose a reason for hiding this comment

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

neat!

Comment on lines +50 to +54
const [isLoggedIn, setIsLoggedIn] = useState<boolean>(false);
const [name, setName] = useState<string>('');
const [profilePic, setProfilePic] = useState<string>('');
const [IDToken, setIDToken] = useState<string | undefined>('');

Copy link
Contributor

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

Comment on lines +66 to +75
const action = (snackbarId: SnackbarKey) => (
<IconButton
onClick={() => {
closeSnackbar(snackbarId);
}}
>
<CloseIcon className="text-white" />
</IconButton>
);

Copy link
Contributor

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

Comment on lines +353 to +361

function logout() {
googleLogout();
setIsLoggedIn(false);
setIDToken('');
setName('');
setProfilePic('');
}

Copy link
Contributor

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

Comment on lines +348 to +351
const jwt: GoogleJWT = credential ? jwtDecode(credential) : ({} as GoogleJWT);
setIDToken(credential);
setName(jwt.given_name);
setProfilePic(jwt.picture);
Copy link
Contributor

Choose a reason for hiding this comment

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

really cool!

Comment on lines +305 to 311
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
Copy link
Contributor

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!

@surchs surchs merged commit 7b16bba into main Jul 14, 2024
9 checks passed
@surchs surchs deleted the feat-197 branch July 14, 2024 18:38
@surchs surchs restored the feat-197 branch July 14, 2024 18:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pr-minor-breaking Feature or enhancement that breaks compatibility, will increment minor version (0.+1.0)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Implement OIDC flow that results in a query sent to the f-API including access and ID tokens
2 participants