So I am trying to get the auth token and authenticate salesforce api endpoint
where i try to use axios and fetch
i made a function to get post it to the api end point to get the response
sample response is
{
"access_token": "00DR00000008oBT!AQwAQCPqzc_HBE59c80QmEJD4rQKRRc1GRLvYZEq...",
"instance_url": "https://MyDomainName.my.salesforce.com",
"id": "https://login.salesforce.com/id/00DR00000008oBTMAY/005R0000000IUUMIA4",
"token_type": "Bearer",
"issued_at": "1513887500425",
"signature": "3PiFUIioqKkHpHxUiCCDzpvSiM2F6//w2/CslNTuf+o="
}
Link for salesforce api
https://developer.salesforce.com/docs/atlas.en-us.api_iot.meta/api_iot/qs_auth_access_token.htm
then i am trying to pass the auth to get the token and fetch to the endpoint to authenticate
and API gave below example on how to approach
The access_token field in the response contains the access token value. API clients pass the access token in the Authorization header (Authorization: Bearer access_token) of each request.
Use the instance_url field value in the response as the Salesforce instance URL in your REST API resource URIs (for example, instance_url/services/data/v42.0/iot/orchestrations).
can anyone give there peace of mind on how to further solve the problem to finish authentication ?
const auth = ()=>{
axios.post (`${endpoint}/services/oauth2/token`,{
body:`grant_type = password&client_id=${clientId}&
client_secret=${clientSecret}&
username=${username}&
password=${password}`,
headers: {
"Authorization": 'Basic' + Buffer.from(`${client_Id}:${clientSecret}`).toString('base64'),
"Content-Type": "application/x-www-form-urlencoded",
}
})
.then(res => res.json())
.then(json => {
console.log('fetching token')
console.log(res)
return json;
}).catch(error => console.log(error));
return [res.access_token, res.instance_url];
}
const salesforce=( res)=>{
const token = auth(config);
const instanceToken =token[0];
const instance_url= token[1];
return fetch(`{}`)
}