ref
This commit is contained in:
1 parent
910fb81a0e
commit
e0ab3236d4
3 files changed
+14
-36
No files matched your search
@@ -99,16 +99,11 @@ func Do(ctx *fasthttp.RequestCtx, path string) (int32, error) {
|
||||
verifiableKeys[utils.DeviceTokenHeader] = string(getParam(utils.DeviceTokenHeader, &ctx.Request))
|
||||
verifiableKeys, err = auth.verify.Identity(verifiableKeys, path)
|
||||
if err != nil {
|
||||
switch e := err.(type) {
|
||||
case veritification.Error:
|
||||
switch e.Code {
|
||||
case veritification.ErrorCodeInvalidUserId:
|
||||
return 0, createError("unauthorized", codes.Unauthenticated, e.Error())
|
||||
case veritification.ErrorCodePermittedToCall:
|
||||
return 0, createError("forbidden", codes.PermissionDenied, e.Error())
|
||||
default:
|
||||
return 0, createError("internal server error", codes.Internal)
|
||||
}
|
||||
switch err {
|
||||
case veritification.ErrorInvalidUserId:
|
||||
return 0, createError("unauthorized", codes.Unauthenticated, err.Error())
|
||||
case veritification.ErrorPermittedToCallUser, veritification.ErrorPermittedToCallApplication:
|
||||
return 0, createError("forbidden", codes.PermissionDenied, err.Error())
|
||||
default:
|
||||
return 0, createError("internal server error", codes.Internal)
|
||||
}
|
||||
|
||||
@@ -1,26 +1,9 @@
|
||||
package veritification
|
||||
|
||||
const (
|
||||
ErrorCodeInvalidUserId code = 0
|
||||
ErrorCodePermittedToCall code = 1
|
||||
import "errors"
|
||||
|
||||
var (
|
||||
ErrorInvalidUserId = errors.New("received unexpected user identity")
|
||||
ErrorPermittedToCallApplication = errors.New("application has no rights to call this method")
|
||||
ErrorPermittedToCallUser = errors.New("user has no rights to call this method")
|
||||
)
|
||||
|
||||
type (
|
||||
code int
|
||||
|
||||
Error struct {
|
||||
Code code
|
||||
message string
|
||||
}
|
||||
)
|
||||
|
||||
func (e Error) Error() string {
|
||||
return e.message
|
||||
}
|
||||
|
||||
func newError(code code, message string) Error {
|
||||
return Error{
|
||||
Code: code,
|
||||
message: message,
|
||||
}
|
||||
}
|
||||
@@ -98,7 +98,7 @@ func (v *runtimeVerify) Identity(t map[string]string, uri string) (map[string]st
|
||||
return t, err
|
||||
}
|
||||
if msg == permittedToCallInfo {
|
||||
return t, newError(ErrorCodePermittedToCall, "application has no rights to call this method")
|
||||
return t, ErrorPermittedToCallApplication
|
||||
}
|
||||
// ===== CHECK USER TOKEN =====
|
||||
msg, err = v.findStringCmd(resp, 3)
|
||||
@@ -107,7 +107,7 @@ func (v *runtimeVerify) Identity(t map[string]string, uri string) (map[string]st
|
||||
}
|
||||
userIdentity, found := t[utils.UserIdHeader]
|
||||
if found && msg != userIdentity {
|
||||
return t, newError(ErrorCodeInvalidUserId, "received unexpected user identity")
|
||||
return t, ErrorInvalidUserId
|
||||
}
|
||||
// ===== NOT PERMITTED BY USER ID =====
|
||||
msg, err = v.findStringCmd(resp, 5)
|
||||
@@ -115,7 +115,7 @@ func (v *runtimeVerify) Identity(t map[string]string, uri string) (map[string]st
|
||||
return t, err
|
||||
}
|
||||
if msg == permittedToCallInfo {
|
||||
return t, newError(ErrorCodePermittedToCall, "user has no rights to call this method")
|
||||
return t, ErrorPermittedToCallUser
|
||||
}
|
||||
// ===== CHECK DEVICE TOKEN =====
|
||||
msg, err = v.findStringCmd(resp, 7)
|
||||
|
||||
Reference in new issue
Block a user