-
Notifications
You must be signed in to change notification settings - Fork 38
/
discovery.go
48 lines (39 loc) · 1.29 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
package quickbooks
import (
"encoding/json"
"fmt"
"io/ioutil"
"net/http"
)
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"`
}
// CallDiscoveryAPI
// See https://developer.intuit.com/app/developer/qbo/docs/develop/authentication-and-authorization/openid-connect#discovery-document
func CallDiscoveryAPI(discoveryEndpoint EndpointUrl) (*DiscoveryAPI, error) {
client := &http.Client{}
req, err := http.NewRequest("GET", string(discoveryEndpoint), nil)
if err != nil {
return nil, fmt.Errorf("failed to create req: %v", err)
}
req.Header.Set("Accept", "application/json")
resp, err := client.Do(req)
if err != nil {
return nil, fmt.Errorf("failed to make req: %v", err)
}
defer resp.Body.Close()
body, err := ioutil.ReadAll(resp.Body)
if err != nil {
return nil, fmt.Errorf("failed to read body: %v", err)
}
respData := DiscoveryAPI{}
if err = json.Unmarshal(body, &respData); err != nil {
return nil, fmt.Errorf("error getting DiscoveryAPIResponse: %v", err)
}
return &respData, nil
}