Commit 3818f009 authored by icowan's avatar icowan
Browse files

fix 下载日志提示"没有授权登陆"的错误信息

parent 01b658a8
Showing with 4 additions and 1 deletion
+4 -1
......@@ -10,12 +10,14 @@ package middleware
import (
"context"
"github.com/go-kit/kit/auth/casbin"
"github.com/go-kit/kit/auth/jwt"
"github.com/go-kit/kit/transport/http"
"github.com/gorilla/mux"
kplcasbin "github.com/kplcloud/kplcloud/src/casbin"
"github.com/kplcloud/kplcloud/src/util/uid"
stdhttp "net/http"
"strconv"
"strings"
)
func NamespaceToContext() http.RequestFunc {
......@@ -59,6 +61,7 @@ func CookieToContext() http.RequestFunc {
return func(ctx context.Context, r *stdhttp.Request) context.Context {
if c, err := r.Cookie("Authorization"); err == nil {
ctx = context.WithValue(ctx, http.ContextKeyRequestAuthorization, c.Value)
ctx = context.WithValue(ctx, jwt.JWTTokenContextKey, strings.Split(c.Value, "Bearer ")[1])
r.Header.Set(string(http.ContextKeyRequestAuthorization), c.Value)
}
return ctx
......
......@@ -36,8 +36,8 @@ func MakeHandler(svc Service, logger log.Logger, repository repository.Repositor
opts := []kithttp.ServerOption{
kithttp.ServerErrorLogger(logger),
kithttp.ServerErrorEncoder(encode.EncodeError),
kithttp.ServerBefore(middleware.CookieToContext()),
kithttp.ServerBefore(kithttp.PopulateRequestContext),
kithttp.ServerBefore(middleware.CookieToContext()),
kithttp.ServerBefore(kitjwt.HTTPToContext()),
kithttp.ServerBefore(middleware.NamespaceToContext()),
kithttp.ServerBefore(middleware.CasbinToContext()),
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment