middleware

package
v1.14.0-dev.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 25, 2024 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Auth = func(next http.Handler) http.Handler {
	return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
		requestPath := r.URL.Path
		for _, value := range notAuth {
			if value == requestPath {
				next.ServeHTTP(w, r)
				return
			}
		}

		tokenHeader := r.Header.Get("Authorization")

		if tokenHeader == "" {
			http.Error(w, "missing_token", http.StatusUnauthorized)
			return
		}
		tk, err := jwt.ParseToken(tokenHeader)
		if err != nil {
			http.Error(w, err.Error(), http.StatusUnauthorized)
			return
		}
		hit := false
		for _, value := range tk.RegisteredClaims.Audience {
			if value == "eKuiper" {
				hit = true
				break
			}
		}
		if !hit {
			http.Error(w, fmt.Sprintf("audience field should contain eKuiper, but got %s", tk.RegisteredClaims.Audience), http.StatusUnauthorized)
			return
		}

		next.ServeHTTP(w, r)
	})
}

Functions

This section is empty.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL