-
-
Notifications
You must be signed in to change notification settings - Fork 49
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
Portal Prototype #3732
Open
rahafjrw
wants to merge
42
commits into
main
Choose a base branch
from
portal
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Portal Prototype #3732
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Conflicts: # Sources/App/Core/SiteURL.swift
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
As part of the Swift Mentorship Program, I prototyped an authentication feature for the site. This PR is progress towards #3384.
This system uses AWS Cognito, accessed via the Soto gem. It adds 13 new routes:
GET /portal/
: The logged-in portal page, currently containing only a logout button and delete account button.GET /login/
: Display the login page, where a user inputs their email and passwordPOST /login/
: Logs in the userGET /signup/
: Displays the sign up page, where a user inputs their email and passwordPOST /signup/
: Registers the user in the Cognito pool. At this point, the user is uncomfirmed and will need to verify their registration to be fully registered.GET /verify/
: Displays the verify page, where a user can input the confirmation code sent to their email. Note that a user can only login once they have verified their account. If you sign up and lose/don't recieve the code for whatever reason/don't complete the verification step and you attempt to sign up again, an error will be thrown. If you try to login, you will get a "user already exists" error. Ways to combat this will need to be researched.POST /verify/
: Verifies the users sign upPOST /login/
: Logs out the user, which entails destroying the session/cookiePOST /delete/
: Deletes the user from the Cognito poolGET /forgot/
: Displays the forgot password page, which allows user to input the email of the account to reset passwordPOST /forgot/
: Sends an email to the user with a reset codeGET /reset-password/
: Displays the reset password change, which allows to user to input the reset code sent to their email, their email, and a new passwordPOST /reset/
: Resets the user's passwordThese pages are intentionally unstyled as this is just a prototype. However, it can be deployed as all additional code paths are gated to the staging/dev environment.
As mentioned in the issue, a key issue is to avoid storing personally identifying information (PII) in the database. Cognito stores all PII (only an email address) in its own database, leaving the SPI database only responsible for storing the unique identifier.
All core Cognito functionality is in
Cognito.swift
so that it can be easily tested or replaced in the future if a different system is needed. It also utilizes the dependencies library for testing, which are inPortalTests.swift
.Note: At this time, the tests use XCTest, and SPI has since fully adopted swift testing. This branch will not be merged until tests are converted to swift testing.
To persist user authentication post-login between requests, I used Vapor’s Session API with secure cookies. See Vapor’s Session and Website Authentication documentation for more information.
Note: In
Cognito.swift
, the awsClient is created and shutdown at the function level in Cognito because the aws client requires a manual shutdown. It can error if it is globally declared inconfigure.swift
s and not shutdown.This PR does not address:
CognitoAuthenticateResponse
, which is returned by Soto's authenticate()). The refresh token will need to be securely stored, then, in the UserSessionAuthenticator inSessionAuthentication
, it can be used to attempt to refresh the token with .refresh() if Soto throws an unauthorized error with reason "invalid token" (see line 24 ofSessionAuthentication
).Lastly, a huuuuuge thank you to Dave for being so supportive and the best mentor!!!