add admin authenticate
This commit is contained in:
1 parent
5b115440f1
commit
0edf80ffed
10 files changed
+128
-38
No files matched your search
@@ -0,0 +1,29 @@
|
||||
package authenticate
|
||||
|
||||
import (
|
||||
"github.com/dgrijalva/jwt-go"
|
||||
"github.com/integration-system/isp-lib/config"
|
||||
"github.com/pkg/errors"
|
||||
"isp-gate-service/conf"
|
||||
)
|
||||
|
||||
var token tokenHelper
|
||||
|
||||
type tokenHelper struct{}
|
||||
|
||||
func (tokenHelper) Check(token string) error {
|
||||
secret := config.GetRemote().(*conf.RemoteConfig).SecretKey
|
||||
|
||||
if parsed, err := jwt.Parse(token, func(token *jwt.Token) (interface{}, error) {
|
||||
if _, ok := token.Method.(*jwt.SigningMethodHMAC); !ok {
|
||||
return nil, errors.Errorf("unexpected signing method: %v", token.Header["alg"])
|
||||
}
|
||||
return []byte(secret), nil
|
||||
}); err != nil {
|
||||
return err
|
||||
} else if !parsed.Valid {
|
||||
return errors.New("token is invalid")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
Reference in new issue
Block a user