0

我已按照 PM 文档 ( http://wiki.processmaker.com/3.1/OAuth_2.0 ) 中的教程进行操作,但没有成功访问访问令牌。目前我正在使用 PM 的试用版,我想访问我的 java 应用程序 js 文件中的 API,但浏览器返回以下错误“ XMLHttpRequest cannot load 'myPMServerAddress' has been blocked by CORS policy: No 'Access-Control -Allow-Origin' 标头存在于请求的资源上。因此,不允许访问Origin ' http://localhost:8100 '。 “。

有什么帮助吗??我在(用户应用程序 - > +New)表单的网站框中注册了我的应用程序服务器(http://localhost:8100),我的代码如下所示:

var restServer = 'https://trial.processmaker.com/';
var workspace = 'sysmyWorkspace/';
var jqxhr = $.ajax({
    type: "POST",
    url:  restServer + workspace + 'oauth2/token',      
        data: {
        grant_type   : 'password',
        scope        : '*',
        client_id    : 'myClientId',
        client_secret: 'myClientSecret',
        username     : 'admin',
        password     : 'myPassword'
    }
})
    .done( function(data) {
        if (data.error) {
            alert("Error in login!\nError: " + data.error +    "\nDescription: " + data.error_description);
        }
        else if (data.access_token) {                
           alert("data access token received!");              
            var d = new Date();
            d.setTime(d.getTime() + 60*60*1000);
            document.cookie = "access_token="  + data.access_token  + "; expires=" + d.toUTCString();
            document.cookie = "refresh_token=" + data.refresh_token; //refresh token doesn't expire
        }
        else {
            alert(JSON.stringify(data, null, 4)); 
        }
    })
    .fail(function(data, statusText, xhr) {
        alert("Failed to connect.\nHTTP status code: " + xhr.status + ' '   + statusText);
    });    
}); 
4

1 回答 1

0

您需要在客户端禁用 CORS

对于 Ubuntu:google-chrome --disable-web-security --user-data-dir

对于 Windows 女士:进入命令提示符并进入 Chrome.exe 所在的文件夹并键入

chrome.exe --disable-web-security

我可以测试没有错误。

于 2017-02-25T16:58:42.977 回答