Authentication parameters are encapsulated in a ConnectionParams object and provided to your DataSource.Connection class’s constructor.
public HttpResponse getResponse(String url) { Http httpProtocol = new Http(); HttpRequest request = new HttpRequest(); request.setEndPoint(url); request.setMethod('GET'); request.setHeader('Authorization', 'Bearer ' + this.connectionInfo.oauthToken); HttpResponse response = httpProtocol.send(request); return response; }
public HttpResponse getResponse(String url) { Http httpProtocol = new Http(); HttpRequest request = new HttpRequest(); request.setEndPoint(url); request.setMethod('GET'); string encodedHeaderValue = EncodingUtil.base64Encode(Blob.valueOf( this.connectioninfo.username + ':' + this.connectionInfo.password)); request.setHeader('Authorization', 'Basic ' + encodedHeaderValue); HttpResponse response = httpProtocol.send(request); return response; }
The Lightning Connect custom adapter automatically obtains the relevant credentials that are stored in Salesforce whenever they’re needed. However, your Apex code must apply those credentials to all callouts, with one exception: HTTP callouts that specify named credentials as the callout endpoints. A named credential lets Salesforce handle the authentication logic for you, so that your code doesn’t have to.
If all your custom adapter’s callouts use named credentials, you can set the external data source’s Authentication Protocol field to No Authentication. The named credentials add the appropriate certificates and headers for basic authentication or OAuth to the HTTP callouts. You also don’t need to define a remote site for any Apex callout endpoint that’s defined as a named credential.