forked from mcluseau/autentigo
/
api.go
40 lines (34 loc) · 929 Bytes
/
api.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
package api
import (
"errors"
"time"
"github.com/dgrijalva/jwt-go"
"github.com/emicklei/go-restful/v3"
)
var (
// ErrInvalidAuthentication indicates an invalid authentication
ErrInvalidAuthentication = errors.New("invalid authentication")
)
// Authenticator is the interface for authn backends
type Authenticator interface {
Authenticate(user, password string, expiresAt time.Time) (claims jwt.Claims, err error)
}
// API registering with restful
type API struct {
CRTData []byte
Authenticator Authenticator
PublicKey interface{}
PrivateKey interface{}
SigningMethod jwt.SigningMethod
TokenDuration time.Duration
}
// Register provide a restful.WebService from this API
func (api *API) Register() *restful.WebService {
ws := &restful.WebService{}
api.registerBasic(ws)
api.registerSimple(ws)
api.registerKeystone(ws)
api.registerK8sAuthenticator(ws)
api.registerCertificate(ws)
return ws
}