Commit 947eb713 authored by Juliusz Chroboczek's avatar Juliusz Chroboczek

Used named errors in token code.

parent 9141d9ec
...@@ -10,6 +10,9 @@ import ( ...@@ -10,6 +10,9 @@ import (
"github.com/golang-jwt/jwt/v4" "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) { func parseBase64(k string, d map[string]interface{}) ([]byte, error) {
v, ok := d[k].(string) v, ok := d[k].(string)
if !ok { if !ok {
...@@ -114,11 +117,11 @@ func Valid(username, token string, keys []map[string]interface{}, issuer string) ...@@ -114,11 +117,11 @@ func Valid(username, token string, keys []map[string]interface{}, issuer string)
sub, ok := claims["sub"].(string) sub, ok := claims["sub"].(string)
if !ok || sub != username { if !ok || sub != username {
return nil, nil, errors.New("invalid 'sub' field") return nil, nil, ErrUnexpectedSub
} }
iss, ok := claims["iss"].(string) iss, ok := claims["iss"].(string)
if !ok || iss != issuer { if !ok || iss != issuer {
return nil, nil, errors.New("invalid 'iss' field") return nil, nil, ErrUnexpectedIss
} }
aud, ok := claims["aud"] aud, ok := claims["aud"]
var res []string var res []string
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment