-
Notifications
You must be signed in to change notification settings - Fork 39
/
service_oauth_authentication.go
54 lines (48 loc) · 1.45 KB
/
service_oauth_authentication.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
44
45
46
47
48
49
50
51
52
53
54
package coinbase
import (
"crypto/tls"
"crypto/x509"
"io/ioutil"
"net/http"
)
// ServiceOAuthAuthentication Struct implements the Authentication interface
// and takes care of authenticating OAuth RPC requests on behalf of the service
// (i.e GetTokens())
type serviceOAuthAuthentication struct {
BaseUrl string
Client http.Client
}
// ServiceOAuth instantiates ServiceOAuthAuthentication with the coinbase certificate file
func serviceOAuth(certFilePath string) (*serviceOAuthAuthentication, error) {
// First we read the cert
certs := x509.NewCertPool()
pemData, err := ioutil.ReadFile(certFilePath)
if err != nil {
return nil, err
}
certs.AppendCertsFromPEM(pemData)
mTLSConfig := &tls.Config{
RootCAs: certs, //Add the cert as a TLS config
}
a := serviceOAuthAuthentication{
BaseUrl: "https://coinbase.com/",
Client: http.Client{
Transport: &http.Transport{
Dial: dialTimeout,
TLSClientConfig: mTLSConfig,
},
},
}
return &a, nil
}
// Service OAuth authentication requires no additional headers to be sent. The
// Coinbase Public Certificate is set as a TLS config in the http.Client
func (a serviceOAuthAuthentication) authenticate(req *http.Request, endpoint string, params []byte) error {
return nil // No additional headers needed for service OAuth requests
}
func (a serviceOAuthAuthentication) getBaseUrl() string {
return a.BaseUrl
}
func (a serviceOAuthAuthentication) getClient() *http.Client {
return &a.Client
}