-
Notifications
You must be signed in to change notification settings - Fork 0
Authentication with JWT, Part 1 #188
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
base: main
Are you sure you want to change the base?
Conversation
… the UI, adding the client tokens app attribute and the get_client_token function
for more information, see https://pre-commit.ci
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #188 +/- ##
==========================================
- Coverage 93.43% 93.09% -0.35%
==========================================
Files 25 31 +6
Lines 2971 3373 +402
Branches 162 246 +84
==========================================
+ Hits 2776 3140 +364
- Misses 195 233 +38 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR implements JWT authentication for both the client and server, secures API endpoints with token checks, and adjusts client‐side asset and import paths to align with Next.js conventions.
- Updated asset and import paths in front‐end files such as sidebar.tsx, page.tsx, and layout.tsx.
- Revised jobs hooks and edit pages to handle client password hashing and removed the redundant usePost hook.
- Enhanced back-end routes to add JWT-based dependency checks and integrated new authentication endpoints for both server and client.
Reviewed Changes
Copilot reviewed 49 out of 49 changed files in this pull request and generated no comments.
File | Description |
---|---|
florist/app/(root)/sidebar.tsx, page.tsx, layout.tsx | Updates to asset paths and import statements for consistency with Next.js conventions. |
florist/app/(root)/jobs/* | Adjusted import paths, updated SWR keys, removed redundant usePost hook, and added client password field and hashing functionality. |
florist/api/* | Added JWT token dependency checks on routes, integrated new auth endpoints, and set up default user creation with secure secret key generation. |
florist/api/db/server_entities.py | Introduced a new User entity with secret key generation and methods to fetch and create users in the database. |
Comments suppressed due to low confidence (1)
florist/api/db/server_entities.py:62
- The function 'jsonable_encoder' is used here but not imported. Please import it from 'fastapi.encoders' (i.e., add 'from fastapi.encoders import jsonable_encoder') to avoid runtime errors.
json_user = jsonable_encoder(self)
… a couple of front end bugs
PR Type
Feature
Short Description
Clickup Ticket(s): https://app.clickup.com/t/868ddgvh7
First of all, obligatory "sorry for the long PR" :)
This is the first part of implementing authentication with JWT, which consists of authentication with a default user and password and gatekeeping of the APIs to only authenticated users. The second part will contain the logic and endpoints to change the default password on first access.
On this PR:
crypto
andjs-cookie
.app/login
folder.app/(root)/
, according to Next.js naming conventions.sha256
to avoid transit and storage of plain text password.api/server/auth/login
endpoint.api/server/auth/login
.401
code (Unauthorized), which means the token is either expired or does not exist.sha256
before sending it to the server to avoid transit and storage of plain text passwords.bcrypt
,pyjwt
andpython-jose
.User
) and client (UserDAO
), which will store the username, password and a secret key that will be used to securely sign a JWT token.admin
user (if one does not already exist) with a default password hashed withsha256
and a randomly generated secret key.check_token
functions on both the client and server to check if a given token is valid.check_token
function to the decorators of all endpoints exceptapi/server/auth/login
andapi/client/auth/login
.hashed_password
field to the client to store the hashed password to the database to be used when calling any client endpoints.app
object to store the tokens issued for all active clients.Tests Added
Fully unit and integration tested.