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

Allow users to retrieve JWT from a query and cookie with a specified name #89

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

JunNishimura
Copy link

Fixes #88

  1. I defined the function TokenFromCookieWith to retrieve jwt from a cookie with a name passed as an argument.
  2. I defined the function TokenFromQueryWith to retrieve jwt from a query with a name passed as an argument.

How to Use

func Verifier(ja *JWTAuth) func(http.Handler) http.Handler {
	return func(next http.Handler) http.Handler {
		return Verify(ja, TokenFromQueryWith("custom-param"), TokenFromHeader, TokenFromCookieWith("custom-cookie"))(next)
	}
}

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.

However, could you think of a better name for the new functions? To me, With() implies some with context pkg.

I'm thinking jwtauth.TokenFromCookieByName("session") or jwtauth.GetTokenFromCookie("session").

Thoughts?

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.

btw: there's a third function that's similar -- TokenFromHeader().

jwtauth.go Outdated
@@ -251,10 +251,25 @@ func SetExpiryIn(claims map[string]interface{}, tm time.Duration) {
claims["exp"] = ExpireIn(tm)
}

const defaultCookieName = "jwt"
Copy link
Contributor

Choose a reason for hiding this comment

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

a single const (for cookie/header/query param) would be enough

to make it easier to understand the usage of of a function from the
function name
@JunNishimura
Copy link
Author

@VojtechVitek

Thanks for the review, and sorry for the delayed response.

I changed the name of functions and cleaned up constants. It would be thankful if you check them again!

Thanks!

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.

Allow users to retrieve JWT from a query and cookie with a specified name
2 participants