update libs

This commit is contained in:
d1slike committed 2020-06-02 14:52:24 +03:00
1 parent 48cbb5c25d
commit b1c16e4901
22 files changed
+301 -204

No files matched your search

+2 -1
View File
@@ -124,11 +124,12 @@ func (v *verifiable) verifyAppToken() error {
return createError("unauthorized", codes.Unauthenticated, "received unexpected identities")
}
applicationId, err := strconv.Atoi(verifiableHeaders[utils.ApplicationIdHeader])
applicationId, err := strconv.ParseInt(verifiableHeaders[utils.ApplicationIdHeader], 10, 32)
if err != nil {
log.Error(log_code.ErrorAuthenticate, errors.WithMessagef(err, "parse appId from redis"))
return createError("internal Server error", codes.Internal)
}
//nolint
if v.appId != -1 && int32(applicationId) != v.appId {
return createError("unauthorized", codes.Unauthenticated, "received unexpected application identity")
}
+7 -4
View File
@@ -8,7 +8,10 @@ import (
"isp-gate-service/conf"
)
var verifyToken token
var (
errInvalidToken = errors.New("invalid token")
verifyToken token
)
type appClaims struct {
*jwt.StandardClaims
@@ -37,7 +40,7 @@ func (t token) Application(token string) (int32, error) {
}
claims, ok := parsed.Claims.(*appClaims)
if !ok {
return 0, errors.New("token is invalid")
return 0, errInvalidToken
}
return claims.AppId, nil
}
@@ -51,7 +54,7 @@ func (t token) User(token string) (string, error) {
}
claims, ok := parsed.Claims.(*userClaims)
if !ok {
return "", errors.New("token is invalid")
return "", errInvalidToken
}
return cast.ToString(claims.UserId), nil
@@ -69,7 +72,7 @@ func (token) parse(token, secret string, claims jwt.Claims) (*jwt.Token, error)
return nil, err
}
if !parsed.Valid {
return nil, errors.New("token is invalid")
return nil, errInvalidToken
}
return parsed, nil
}