/
api.go
43 lines (39 loc) · 1.25 KB
/
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
41
42
43
package webauth
import (
"net/http"
"strings"
"github.com/Cloud-Foundations/golib/pkg/log"
)
type state struct {
// Parameters.
userName string
webauthBrowser []string
tokenFilename string
targetUrls []string
client *http.Client
userAgentString string
logger log.DebugLogger
// Runtime data.
gotCookie chan<- struct{}
portNumber string
tokenToWrite []byte
}
// Authenticate will prompt the user to authenticate to a Keymaster server using
// a Web browser, for the specified username.
// The user will occasionally be prompted to copy-paste a token from the Web
// browser, which will be written to the file specified by tokenFilename.
// The authentication cookie will be saved in the client cookie jar which may be
// used for subsequent requests to sign identity certificates.
func Authenticate(userName, webauthBrowser, tokenFilename string,
targetUrls []string, client *http.Client, userAgentString string,
logger log.DebugLogger) (string, error) {
return authenticate(state{
userName: userName,
webauthBrowser: strings.Fields(webauthBrowser),
tokenFilename: tokenFilename,
targetUrls: targetUrls,
client: client,
userAgentString: userAgentString,
logger: logger,
})
}