0

I have followed the tutorial from the PM docs (http://wiki.processmaker.com/3.1/OAuth_2.0) and have not success accessing the access token. Currently I am using the trial version of PM and I would like to access the APIs in my java application js file, but the browser returns the following error "XMLHttpRequest cannot load 'myPMServerAddress' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:8100' is therefore not allowed access.".

Any help?? I registered my apps server (http://localhost:8100) within the Website box of the (User Applications -> +New) form and my code looks as followed:

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);
    });    
}); 
chri3g91
  • 1,196
  • 14
  • 16
  • Solution: although the staff at PM said it was a security issue on their trial version servers, I discovered it was an error in the workspace. https://trial.processmaker.com/sysmyWorkspace/oauth2/token was the address I was trying to reach, but I should have removed the 'sys' from the work space and used https://trial.processmaker.com/myWorkspace/oauth2/token – chri3g91 Mar 09 '17 at 14:37
  • Ahh and that solved your issue? Interesting. – Ethan Presberg Mar 12 '17 at 06:03

1 Answers1

0

You need to disable CORS in client side

for Ubuntu: google-chrome --disable-web-security --user-data-dir

for Ms Windows: Go into the command prompt and go into the folder where Chrome.exe is and type

chrome.exe --disable-web-security

I can test that with no errors.

omalave
  • 775
  • 1
  • 8
  • 15