-
Notifications
You must be signed in to change notification settings - Fork 0
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
Feature/auth #54
Feature/auth #54
Conversation
323b2f7
to
199c08c
Compare
199c08c
to
4128f2c
Compare
80bc648
to
edc8ff1
Compare
The stateless implementation is working. We still need to save state, either to invalidate tokens or to link tokens to users for a manual check of permissions. How would you approach this @limwa? |
a3acba4
to
5a0f2e2
Compare
fad201d
to
3964d75
Compare
3964d75
to
f98fb20
Compare
526a51f
to
6097d85
Compare
6097d85
to
cdf62b6
Compare
After some research, I found that JWT with total stateless behavior is the best way to go (see https://stackoverflow.com/questions/6068113/do-sessions-really-violate-restfulness). |
I'll soon add a custom message for invalid tokens. Meanwhile, everything that is important is done, so this is ready for review |
This is fully ready |
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.
This is a really great job! Amazing PR, this will be extremely useful going forward 🚀
That said, I wrote quite a few comments, mostly asking questions since this is a complex PR. I also left some suggestions regarding smaller details.
src/test/kotlin/pt/up/fe/ni/website/backend/controller/AuthControllerTest.kt
Show resolved
Hide resolved
src/test/kotlin/pt/up/fe/ni/website/backend/controller/AuthControllerTest.kt
Outdated
Show resolved
Hide resolved
fun `should return access and refresh tokens`() { | ||
mockMvc.post("/auth/new") { | ||
contentType = MediaType.APPLICATION_JSON | ||
content = objectMapper.writeValueAsString(LoginDto(testAccount.email, testPassword)) |
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.
We should use the same method here and in the test above. I personally like the first one more because it doesn't depend on the Dto implementation but it can also be more verbose
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'll convert the first to this one since I prefer the less verbose approach
src/test/kotlin/pt/up/fe/ni/website/backend/controller/AuthControllerTest.kt
Outdated
Show resolved
Hide resolved
9e40f57
to
c366cf8
Compare
c366cf8
to
b897bc0
Compare
throw InvalidBearerTokenException("invalid refresh token") | ||
} | ||
if (jwt.expiresAt?.isBefore(Instant.now()) != false) { | ||
throw ResponseStatusException(HttpStatus.UNAUTHORIZED, "refresh token has expired") | ||
throw InvalidBearerTokenException("refresh token has expired") |
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 didn't test this on my own so I'm going to ask. I like the change but is this exception being handled or does it just return an unexpected error?
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.
Yes, it is an AuthenticationException. This is being tested, too
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 job! :)
Closes #12
Review checklist
docs/openapi.yml