Skip to content

Commit

Permalink
Support proper cookie authentication
Browse files Browse the repository at this point in the history
  • Loading branch information
NicolasDorier committed Jul 27, 2018
1 parent a03db40 commit b73053b
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion rpcclient/infrastructure.go
Original file line number Diff line number Diff line change
Expand Up @@ -820,7 +820,17 @@ func (c *Client) sendPost(jReq *jsonRequest) {
httpReq.Header.Set("Content-Type", "application/json")

// Configure basic access authorization.
httpReq.SetBasicAuth(c.config.User, c.config.Pass)
if c.config.CookieFilePath == "" {
httpReq.SetBasicAuth(c.config.User, c.config.Pass)
} else {
cookie, err := ioutil.ReadFile(c.config.CookieFilePath)
if err == nil {
splitCookie := strings.Split(string(cookie), ":")
if len(splitCookie) == 2 {
httpReq.SetBasicAuth(splitCookie[0], splitCookie[1])
}
}
}

log.Tracef("Sending command [%s] with id %d", jReq.method, jReq.id)
c.sendPostRequest(httpReq, jReq)
Expand Down Expand Up @@ -1065,6 +1075,9 @@ type ConnConfig struct {
// Pass is the passphrase to use to authenticate to the RPC server.
Pass string

// Alternative to User/Pass authentication, this file get read for each request
CookieFilePath string

// DisableTLS specifies whether transport layer security should be
// disabled. It is recommended to always use TLS if the RPC server
// supports it as otherwise your username and password is sent across
Expand Down

0 comments on commit b73053b

Please sign in to comment.