@ -101,7 +101,7 @@ func GetClaimFromToken(tokensString string) (*Claims, error) {
}
func IsAppManagerAccess ( token string , OpUserID string ) bool {
claims , err := ParseToken ( token )
claims , err := ParseToken ( token , "" )
if err != nil {
return false
}
@ -130,7 +130,7 @@ func CheckAccess(OpUserID string, OwnerUserID string) bool {
}
func GetUserIDFromToken ( token string , operationID string ) ( bool , string ) {
claims , err := ParseToken ( token )
claims , err := ParseToken ( token , operationID )
if err != nil {
log . Error ( operationID , "ParseToken failed, " , err . Error ( ) , token )
return false , ""
@ -138,31 +138,31 @@ func GetUserIDFromToken(token string, operationID string) (bool, string) {
return true , claims . UID
}
func ParseToken ( tokensString string ) ( claims * Claims , err error ) {
func ParseToken ( tokensString , operationID string ) ( claims * Claims , err error ) {
claims , err = GetClaimFromToken ( tokensString )
if err != nil {
log . NewError ( "" , "token validate err" , err . Error ( ) )
log . NewError ( operationID , "token validate err" , err . Error ( ) , tokensString )
return nil , err
}
m , err := commonDB . DB . GetTokenMapByUidPid ( claims . UID , claims . Platform )
if err != nil {
log . NewError ( "" , "get token from redis err" , err . Error ( ) )
log . NewError ( operationID , "get token from redis err" , err . Error ( ) , tokensString )
return nil , & constant . ErrTokenInvalid
}
if m == nil {
log . NewError ( "" , "get token from redis err" , "m is nil" )
log . NewError ( operationID , "get token from redis err" , "m is nil" , tokensString )
return nil , & constant . ErrTokenInvalid
}
if v , ok := m [ tokensString ] ; ok {
switch v {
case constant . NormalToken :
log . NewDebug ( "" , "this is normal return" , claims )
log . NewDebug ( operationID , "this is normal return" , claims )
return claims , nil
case constant . InValidToken :
return nil , & constant . ErrTokenInvalid
case constant . KickedToken :
log . Error ( operationID , "this token has been kicked by other same terminal " , constant . ErrTokenKicked )
return nil , & constant . ErrTokenKicked
case constant . ExpiredToken :
return nil , & constant . ErrTokenExpired
@ -170,6 +170,7 @@ func ParseToken(tokensString string) (claims *Claims, err error) {
return nil , & constant . ErrTokenUnknown
}
}
log . NewError ( operationID , "redis token map not find" , constant . ErrTokenUnknown )
return nil , & constant . ErrTokenUnknown
}
@ -195,7 +196,7 @@ func ParseRedisInterfaceToken(redisToken interface{}) (*Claims, error) {
//Validation token, false means failure, true means successful verification
func VerifyToken ( token , uid string ) ( bool , error ) {
claims , err := ParseToken ( token )
claims , err := ParseToken ( token , "" )
if err != nil {
return false , err
}
@ -207,7 +208,7 @@ func VerifyToken(token, uid string) (bool, error) {
return true , nil
}
func WsVerifyToken ( token , uid string , platformID string ) ( bool , error , string ) {
claims , err := ParseToken ( token )
claims , err := ParseToken ( token , "" )
if err != nil {
return false , err , "parse token err"
}