Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var JwtAuthentication = func(next http.Handler) http.Handler { return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { notAuth := []string{ "/api/admin", "/api/admin/login", "/api/admin/client/app", "/api/clients/login", "/ws", } requestPath := r.URL.Path for _, value := range notAuth { if value == requestPath { next.ServeHTTP(w, r) return } } tokenHeader := r.Header.Get("Authorization") if tokenHeader == "" { sendErrorResponse(w, "Missing auth token") return } splitted := strings.Split(tokenHeader, " ") if len(splitted) != 2 { sendErrorResponse(w, "Invalid/Malformed auth token") return } tokenPart := splitted[1] tk := &models.Token{} token, err := jwt.ParseWithClaims(tokenPart, tk, func(token *jwt.Token) (interface{}, error) { return []byte(os.Getenv("token_password")), nil }) if err != nil { sendErrorResponse(w, "Malformed authentication token") return } if !token.Valid { sendErrorResponse(w, "Token is not valid") return } log.Printf("User %v", tk.UserID) ctx := context.WithValue(r.Context(), "user", tk.UserID) r = r.WithContext(ctx) next.ServeHTTP(w, r) }) }
JwtAuthentication validation authentification
Functions ¶
This section is empty.
Types ¶
This section is empty.
Click to show internal directories.
Click to hide internal directories.