-
Notifications
You must be signed in to change notification settings - Fork 7
/
yubi_authenticator.go
43 lines (34 loc) · 968 Bytes
/
yubi_authenticator.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
41
42
43
package main
import (
"github.com/GeertJohan/yubigo"
"github.com/kelseyhightower/envconfig"
)
type yubiConfig struct {
ClientId string `envconfig:"CLIENT_ID" required:"true"`
ApiKey string `envconfig:"API_KEY" required:"true"`
ApiHost string `envconfig:"API_HOST" default:"api.yubico.com/wsapi/2.0/verify"`
UseHttps bool `envconfig:"USE_HTTPS" default:"true"`
}
type yubiAuth struct {
authenticator *yubigo.YubiAuth
}
func NewYubiAuthenticator() (authenticator, error) {
var c yubiConfig
err := envconfig.Process("KG_YUBI", &c)
if err != nil {
envconfig.Usage("KG_YUBI", &c)
return nil, err
}
yubi, err := yubigo.NewYubiAuth(c.ClientId, c.ApiKey)
if err != nil {
return nil, err
}
yubi.SetApiServerList(c.ApiHost)
yubi.UseHttps(c.UseHttps)
auth := yubiAuth{authenticator: yubi}
return &auth, nil
}
func (a *yubiAuth) authenticate(_, password string) (ok bool, err error) {
_, ok, err = a.authenticator.Verify(password)
return
}