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

axum-login credential-checking and user session creation #29

Merged
merged 14 commits into from
Feb 9, 2024

Conversation

jhodapp
Copy link
Member

@jhodapp jhodapp commented Jan 15, 2024

Description

Adds axum-login based credential-checking and user session creation/checking/deletion available at two specific new endpoints:

/login
/logout

GitHub Issue: None

Changes

  • Adds a password field to the User entity. Make sure to rerun DB migrations.
  • Protects all existing entity-api endpoints behind needing to log in and create a session
  • Allows 2 DB-seeded users to log in and can maintain the 2 distinct sessions
  • The entity-api endpoints do work, e.g. organizations/*, but only if you pass the session id with every request
  • The user can log out thus destroying the session
  • Uses PostgresStore to store created user sessions, currently stores them under tower_sessions/sessions

Testing Strategy

  • Log in: curl -v --header "Content-Type: application/x-www-form-urlencoded" --data "username=james.hodapp@gmail.com&password=password1&next=organizations" http://localhost:4000/login
  • Notice the cookie that is create and mentioned in the reply which includes a session ID. Copy and replace <session_id> for all other requests.
  • Test an organization endpoint: curl -v --header "Cookie: id=<session_id>" --request GET http://localhost:4000/organizations
  • This should work as expected
  • Log out: curl -v --header "Cookie: id=<session_id>" --request GET http://localhost:4000/logout

Concerns

  • The existing endpoints tests are broken, they need to be updated to log in and create/use a session

@jhodapp jhodapp added feature work Specifically implementing a new feature help wanted Extra attention is needed research Researching something labels Jan 15, 2024
@jhodapp jhodapp self-assigned this Jan 15, 2024
@jhodapp jhodapp changed the title Experimental axum-login password checking and session creation Experimental axum-login credential-checking and session creation Jan 22, 2024
@jhodapp jhodapp changed the title Experimental axum-login credential-checking and session creation Experimental axum-login credential-checking and user session creation Jan 22, 2024
entity_api/src/user.rs Outdated Show resolved Hide resolved
entity_api/src/user.rs Outdated Show resolved Hide resolved
@jhodapp
Copy link
Member Author

jhodapp commented Jan 24, 2024

@calebbourg expressed that this looks like a solid enough base to not just use as a PoC but to actually land this code.

So the main thing that needs to be done before landing is to update the failing tests so that they're able to work with the login/session system. And perhaps add a new blackbox test or two for the new login/user session endpoints.

The original intention of initializing an AppState with database_connection being an Option
was so that we could call AppState::new prior to having a database connection.
I think this new way is fine as well since we are not accessing things like config.database_uri
directly outside of the apps top-level main function. This change allows us to remove a bunch of
unwrap()s
@jhodapp jhodapp force-pushed the experimental_axum_login branch 2 times, most recently from f33c69c to 218ff4a Compare February 5, 2024 04:46
@jhodapp jhodapp changed the title Experimental axum-login credential-checking and user session creation axum-login credential-checking and user session creation Feb 9, 2024
@jhodapp jhodapp marked this pull request as ready for review February 9, 2024 19:14
@calebbourg
Copy link
Collaborator

Approving despite CI failure. Issue tracked in #32

@jhodapp jhodapp merged commit 565b335 into main Feb 9, 2024
0 of 4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature work Specifically implementing a new feature help wanted Extra attention is needed research Researching something
Projects
Status: ✅ Done
Development

Successfully merging this pull request may close these issues.

2 participants