You need to sign in to do that
Don't have an account?

Basic http authentication for Salesforce?
Hi,
is there a way to authenticate an application for using the salesforce rest api with just the normal username / password credentials from
the basic http authentication?
I know thats not safe but its just for testing the functionality of my application.
best regards
Elmar
Hi,
Try the below code snippet as reference:
HTTP h = new HTTP();
HTTPRequest r = new HTTPRequest();
r.setEndpoint('https://my.domain.com');
Blob headerValue = Blob.valueOf(username + ':' + password);
String authorizationHeader = 'BASIC ' + EncodingUtil.base64Encode(headerValue);
r.setHeader('Authorization', authorizationHeader);
r.setMethod('GET');
HTTPResponse resp = h.send(r);
Did this answer your question? If not, let me know what didn't work, or if so, please mark it solved.
hi,
what is the salesforce endpoint for the basic http authentication?
for the oauth2 it is https://na1.salesforce.com/services/oauth2/token, right?
and what about the credentials, do i have to use the username password from my developer account?
thx for your help!
best regards
Elmar
You cannot use basic auth to make requests to the salesforce.com REST API.
Hi,
I am surprised to see that it does not work sometimes, I got into serious issue with the word "BASIC " , I changed it to "Basic " and it worked for me.
Hi,
Try the below code snippet as reference:
HTTP h = new HTTP();
HTTPRequest r = new HTTPRequest();
r.setEndpoint('https://my.domain.com');
Blob headerValue = Blob.valueOf(username + ':' + password);
String authorizationHeader = 'BASIC ' + EncodingUtil.base64Encode(headerValue);
r.setHeader('Authorization', authorizationHeader);
r.setMethod('GET');
HTTPResponse resp = h.send(r);
Named Credentials - Setup (https://sfdcfanboy.com/2018/01/15/named-credentials-setup/)
Named Credentials - Code (https://sfdcfanboy.com/2018/01/15/named-credentials-code/)
Thanks in advance.
let userName = document.getElementById('username').value;
let password = document.getElementById('password').value;
console.log(encodeURIComponent(password));
var url = 'https://ap24.salesforce.com/index.jsp?un='+encodeURIComponent(userName)+'&pw='+encodeURIComponent(password);
var xhr = new XMLHttpRequest();
xhr.open("POST",url);
xhr.setRequestHeader('Accept', 'application/json');
xhr.send();
console.log(xhr.responseText);
xhr.onreadystatechange = function() {
if (xhr.readyState == 4) {
console.log(xhr.response);
if(xhr.responseURL == url){
console.log("Error");
}else{
console.log("Successfully Login");
window.open(xhr.responseURL);
}
}
};