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

Add login functionality to ezBIDS #101

Merged
merged 16 commits into from
Nov 14, 2023

Conversation

nicoalee
Copy link
Collaborator

@nicoalee nicoalee commented Oct 31, 2023

This PR aims to connect our login implementation for brainlife to ezBIDS.

NOTE: This PR is also connected to changes to generate_keys.sh.

HOW TO TEST

  1. Go to chrome and enter this flag in the URL: chrome://flags/#block-insecure-private-network-requests . Set it to disabled
        - This flag exists due to security vulnerabilities so make sure to enable again after testing
  2. Go to http://149.165.152.76:8080/ezbids/
  3. Click on Get Started and log in
        - ADMIN USER: email: [email protected] password: 30q49th
        - GUEST USER: email: [email protected] password: 912r3iub
  4. Check that you can go to warehouse projects and are logged in already
  5. create an ezBIDS session by uploading files
        - login as another user in private browsing (you can create a user if you want or use the one you are not logged in with) and check that you cannot access the session
        - in the original window, click the Share Session button to open the manage users dialog and add a user.
        - use incognito mode and log in as the user you just added. Check that you can access the given session. This user should not be able to see the Share Session button.

SUMMARY OF CHANGES

  1. Removed a bunch of auto generated .js files
  2. Added implementation for validating JWTs in auth.ts.
        - ezBIDS now issues its own JWTs from the /download/:session_id/token which will only be valid for 10 seconds.
        - The reason for this is because the /download/:session_id/* route often is used in a way that does not allow us to attach HTTP headers. We therefore send a JWT in the URL (albeit a short lived one).
        - The /download/:session_id/* route is the only valid route that expects and consumes these JWTs. Other routes will expect JWTs in the header.
  3. All API routes now are protected except for the healthcheck
  4. dev.sh has been modified to be clearer on failure
  5. A ManageUsersDialog has been added in order to add/remove users to the session to share it with them. It can only be shared with other brainlife users
  6. Note: We use the same JWTs received from the auth service as warehouse. This means that if someone logs into warehouse, they can access ezBIDS and vice versa.
  7. A bunch of <a ...><img ... /></a> HTML has been replaced with a custom <AsyncImageLink />. This is because of the previously mentioned token change.
        - previously these elements were bound to the path directly, i.e. <img :src="/route/to/backend.png" />. This doesn't work anymore so this case needs to be handled.
  8. I've replaced all fetch requests with axios. Axios allows us to add a global http interceptor, which I've defined in axios.instance.ts. This attaches a JWT to every outgoing request.
  9. I've added route protections to prevent people from navigating to /ezbids/convert unless they are authenticated
  10. The manage session button only appears if (1) there is a session and (2) the owner of the session is the current user.
        - people added to the session cannot add more users, only the owner can

@nicoalee nicoalee self-assigned this Oct 31, 2023
@bhatiadheeraj bhatiadheeraj removed their request for review November 1, 2023 16:35
@dlevitas
Copy link
Collaborator

dlevitas commented Nov 7, 2023

LGTM, based on your testing instructions.

Copy link
Member

@anibalsolon anibalsolon left a comment

Choose a reason for hiding this comment

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

LGTM some minor things but not obstructing


api/*.pub
api/*.key
api/ezbids.key
Copy link
Member

Choose a reason for hiding this comment

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

I guess the previous line should account for ezbids.key

api/models.ts Outdated Show resolved Hide resolved
style="font-size: var(--el-font-size-extra-large); font-family: unset; color: #3482e9;"
>{{ hasJWT ? "GET STARTED" : "LOG IN / REGISTER"}}</el-button
>
<!-- <RouterLink style="text-decoration: none;" to="/convert">LOG IN / REGISTER</RouterLink> -->
Copy link
Member

Choose a reason for hiding this comment

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

safe to cleanup

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

done


<br>
<br>
<br>

Copy link
Member

Choose a reason for hiding this comment

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

YES

Uploading
<font-awesome-icon icon="spinner" pulse/>
</h3>
<small>Please do not close/refresh this page until all files are uploaded.</small>
Copy link
Member

Choose a reason for hiding this comment

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

For semantics I'd still wrap with a block element, like <p>

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

i removed this originally because i was getting template parsing errors:

image

const res = await axios.post(`${this.config.apihost}/session`, {
headers: { 'Content-Type': 'application/json' }
})
console.log("created new session");
Copy link
Member

Choose a reason for hiding this comment

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

cleanup

Copy link
Collaborator Author

@nicoalee nicoalee Nov 13, 2023

Choose a reason for hiding this comment

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

im going to hold off on this for now, as cleaning this up will mean redoing how we manage configs in ezBIDS. (currently we store them in the store, which is quite annoying if we want to access them outside of the vuex context)

next(err);
});
});

router.post('/upload-multi/:session_id', upload.any(), (req:any, res, next)=>{
router.post('/upload-multi/:session_id', validateWithJWTConfig(), upload.any(), (req: any, res, next) => {
userCanAccessSession(req.params.session_id, req.auth.sub as unknown as number, false).then(async (session) => {
Copy link
Member

Choose a reason for hiding this comment

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

couldnt userCanAccessSession be a router middleware?

Copy link
Collaborator Author

@nicoalee nicoalee Nov 14, 2023

Choose a reason for hiding this comment

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

done, the req object will now hold a property ezBIDS which contains the session

size="large"
closable
v-for="allowedUser in allowedUserProfiles"
:key="allowedUser?.sub"
Copy link
Member

Choose a reason for hiding this comment

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

for some reason, github highlighting breaks at this point, I think it does not understand the ?. yet

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Based on my testing, this should be fine

@dlevitas
Copy link
Collaborator

@nicoalee feel free to merge this PR after looking over Anibal's comments

@nicoalee nicoalee merged commit c45846b into brainlife:master Nov 14, 2023
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants