func (a *App) SignInFirebaseWithOAuthCredential(r *http.Request, service string, ar *model.AccessResponse) (*model.FirebaseOAuthResponse, *model.AppError) {
sso := a.Config().GetSSOService(service)
providerId := *sso.ProviderId
p := url.Values{}
p.Set("access_token", ar.AccessToken)
p.Set("providerId", providerId)
d := r.Header
_ = d
oAuthBody, err := json.Marshal(map[string]interface{}{
"postBody": p.Encode(),
"returnSecureToken": true,
"returnIdpCredential": true,
})
if err != nil {
return nil, model.NewAppError("SignInWithOAuth", "api.admin.delete_brand_image.storage.not_found", nil, "", http.StatusNotFound)
}
req, requestErr := http.NewRequest("POST", fmt.Sprintf(SignInWithOAuthURL, apiKey), bytes.NewBuffer(oAuthBody))
if requestErr != nil {
return nil, model.NewAppError("SignInWithOAuth", "api.admin.delete_brand_image.storage.not_found", nil, "", http.StatusNotFound)
}
req.Header.Set("Content-Type", "application/json")
req.Header.Set("Accept", "application/json")
resp, err := a.HTTPService.MakeClient().Do(req)
if err != nil {
return nil, model.NewAppError("SignInWithOAuth", "api.admin.delete_brand_image.storage.not_found", nil, "", http.StatusNotFound)
}
defer resp.Body.Close()
if ar == nil || resp.StatusCode != http.StatusOK {
bodyBytes, _ := ioutil.ReadAll(resp.Body)
bodyString := string(bodyBytes)
fmt.Println("Error getting OAuth user: " + bodyString)
return nil, model.NewAppError("SignInWithOAuth", "api.admin.delete_brand_image.storage.not_found", nil, "", http.StatusNotFound)
}
var buf bytes.Buffer
tee := io.TeeReader(resp.Body, &buf)
fu := model.FirebaseOAuthResponseFromJson(tee)
return fu, nil
}