-
Notifications
You must be signed in to change notification settings - Fork 15
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
Jwt authentication #1042
Jwt authentication #1042
Conversation
e7980d5
to
5ecc70c
Compare
d42f8a4
to
29dfd90
Compare
DO NOT MERGE, BEFORE THE HELM CHART IS UPDATED |
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.
Amazing.
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.
Great work overall!
I did a first pass of the review looking only at the elixir code, I will take the time to look at the FE part soonish.
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.
Hey @CDimonaco ,
It looks great. I couldn't do a really deep review as it is huge.
Besides some cosmetic comments, 2 things:
- The routes in
trento.jsx
look duplicated - The login page component html template now is duplicated in the frontend and backend, is this needed?
PD: I have tested the happy path of the branch, and it works great. And really appreciated for the massive amount of tests you added, this give a lot of confidence to the change
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.
Still amazing, but with some comments 😄
@@ -2,7 +2,7 @@ import { getValue } from '../support/common'; | |||
|
|||
describe('User account page', () => { | |||
before(() => { | |||
cy.navigateToItem('About'); | |||
cy.visit('/about'); | |||
cy.url().should('include', '/about'); |
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.
Is this assertion cy.url().should('include', '/about');
needed when we do cy.visit('/about');
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.
I was thinking about that, but since we have some route guards that can change the route url, I just added as a defensive movement to debug the e2e tests in case of failing, but we can remove
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.
Some changes but overall really a good job
})), | ||
}); | ||
}); | ||
it('should redirect to the / path, when the user is already logged in', async () => { |
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.
newline here?
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.
idk formatter goes this way 🤣
const usernameField = screen.getByTestId('login-username'); | ||
const passwordField = screen.getByTestId('login-password'); | ||
|
||
await user.type(usernameField, 'admin'); | ||
await user.type(passwordField, 'admin'); | ||
|
||
const submitButton = screen.getByTestId('login-submit'); | ||
await user.click(submitButton); |
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.
are you sure you can't get those fields by any other query?
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.
I think I can get them with Id certainly, do you think it's better?
…actored The new tests follows the guideline/directory structure of cypress 12. The use of the new session api allows to integration and testing of the jwt authentication across all the screens.
…hen session expires
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.
Here we go! Thanks
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.
excellent work, @CDimonaco ! |
Description
This pr change the authentication method of the web project from stateful cookie auth to stateless jwt auth.
Changes the web auth logic and implement on the frontend a jwt auth flow with the all the client side authentication flow handled within the single page application. Route guard on the frontend will be added.
The application will use a access/refresh token flow, with the SPA responsible for all the api interaction, including the login and the token refresh part. Here some diagrams
Login flow
Refresh token success flow
Refresh token failure flow
The frontend routes are protected with a react router
route guard
. The guard will check that the user is logged in, and the token is valid. The route uses the/api/me
endpoint.The backend jwts, both access and refresh token are signed with a HS256 (HMAC with SHA-256) key, on runtime the key should be provided as config variable.
The AUTHENTICATION IS ENABLED IN THE DEV ENVIRONMENT
How was this tested?
Automatic tests.
The e2e tests are refactored to use cypress version 12 with proper session support across tests, we need that in order to ensure that the authentication mechanism is present in e2e tests and well tested.