I'm getting the following error authenticating with the UN/PW oauth2 flow (I redacted the actual domain name):
Unauthorized endpoint, please check Setup->Security->Remote site settings. endpoint = https://CUSTOM_DOMAIN.cs32.my.salesforce.com/services/oauth2/token
I have added a remote site setting for this domain but the error is persisting. Has anyone else experienced this doing oauth2 callouts to orgs with custom login domains?
NOTE: this org does have this checkbox enabled Prevent login from https://test.salesforce.com
.
EDIT:
if (customer.thisOrg.domain_override__c!=null) {
req.setEndpoint(customer.thisOrg.domain_override__c+'/services/oauth2/token');
}
else {
//check to see if type is sandbox or production/developer
if(customer.thisOrg.type__c == 'Sandbox'){
req.setEndpoint('https://test.salesforce.com/services/oauth2/token');
}
else{
req.setEndpoint('https://login.salesforce.com/services/oauth2/token');
}
}
req.setMethod('POST');
req.setBody('grant_type=password'+
'&client_id='+' CLIENT_ID'+
'&client_secret='+'CLIENT_SECRET'+
'&username='+customer.thisOrg.username__c+
'&password='+customer.thisOrg.password__c
);
httpResponse res = new httpResponse();
try {
// send request
Http http = new Http();
// capture response
res = http.send(req);
system.debug('authentication response: '+ res.getBody());
}
catch (exception e) {
system.debug('error authenticating with customer: '+ e.getMessage());
customer.log += '\n\n error authenticating: ' + e.getMessage();
return null;
}
https://CUSTOM_DOMAIN.cs32.my.salesforce.com/
in remote site.. If yes also try to addhttps://test.salesforce.com