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

Support addition of exclusion URLs to the JWT auth #283

Open
1 task done
ignatij opened this issue Aug 30, 2024 · 0 comments
Open
1 task done

Support addition of exclusion URLs to the JWT auth #283

ignatij opened this issue Aug 30, 2024 · 0 comments
Labels
feature request A feature has been asked for or suggested by the community

Comments

@ignatij
Copy link

ignatij commented Aug 30, 2024

Checklist

Describe the problem you'd like to have solved

We have a server that's accessed from the public network but also provides an API for a machine-to-machine communication. For this API there's no need for the JWT auth process, so ideally we would like to exclude these URLs from the authorization.

Describe the ideal solution

Another middleware that will be provide an easy and intuitive approach for excluding some URLs of the JWT auth process. For example something similar to the current error handler but maybe adapted a bit:

	exlcusionUrlHandler := func(w http.ResponseWriter, r *http.Request) bool {
		if isExclusionUrl(r.URL.String()) {
                      return true
                 }
                 return false
	}
     jwtmiddleware.New(
		jwtmiddleware.WithExclusionUrl(exlcusionUrlHandler),
	)

Alternatives and current workarounds

Currently we use the following approach to achieve this (not sure if it's the best way though):

        jwtExclusions := []string{...}
	jwt := func(next http.Handler) http.Handler {
		fn := func(w http.ResponseWriter, r *http.Request) {
			if isJwtExclusion(r.URL.String(), jwtExclusions) {
				next.ServeHTTP(w, r)
				return
			}
			middleware.CheckJWT(next).ServeHTTP(w, r)
		}
		return http.HandlerFunc(fn)
	}

Additional context

More than happy to provide a PR for this feature if you agree with the provided use case.

@ignatij ignatij added the feature request A feature has been asked for or suggested by the community label Aug 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature request A feature has been asked for or suggested by the community
Projects
None yet
Development

No branches or pull requests

1 participant