2021-05-15 14:03:10 +00:00
|
|
|
package middleware
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
2021-09-05 15:24:13 +00:00
|
|
|
"heruvym/jwt_adapter"
|
2021-05-15 14:03:10 +00:00
|
|
|
"net/http"
|
|
|
|
)
|
|
|
|
|
|
|
|
func (mw *Middleware) MiddlewareGetJwt(next http.Handler) http.Handler {
|
|
|
|
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
|
|
|
// Escape non-GET requests
|
|
|
|
if r.Method != http.MethodGet {
|
|
|
|
next.ServeHTTP(w, r)
|
|
|
|
return
|
|
|
|
}
|
2021-09-05 15:24:13 +00:00
|
|
|
ctx := r.Context()
|
2021-05-15 14:03:10 +00:00
|
|
|
|
|
|
|
bearer := r.URL.Query().Get(jwt_adapter.DefaultHeaderKey)
|
|
|
|
|
|
|
|
adapter, err := jwt_adapter.Decode(bearer)
|
2021-09-05 15:24:13 +00:00
|
|
|
if err == nil {
|
|
|
|
//mw.logger.Emit(ErrorJwtAccess{Err: err})
|
|
|
|
//w.WriteHeader(http.StatusUnauthorized)
|
|
|
|
//return
|
|
|
|
ctx = context.WithValue(r.Context(), jwt_adapter.DefaultHeaderKey, adapter)
|
|
|
|
//
|
2021-05-15 14:03:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
next.ServeHTTP(w, r.WithContext(ctx))
|
|
|
|
})
|
|
|
|
}
|