change RP interfaces
This commit is contained in:
parent
ed6cbe4fe2
commit
45230569d3
10 changed files with 529 additions and 259 deletions
|
@ -25,17 +25,24 @@ type Encoder interface {
|
|||
Encode(src interface{}, dst map[string][]string) error
|
||||
}
|
||||
|
||||
func FormRequest(endpoint string, request interface{}) (*http.Request, error) {
|
||||
func FormRequest(endpoint string, request interface{}, clientID, clientSecret string, header bool) (*http.Request, error) {
|
||||
form := make(map[string][]string)
|
||||
encoder := schema.NewEncoder()
|
||||
if err := encoder.Encode(request, form); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if !header {
|
||||
form["client_id"] = []string{clientID}
|
||||
form["client_secret"] = []string{clientSecret}
|
||||
}
|
||||
body := strings.NewReader(url.Values(form).Encode())
|
||||
req, err := http.NewRequest("POST", endpoint, body)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if header {
|
||||
req.SetBasicAuth(clientID, clientSecret)
|
||||
}
|
||||
req.Header.Set("Content-Type", "application/x-www-form-urlencoded")
|
||||
return req, nil
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue