2

I was trying to call OAuth from our website but it gives an error

Access to XMLHttpRequest at 'https://.salesforce.com/services/oauth2/token' from origin 'https://***.com.ph' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource.

And i already added this on COR Policy enter image description here

here is the Javascript im Using

jQuery.ajax({
         beforeSend: function(xhr) {
        xhr.setRequestHeader("Access-Control-Allow-Origin", "*");
       
    },
    contentType: 'application/json',
    cache: false,
        type: "POST",
        url: "https://***.salesforce.com/services/oauth2/token",
        data: {
             "client_id":"****",
        "client_secret":"****",
        "username":"*****",
        "password":"*****",
        "grant_type":"password",
        },
        
        success: function (response) {
            //service.php response
            console.log(response);
            // jQuery("#form-field-uthentication_token").val(response.access_token);
        }
    });
1
  • Hi, did you resolve it ? I am facing the same issue! Jun 11 at 9:21

1 Answer 1

0

I would suggest you to add your site into below:

  1. CSP Trusted Sites
  2. CORS Setting

In addition to the above, did you try using ConnectedApp to achieve what you wanted?

Also i had used Allow CORS: Access-Control-Allow-Origin chrome extension to test.

Let me know if it helps.

1
  • I did try.. still the same.... :( Jun 25, 2021 at 8:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.