MCPcopy
hub / github.com/daptin/daptin / oauthAppAction

Function oauthAppAction

server_test.go:1201–1231  ·  view source on GitHub ↗
(client *http.Client, baseAddress string, daptinToken string, actionName string, oauthAppRef string, attributes map[string]interface{})

Source from the content-addressed store, hash-verified

1199}
1200
1201func oauthAppAction(client *http.Client, baseAddress string, daptinToken string, actionName string, oauthAppRef string, attributes map[string]interface{}) (map[string]interface{}, error) {
1202 if attributes == nil {
1203 attributes = map[string]interface{}{}
1204 }
1205 if oauthAppRef != "" {
1206 attributes["oauth_app_id"] = oauthAppRef
1207 }
1208 payload, err := json.Marshal(map[string]interface{}{"attributes": attributes})
1209 if err != nil {
1210 return nil, err
1211 }
1212 req, err := http.NewRequest("POST", baseAddress+"/action/oauth_app/"+actionName, bytes.NewReader(payload))
1213 if err != nil {
1214 return nil, err
1215 }
1216 req.Header.Set("Authorization", "Bearer "+daptinToken)
1217 req.Header.Set("Content-Type", "application/json")
1218 resp, err := client.Do(req)
1219 if err != nil {
1220 return nil, err
1221 }
1222 defer resp.Body.Close()
1223 var actionResponses []map[string]interface{}
1224 if err := json.NewDecoder(resp.Body).Decode(&actionResponses); err != nil {
1225 return nil, err
1226 }
1227 if resp.StatusCode >= 400 {
1228 return nil, fmt.Errorf("oauth_app %s action failed: %d %v", actionName, resp.StatusCode, actionResponses)
1229 }
1230 return actionResponseAttributes(actionResponses, "oauth_app"), nil
1231}
1232
1233func actionResponseAttributes(actionResponses []map[string]interface{}, responseType string) map[string]interface{} {
1234 for _, actionResponse := range actionResponses {

Callers 1

runOAuthProviderE2ETestsFunction · 0.85

Calls 3

actionResponseAttributesFunction · 0.85
SetMethod · 0.80
CloseMethod · 0.65

Tested by

no test coverage detected