1
Fork 0
mirror of https://github.com/jech/galene.git synced 2024-11-25 10:05:58 +01:00

Used named errors in token code.

This commit is contained in:
Juliusz Chroboczek 2022-02-18 15:59:59 +01:00
parent 9141d9eccb
commit 947eb71328

View file

@ -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)
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