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

Return correct error message for invalid tokens.

This commit is contained in:
Juliusz Chroboczek 2024-03-03 15:38:08 +01:00
parent 89f947df1f
commit b8f7c68338
4 changed files with 7 additions and 3 deletions

View file

@ -1012,7 +1012,7 @@ func (g *Group) getPermission(creds ClientCredentials) (string, []string, error)
if creds.Token != "" {
tok, err := token.Parse(creds.Token, desc.AuthKeys)
if err != nil {
return "", nil, err
return "", nil, &NotAuthorisedError{err: err}
}
conf, err := GetConfiguration()

View file

@ -1426,6 +1426,7 @@ func handleClientMessage(c *webClient, m clientMessage) error {
} else if errors.As(err, &autherr) {
s = "not authorised"
time.Sleep(200 * time.Millisecond)
log.Printf("Join group: %v", err)
} else if _, ok := err.(group.UserError); ok {
s = err.Error()
} else {

View file

@ -137,6 +137,10 @@ func parseJWT(token string, keys []map[string]interface{}) (*JWT, error) {
jwt.WithLeeway(5*time.Second),
)
if err != nil {
if errors.Is(err, jwt.ErrTokenMalformed) {
// assume this is not a JWT
return nil, nil
}
return nil, err
}
return (*JWT)(t), nil

View file

@ -28,7 +28,6 @@ func Parse(token string, keys []map[string]interface{}) (Token, error) {
return nil, err1
} else if err2 != nil {
return nil, err2
} else {
return nil, os.ErrNotExist
}
return nil, os.ErrNotExist
}