From 947eb71328f2ae0b84fdd571b3a878b7833174a6 Mon Sep 17 00:00:00 2001 From: Juliusz Chroboczek Date: Fri, 18 Feb 2022 15:59:59 +0100 Subject: [PATCH] Used named errors in token code. --- token/token.go | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/token/token.go b/token/token.go index d7e546e..90fc3d1 100644 --- a/token/token.go +++ b/token/token.go @@ -10,6 +10,9 @@ import ( "github.com/golang-jwt/jwt/v4" ) +var ErrUnexpectedSub = errors.New("unexpected 'sub' field") +var ErrUnexpectedIss = errors.New("unexpected 'iss' field") + func parseBase64(k string, d map[string]interface{}) ([]byte, error) { v, ok := d[k].(string) if !ok { @@ -114,11 +117,11 @@ func Valid(username, token string, keys []map[string]interface{}, issuer string) sub, ok := claims["sub"].(string) if !ok || sub != username { - return nil, nil, errors.New("invalid 'sub' field") + return nil, nil, ErrUnexpectedSub } iss, ok := claims["iss"].(string) if !ok || iss != issuer { - return nil, nil, errors.New("invalid 'iss' field") + return nil, nil, ErrUnexpectedIss } aud, ok := claims["aud"] var res []string