【问题标题】:sugarcrm fileDownload error after upgrade升级后sugarcrm文件下载错误
【发布时间】:2017-06-21 18:07:13
【问题描述】:

我升级sugar7.8后收到此错误,调用我的文件下载。

{"error":"need_login","error_message":"No valid authentication for user."}

经过一些调查发现糖升级了 OAuth 的 API 调用。以下是我的代码:

 api.fileDownload(api.buildURL("Quotes/" + model.get("id") + "/pdf/download?OAuth-Token=" + api.getOAuthToken()), {
        success: function() {
            app.alert.show("pdf_download_api_success", {
                level: "success",
                messages: SUGAR.language.get('Quotes', 'LBL_QUOTE_PDF_GENERATED'),
                autoClose: true
            });
        },});

我检查了以下网址中的详细信息:但我无法将标头添加到 HTTPS 请求中,有人可以帮忙吗?

https://developer.sugarcrm.com/2016/11/15/security-changes-coming-in-sugar-7-8/

【问题讨论】:

    标签: php oauth-2.0 sugarcrm


    【解决方案1】:

    我从未使用过(或听说过)SugarCRM,但您似乎需要将身份验证令牌从 url 移动到 HTTP-header。究竟如何在对 api.fileDownload() 的内置函数调用中设置标题很难说(并且无法在网上找到描述该函数的单个文档)。但想法是从 url 中删除令牌,然后很可能将标头作为某种参数发送:

    api.fileDownload(api.buildURL("Quotes/" + model.get("id") + "/pdf/download"), {
    http-header: "OAuth-Token = " +api.getOAuthToken(),
        success: function() {
            app.alert.show("pdf_download_api_success", {
                level: "success",
                messages: SUGAR.language.get('Quotes', 'LBL_QUOTE_PDF_GENERATED'),
                autoClose: true
            });
        },});
    

    另一种方法是简单地更改您发布的 URL 中所述的设置:

    “如果您想再次启用此功能,则可以使用名为 allow_oauth_via_get 的新 SugarConfig 设置。当配置设置为 true 时,这将允许使用 oauth_token URL 参数来传递访问令牌。”

    编辑:所以我相信我在 https://github.com/askhogan/sugarcrm/blob/master/index.js 找到了 .js 文件

    函数fileDownload()的底部:

    // ping to make sure we have our token, then make an iframe and download away return this.call('read', this.buildURL('ping'), {}, internalCallbacks, {processData: false});

    您是否尝试过完全删除令牌部分,只是希望库将在 cookie 的帮助下处理身份验证?

    除此之外,该函数似乎没有设置任何标题字段的选项(它似乎读取的唯一选项是 iframe 选项似乎对您没有帮助)。

    【讨论】:

    • 我正在寻找http-header,只是我尝试了你提到的所有内容。
    • 你提到的和我在我的问题中提到的一样。 :(@taracus
    • 好吧,我不确定 api.fileDownload() 调用来自哪里?例如,您如何知道该函数称为 fileDownload() 而不是 downloadFile()?我的猜测是,可以在同一个地方找到有关如何为调用设置 HTTP 标头的文档。作为记录,我用谷歌搜索了 10 分钟,但找不到任何可搜索的 SugarCRM 文档,所以也许他们的文档在付费墙或其他东西后面?
    • 不,我已经搜索了 2 天没有这样的文件 :( 甚至还付费墙 :(
    • 出于好奇(假设你有一个 typeO,意思是 suGarapi.js)你在哪里找到这个 .js 文件? Google 什么也没给我...
    【解决方案2】:

    经过这么多研究,我想出了一个解决这个问题的方法。

    注意:api.fileDownload( 使用OAuth-token 没有支持文档。

    所以我尝试使用XMLHttpRequest,效果很好。

    解决方案

        var request = new XMLHttpRequest();
        request.open('GET', api.buildURL("YOURMODULE/" + model.get("id") + "/pdf/download"), true);
        request.setRequestHeader('OAuth-Token', api.getOAuthToken()); // UR TOKEN
        request.responseType = "blob";
        request.onload = function (e) {
            if (this.status === 200) {
                // `blob` response
                // create `objectURL` of `this.response` : `.pdf` as `Blob`
                var file = window.URL.createObjectURL(this.response);
                var a = document.createElement("a");
                a.href = file;
                /*request.onreadystatechange = function() {
                  if(this.readyState == this.HEADERS_RECEIVED) {
                    console.log(request.getResponseHeader("Content-Type"));
                  }
                }*/
    
                a.download =  request.getResponseHeader("FileName");
                document.body.appendChild(a);
                a.click();
                document.body.removeChild(a);
            };
        };
        request.send();
    

    查看这个帖子可能会在未来有更新:https://community.sugarcrm.com/message/90474-re-sugarcrm-filedownload-error-after-upgrade?commentID=90474#comment-90474

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多