2021-10-29 23:37:05 +02:00
|
|
|
package token
|
|
|
|
|
2023-03-22 04:04:22 +01:00
|
|
|
import (
|
|
|
|
"errors"
|
|
|
|
)
|
|
|
|
|
|
|
|
var ErrUsernameRequired = errors.New("username required")
|
|
|
|
|
2023-03-22 00:07:13 +01:00
|
|
|
type Token interface {
|
|
|
|
Check(host, group string, username *string) (string, []string, error)
|
2022-02-20 01:04:16 +01:00
|
|
|
}
|
|
|
|
|
2023-03-22 00:07:13 +01:00
|
|
|
func Parse(token string, keys []map[string]interface{}) (Token, error) {
|
2023-05-14 21:14:59 +02:00
|
|
|
// both getStateful and parseJWT may return nil, which we
|
2024-05-01 19:05:52 +02:00
|
|
|
// 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
|
2023-05-14 21:14:59 +02:00
|
|
|
}
|
2024-05-01 19:05:52 +02:00
|
|
|
if jwt != nil {
|
2023-05-14 21:14:59 +02:00
|
|
|
return jwt, nil
|
|
|
|
}
|
|
|
|
|
2024-05-01 19:05:52 +02:00
|
|
|
return Get(token)
|
2021-10-29 23:37:05 +02:00
|
|
|
}
|