mirror of
https://github.com/jech/galene.git
synced 2024-11-09 02:05:59 +01:00
Used named errors in token code.
This commit is contained in:
parent
9141d9eccb
commit
947eb71328
1 changed files with 5 additions and 2 deletions
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue