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

Integrate hs_auth #128

Open
seanjparker opened this issue Oct 17, 2019 · 0 comments
Open

Integrate hs_auth #128

seanjparker opened this issue Oct 17, 2019 · 0 comments
Assignees
Labels
back-end Back-end issues P1 Issues that have high priority
Milestone

Comments

@seanjparker
Copy link
Contributor

seanjparker commented Oct 17, 2019

At the moment in hs_hub, the hub has its own login and team system. We need to remove this and replace it with API calls to hs_auth.

We need to change a few systems in the hub:

Login system

First, look at src/util/user/passportLocalStrategy.ts. This uses a LocalStrategy in passportjs. Basically, it takes the username and passport from the request so they can be used for authentication.

We need to replace it with a "cookie strategy" (look at hs_application: src/util/auth/hs_auth for details on implementation). You can also refer to the passport js docs under "custom callback". The hub will perform exactly the same authentication flow as the applications so you can almost copy/paste the code.

In the hub (src/util/user/authorization.ts) we have define some middleware we use to check that:

  1. A user is logged in
  2. They have the required authentication level

We need to replace this with the code from hs_application. It will probably be very similar so you can again just follow how it works in hs_application (we have it all in a single file src/util/auth/hs_auth.ts).

If you could update the file structure in hs_hub to match that of hs_hub for these methods that would be great 😊

Team system

This one might be a bit more difficult, the team system on the hub needs to be refactored to use the hs_auth team API. Most of the work will be done in src/services/teams/teamsService.ts. When they click "Profile" on the Hub we should make API calls to get the users team and when they edit some info (like join/leave teams) we should make an API call to hs_auth to perform these actions. Here is a postman link to a collect where you can find the API endpoints. I have included them below for quick reference as well:

  • Create team -> POST /api/v1/teams with name in the body of the request
  • Get teams -> GET /api/v1/teams
  • Leave team -> DELETE /api/v1/teams/leave
  • Join team -> POST /api/v1/teams/<team id>/join
  • Get team members -> GET /api/v1/teams/<team id>/members

Each of the API requests needs the auth token in the Authorization header. You can see an example of it in hs_application: src/util/auth/hs_auth.ts (around line 70).

@seanjparker seanjparker added back-end Back-end issues P1 Issues that have high priority labels Oct 17, 2019
@seanjparker seanjparker added this to the GUH 2019 milestone Oct 17, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
back-end Back-end issues P1 Issues that have high priority
Projects
None yet
Development

No branches or pull requests

2 participants