fix jwt auth
This commit is contained in:
parent
9393518045
commit
59c949f627
|
@ -45,12 +45,12 @@ func WithClaims(f func() jwt.Claims) Option {
|
|||
}
|
||||
|
||||
// WithAllow with allow path
|
||||
func WithAllow(path string) Option {
|
||||
func WithAllow(paths ...string) Option {
|
||||
return func(o *options) {
|
||||
if o.allows == nil {
|
||||
o.allows = make([]string, 0, 16)
|
||||
}
|
||||
o.allows = append(o.allows, path)
|
||||
o.allows = append(o.allows, paths...)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -82,10 +82,6 @@ func JWT(keyFunc jwt.Keyfunc, cbs ...Option) middleware.Middleware {
|
|||
return func(next middleware.Handler) middleware.Handler {
|
||||
return func(ctx context.Context) (err error) {
|
||||
md := metadata.FromContext(ctx)
|
||||
authorizationValue, ok := md.Get(authorizationKey)
|
||||
if !ok {
|
||||
return errors.ErrAccessDenied
|
||||
}
|
||||
if len(opts.allows) > 0 {
|
||||
requestPath, ok := md.Get(metadata.RequestPathKey)
|
||||
if ok {
|
||||
|
@ -94,6 +90,10 @@ func JWT(keyFunc jwt.Keyfunc, cbs ...Option) middleware.Middleware {
|
|||
}
|
||||
}
|
||||
}
|
||||
authorizationValue, ok := md.Get(authorizationKey)
|
||||
if !ok {
|
||||
return errors.ErrAccessDenied
|
||||
}
|
||||
if !strings.HasPrefix(authorizationValue, bearerWord) {
|
||||
return errors.ErrAccessDenied
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue