You need to sign in to do that
Don't have an account?
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
u can refer this ..i have shared most of the things..
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. ?