We are trying to establish username-password authorization from javascript (visualforce or lightning) but this doesn't work.

We are trying to login from Organization A to Organization B.

POST request payload is the following

'<Envelope xmlns="http://schemas.xmlsoap.org/soap/envelope/">'
                    + '<Header/><Body><login xmlns="urn:partner.soap.sforce.com">'
                    + '<username>' + USERNAME + '</username><password>' + PASSWORD + '</password>'
                    + '</login></Body></Envelope>'

and it is sent to http://login.salesforce.com/services/Soap/u/43.0.

It is working fine from POSTMAN but it is not working from Visualforce page because the following error is failing

Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource.

We tried to use custom login domain and we tried to add everything to whitelist like it is described here.

Nothing worked.

1 Answer 1


Looks like SOAP API which is used for username and password authentication doesn't support CORS since it is not listed in this document

These Salesforce technologies support CORS.

Analytics REST API

Bulk API

Chatter REST API

Salesforce IoT REST API

Lightning Out


User Interface API


And looks like CORS doesn't support resources used for authentication

IMPORTANT CORS does not support requests for unauthenticated resources, including OAuth endpoints. You must pass an OAuth token with requests that require it.

So it is impossible to implement username and password Salesforce authentication in javascript.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .