(client *http.Client, endpoint string, clientID string, clientSecret string, form url.Values)
| 1172 | } |
| 1173 | |
| 1174 | func oauthFormRequest(client *http.Client, endpoint string, clientID string, clientSecret string, form url.Values) (map[string]interface{}, error) { |
| 1175 | httpReq, err := http.NewRequest("POST", endpoint, strings.NewReader(form.Encode())) |
| 1176 | if err != nil { |
| 1177 | return nil, err |
| 1178 | } |
| 1179 | httpReq.SetBasicAuth(clientID, clientSecret) |
| 1180 | httpReq.Header.Set("Content-Type", "application/x-www-form-urlencoded") |
| 1181 | |
| 1182 | resp, err := client.Do(httpReq) |
| 1183 | if err != nil { |
| 1184 | return nil, err |
| 1185 | } |
| 1186 | defer resp.Body.Close() |
| 1187 | |
| 1188 | var body map[string]interface{} |
| 1189 | if err := json.NewDecoder(resp.Body).Decode(&body); err != nil { |
| 1190 | if resp.StatusCode >= 200 && resp.StatusCode < 300 { |
| 1191 | return map[string]interface{}{}, nil |
| 1192 | } |
| 1193 | return nil, err |
| 1194 | } |
| 1195 | if resp.StatusCode >= 400 { |
| 1196 | return body, fmt.Errorf("oauth form request failed: %d %v", resp.StatusCode, body) |
| 1197 | } |
| 1198 | return body, nil |
| 1199 | } |
| 1200 | |
| 1201 | func oauthAppAction(client *http.Client, baseAddress string, daptinToken string, actionName string, oauthAppRef string, attributes map[string]interface{}) (map[string]interface{}, error) { |
| 1202 | if attributes == nil { |
no test coverage detected