-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathrequest.go
More file actions
45 lines (35 loc) · 925 Bytes
/
request.go
File metadata and controls
45 lines (35 loc) · 925 Bytes
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
package goapple
import (
"bytes"
"io/ioutil"
"net/http"
"net/url"
)
//fetchLoginData handle user code and goaple config struct
//make http post request to handle data from apple
//return data and relevant error finally
func fetchLoginData(code string, c *Config) (string, error) {
v := url.Values{}
v.Set("client_id", c.ClientID)
v.Set("client_secret", c.PrivateKey.(string))
v.Set("code", code)
v.Set("grant_type", c.GrantType)
vs := v.Encode()
req, err := http.NewRequest("POST", AppleLoginURL, bytes.NewBuffer([]byte(vs)))
req.Header.Add("Content-Type", "application/x-www-form-urlencoded")
req.Header.Add("User-Agent", "curl")
req.Header.Add("Accept", "application/json")
if err != nil {
return "", err
}
client := http.Client{}
res, err := client.Do(req)
if err != nil {
return "", err
}
s, err := ioutil.ReadAll(res.Body)
if err != nil {
return "", err
}
return string(s), nil
}