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
sunil2018sunil2018 

Is Salesforce Authentication process is different for inboud and outbound integration?

HI All,
Please provide your inputs on Salesforce Authentication process required for
1)Inbound REST API
2)outboud REST API
 
Best Answer chosen by sunil2018
AnudeepAnudeep (Salesforce Developers) 
Hi Sunil, 

Sharing an outbound example
 
HttpRequest req = new HttpRequest();
req.setEndpoint('https://my_endpoint.example.com/some_path');
req.setMethod('GET');

// Because we didn't set the endpoint as a named credential, 
// our code has to specify:
// - The required username and password to access the endpoint
// - The header and header information
 
String username = 'myname';
String password = 'mypwd';
  
Blob headerValue = Blob.valueOf(username + ':' + password);
String authorizationHeader = 'BASIC ' +
EncodingUtil.base64Encode(headerValue);
req.setHeader('Authorization', authorizationHeader);
   
// Create a new http object to send the request object
// A response object is generated as a result of the request  
  
Http http = new Http();
HTTPResponse res = http.send(req);
System.debug(res.getBody());

Example with Named Credentials
 
HttpRequest req = new HttpRequest();
req.setEndpoint('callout:My_Named_Credential/some_path');
req.setMethod('GET');
Http http = new Http();
HTTPResponse res = http.send(req);
System.debug(res.getBody());

Please mark this answer as Best if it is helpful

Anudeep

All Answers

ShirishaShirisha (Salesforce Developers) 
Hi Sunil,

Greetings!

No,you can use same authentication for both and using Named Credentials to store the confidential information like username and password is the best practice.

Named Credentials:https://help.salesforce.com/apex/HTViewHelpDoc?id=named_credentials_define.htm&language=en_us

Also,please find the information in the below blog for authentication:

https://developer.salesforce.com/blogs/developer-relations/2015/07/using-apex-to-integrate-salesforce.html

Kindly mark it as best answer if it helps so that it can help others in the future.

Warm Regards,
Shirisha Pathuri
sunil2018sunil2018
Hi Shrisha,

Thank you for your respnose.

1)Inbound REST API --- Is only connected app required for inbound integration authentication? or Remote site also also required for authorization .
2)outboud REST API ---- Is only Remote site setting is required. No connected app needed here. Please correct me here.

Can you please provide your inputs when Connected app and Remote site needed for Inbound /Outbound REST API.
AnudeepAnudeep (Salesforce Developers) 
Hi Sunil, 

1) Inbound REST API

For Inbound calls, you can do with a connected app/Auth Provider. See this blog for example

2) Outbound REST API

For outbound calls, you can use oAuth 2.0. See
OAuth Authorization Flows

If you find this information helpful, please mark this answer as Best. It may help others in the community. Thank You!

Anudeep
sunil2018sunil2018
Thank you Anudeep. 
Could you share outbound example please.
AnudeepAnudeep (Salesforce Developers) 
Hi Sunil, 

Sharing an outbound example
 
HttpRequest req = new HttpRequest();
req.setEndpoint('https://my_endpoint.example.com/some_path');
req.setMethod('GET');

// Because we didn't set the endpoint as a named credential, 
// our code has to specify:
// - The required username and password to access the endpoint
// - The header and header information
 
String username = 'myname';
String password = 'mypwd';
  
Blob headerValue = Blob.valueOf(username + ':' + password);
String authorizationHeader = 'BASIC ' +
EncodingUtil.base64Encode(headerValue);
req.setHeader('Authorization', authorizationHeader);
   
// Create a new http object to send the request object
// A response object is generated as a result of the request  
  
Http http = new Http();
HTTPResponse res = http.send(req);
System.debug(res.getBody());

Example with Named Credentials
 
HttpRequest req = new HttpRequest();
req.setEndpoint('callout:My_Named_Credential/some_path');
req.setMethod('GET');
Http http = new Http();
HTTPResponse res = http.send(req);
System.debug(res.getBody());

Please mark this answer as Best if it is helpful

Anudeep
This was selected as the best answer
sunil2018sunil2018
Thank you Anudeep