function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Ankush SomaniAnkush Somani 

getting error "Unauthorized endpoint, please check Setup->Security->Remote site settings. endpoint = https://login.salesforce.com/services/oauth2/token"

I am connecting one org to another org using REST API
I have already set remote site access setting is as follow:
https://login.salesforce.com, and https://ap1.salesforce.com as a instance url.
i am geting authorozie code as a 1st step, but when i am trying to get access_token as a 2nd step of web-server authorization flow, getting this error.
i am setting endpoint in request "https://login.salesforce.com/services/oauth2/token"
please help me.

i am setting my request body:
requestbody ='grant_type='+GRANT_TYPE+'&code='+codeparam+'&client_id='+CLIENT_ID+'&client_secret='+CLIENT_SECRET+'&redirect_uri='+REDIRECT_URL;

using POST method

CheyneCheyne
Try going into Setup -> Security Controls -> Remote Site Settings and adding a new Remote Site with url https://login.salesforce.com.
Ankush SomaniAnkush Somani
i have aready did this setting, read my post completly plz.

CheyneCheyne
Could you post the relevant code that you are using?
Ankush SomaniAnkush Somani

public pagereference connect()
{
      
     String x='https://login.salesforce.com/services/oauth2/authorize?&response_type=code&client_id='+CLIENT_ID+'&redirect_uri='+REDIRECT_URL;
    pagereference p=new pagereference(x);
     return p;
        
}
      
        public pagereference getaccesstoken(){
      //getting authorization code
            string codeparam=apexpages.currentpage().getparameters().get('code');
            Http h = new Http();
            String body='grant_type='+GRANT_TYPE+'&code='+codeparam+'&client_id='+CLIENT_ID+'&client_secret='+CLIENT_SECRET+'&redirect_uri='+REDIRECT_URL;
           
            HttpRequest req = new HttpRequest();
            req.setEndpoint('https://login.salesforce.com/services/oauth2/token');
            req.setMethod('POST');
            req.setBody(body);
   HttpResponse res = h.send(req);            
            Map<string,Object> mapbody=(Map<string,Object>)JSON.deserializeUntyped(res.getbody());
            accesstoken= (string)mapbody.get('access_token');
            system.debug('--accesstoken'+accesstoken);
            return null;
      
       }

plz check my connect() method call, sholud i send http request or this http link through page refernce is fine. ?