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

Authenticator: remove jwt.Validate #91

Merged
merged 1 commit into from
Nov 19, 2024

Conversation

drakkan
Copy link
Contributor

@drakkan drakkan commented Jun 9, 2024

jwt.Validate is already called in Verifier, no need to call it twice.

If jwt.Validate fails in Verifier, the error is set in the context and the Authenticator retrieves the token and error from the context.

jwt.Validate is already called in Verifier, no need to call it
twice
Copy link
Contributor

@VojtechVitek VojtechVitek left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Makes sense.

Already called in Verifier:

jwtauth/jwtauth.go

Lines 114 to 116 in 127ee7c

if err := jwt.Validate(token, ja.validateOptions...); err != nil {
return token, ErrorReason(err)
}

@rasm685p
Copy link

rasm685p commented Nov 17, 2024

Looking at the Verifier implementation, the if token == nil check seems redundant too since the Verifier middleware already sets an error in the context when the token is nil. Could someone clarify why this check is needed and why it hasn't been removed?

Copy link
Contributor

@VojtechVitek VojtechVitek left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM.

@klaidliadon this is exactly what we discussed last week.

@VojtechVitek VojtechVitek merged commit cef4764 into go-chi:master Nov 19, 2024
9 checks passed
@rasm685p
Copy link

Looking at the Verifier implementation, the if token == nil check seems redundant too since the Verifier middleware already sets an error in the context when the token is nil. Could someone clarify why this check is needed and why it hasn't been removed?

@VojtechVitek Hi! Wondering if my previous message might have slipped through - would really appreciate your thoughts when you have a moment.

@VojtechVitek
Copy link
Contributor

I guess it can happen if someone forgets to apply Verifier middleware or have a custom verifier that returns nil.

@pkieltyka
Copy link
Member

please leave the code the way it is for extra safety as Vojtech mentioned

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants