forked from jinmatt/go-quickbooks.v2
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathdiscovery.go
51 lines (43 loc) · 1.2 KB
/
discovery.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
package quickbooks
import (
"encoding/json"
"net/http"
"github.com/omniboost/go-quickbooks/sdk"
)
// Discovery quickbooks discovery API response type
type Discovery struct {
Issuer string `json:"issuer"`
AuthorizationEndpoint string `json:"authorization_endpoint"`
TokenEndpoint string `json:"token_endpoint"`
UserinfoEndpoint string `json:"userinfo_endpoint"`
RevocationEndpoint string `json:"revocation_endpoint"`
JwksURI string `json:"jwks_uri"`
}
// NewDiscovery makes call to quickbooks discovery API and returns discovery object
func NewDiscovery(isSandbox bool) (*Discovery, error) {
var discoveryHost string
if isSandbox {
discoveryHost = sdk.SandboxDiscoveryURL
} else {
discoveryHost = sdk.ProductionDiscoveryURL
}
req, err := http.NewRequest("GET", discoveryHost, nil)
if err != nil {
return nil, err
}
req.Header.Set("accept", "application/json")
httpClient := &http.Client{}
res, err := httpClient.Do(req)
if err != nil {
return nil, err
}
if res.Body != nil {
defer res.Body.Close()
}
discovery := Discovery{}
err = json.NewDecoder(res.Body).Decode(&discovery)
if err != nil {
return nil, err
}
return &discovery, nil
}