mirror of
https://github.com/jech/galene.git
synced 2024-11-25 18:15:57 +01:00
27 lines
583 B
Go
27 lines
583 B
Go
package token
|
|
|
|
import (
|
|
"errors"
|
|
)
|
|
|
|
var ErrUsernameRequired = errors.New("username required")
|
|
|
|
type Token interface {
|
|
Check(host, group string, username *string) (string, []string, error)
|
|
}
|
|
|
|
func Parse(token string, keys []map[string]interface{}) (Token, error) {
|
|
// both getStateful and parseJWT may return nil, which we
|
|
// shouldn't cast into an interface before testing for nil.
|
|
jwt, err := parseJWT(token, keys)
|
|
if err != nil {
|
|
// parses correctly but doesn't validate
|
|
return nil, err
|
|
}
|
|
if jwt != nil {
|
|
return jwt, nil
|
|
}
|
|
|
|
s, _, err := Get(token)
|
|
return s, err
|
|
}
|