MSP-625 reimplement authenticate
This commit is contained in:
1 parent
538e9a7aab
commit
668cbb37d2
7 files changed
+33
-504
No files matched your search
@@ -0,0 +1,33 @@
|
||||
package middleware
|
||||
|
||||
import (
|
||||
"github.com/pkg/errors"
|
||||
"isp-gate-service/domain"
|
||||
)
|
||||
|
||||
const (
|
||||
adminTokenHeader = "x-auth-admin"
|
||||
)
|
||||
|
||||
type AdminAuthenticate interface {
|
||||
Authenticate(token string) (int, error)
|
||||
}
|
||||
|
||||
func Authenticate(adminAuthenticate AdminAuthenticate) Middleware {
|
||||
return func(next Handler) Handler {
|
||||
return HandlerFunc(func(ctx *Context) error {
|
||||
ctx.AppId = 1 // todo application
|
||||
|
||||
adminToken := ctx.Request.Header.Get(adminTokenHeader)
|
||||
adminId, err := adminAuthenticate.Authenticate(adminToken)
|
||||
if err != nil {
|
||||
return errors.WithMessagef(domain.ErrAuthenticate, "admin athenticate: %v", err)
|
||||
}
|
||||
ctx.AdminId = adminId
|
||||
|
||||
ctx.authenticated = true
|
||||
|
||||
return next.Handle(ctx)
|
||||
})
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user