forked from rwestlund/quickbooks-go
-
Notifications
You must be signed in to change notification settings - Fork 1
/
discovery.go
49 lines (44 loc) · 1.33 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
package quickbooks
import (
"encoding/json"
"io/ioutil"
"log"
"net/http"
)
// Call the discovery API.
// See https://developer.intuit.com/app/developer/qbo/docs/develop/authentication-and-authorization/openid-connect#discovery-document
//
func CallDiscoveryAPI(discoveryEndpoint EndpointURL) *DiscoveryAPI {
log.Println("Entering CallDiscoveryAPI ")
client := &http.Client{}
request, err := http.NewRequest("GET", string(discoveryEndpoint), nil)
if err != nil {
log.Fatalln(err)
}
//set header
request.Header.Set("accept", "application/json")
resp, err := client.Do(request)
defer resp.Body.Close()
body, err := ioutil.ReadAll(resp.Body)
if err != nil {
log.Fatalln(err)
}
discoveryAPIResponse, err := getDiscoveryAPIResponse(body)
return discoveryAPIResponse
}
type DiscoveryAPI 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"`
}
func getDiscoveryAPIResponse(body []byte) (*DiscoveryAPI, error) {
var s = new(DiscoveryAPI)
err := json.Unmarshal(body, &s)
if err != nil {
log.Fatalln("error getting DiscoveryAPIResponse:", err)
}
return s, err
}