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-03-22 04:04:22 +01:00
|
|
|
t, err := getStateful(token)
|
|
|
|
if err == nil && t != nil {
|
|
|
|
return t, nil
|
|
|
|
}
|
2023-03-22 00:07:13 +01:00
|
|
|
return parseJWT(token, keys)
|
2021-10-29 23:37:05 +02:00
|
|
|
}
|