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 /auth endpoint #402

Merged
merged 38 commits into from
Mar 11, 2024
Merged

Add /auth endpoint #402

merged 38 commits into from
Mar 11, 2024

Conversation

seallard
Copy link
Contributor

@seallard seallard commented Mar 6, 2024

Description

Add /auth endpoint. A step in supporting the authorization code flow, see docs. The documentation describes the entire flow, this PR implements Step 5: Exchange authorization code for refresh and access tokens.

This endpoint will be used when a user signs in via Google to exchange the resulting authorization code for a refresh and access token. We can likely extract this service in the future, added to backlog here Clinical-Genomics/cg#3027.

Closes Clinical-Genomics/streamline-delivery#58. The goal is to ensure users in Cigrid do not have to re-login during the workday.

The new components:

  • Authentication service: contains logic for authentication
  • Encryption service: contains logic for encrypting data
  • Google OAuth client: web API client for Googles OAuth endpoints
  • Google API client: web API client for Googles API
  • New column refresh_token in user table

The authentication service does the following

  1. Exchange the authorization code for an access token and refresh token via the Google OAuth client
  2. Use the access token to retrieve the users email via the Google API client
  3. Retrieve the user with matching email from the database if it exists
  4. Encrypt the refresh token and store it on the user
  5. Return the access token

This logic is exposed via the /auth endpoint.

Added

  • /auth endoint

trailblazer/services/encryption_service/utils.py Dismissed Show resolved Hide resolved
trailblazer/services/encryption_service/utils.py Dismissed Show resolved Hide resolved
@seallard seallard marked this pull request as ready for review March 8, 2024 09:40
@seallard seallard requested a review from a team as a code owner March 8, 2024 09:40
Copy link

@ChrOertlin ChrOertlin left a comment

Choose a reason for hiding this comment

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

Looks good!

trailblazer/server/api.py Show resolved Hide resolved
Copy link
Contributor

@islean islean left a comment

Choose a reason for hiding this comment

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

Looks great! Will probably need some manual testing since external APIs are involved but massive effort 💪

trailblazer/server/api.py Show resolved Hide resolved
trailblazer/store/models.py Outdated Show resolved Hide resolved
@clingen-sthlm clingen-sthlm temporarily deployed to stage March 11, 2024 08:31 Inactive
@clingen-sthlm clingen-sthlm temporarily deployed to stage March 11, 2024 08:38 Inactive
Copy link

sonarcloud bot commented Mar 11, 2024

Quality Gate Passed Quality Gate passed

Issues
0 New issues
0 Accepted issues

Measures
0 Security Hotspots
No data about Coverage
0.0% Duplication on New Code

See analysis details on SonarCloud

@clingen-sthlm clingen-sthlm temporarily deployed to stage March 11, 2024 08:49 Inactive
@seallard seallard merged commit acf2224 into master Mar 11, 2024
5 checks passed
@seallard seallard deleted the add-oauth-client branch March 11, 2024 08:51
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.

Add /auth endpoint to trailblazer
4 participants