[SalesForce] How to make a Public REST API in apex without user name/Password but using authToken in apex class

I am trying to create REST API using apex class in Salesforce.
I am following the Link to create REST API.
I want to make it public so that we can access this from anywhere only by hitting the URL like: https://myInstance.com/services/apexrest/MyClassURLMappingName.

But it gives me error of authorization or URL not found/URL not correct etc.

Now my question is:
How can I get authenticated with Salesforce Instance without giving User name and password?

For this, i think I have to create a connected application. But it required callback URL, (I am confuse about it. What it should be?).

After creating connected app, we have client ID, client Secret. Now what is the code that I need to write in apex class to make REST API link accessible publicly, but without Force.com Sites.

Please help me out with some code or some exact steps.
I have create a simple class with some debug statements and I just want to get them in debug logs, to check if my API is working fine? It is authenticating automatically with Salesforce instance or not.

Any help will be appreciated.

Best Answer

It's not possible to create public rest service to salesforce without credentials. You need some kind of service between salesforce and WWW with hardcoded credentials/authToken and refresh token processing strategy (dependant on authentication strategy) e.g. we use Mule esb

But still it's not safe to make salesforce api accesible to everyone.

Related Topic