I've to call a rest API(Class exposed as rest resource in the same org) from Batch class.
For that I've get session Id for authenticaiton
I'm using SOAP API Login method to get Session ID which In turn, I use in my Rest API call for authentication as shown below
req.setHeader('Authorization', 'OAuth ' + userSessionId);
Issue is : for SOAP API Call to generate session ID, I've to store Username and password in batch class or somewher in salesforce(probably Custom setting etc). I'm pretty issue- it is not right practice to store passwords in such a way.
On further researching, I found this thread which provide guidlines how to store sensitive information. I'm thinking to use crypto class but would like to know if there is any easy/simpler way out there.
I'm also thinking probably another way as to use 'OAuth Token' for authentication. For which I've to create connected APP to get client ID and Client Secret. This could avoid username and password totally and therefor no need to encyrpt anything Would that be fine and effecive?
Please suggest what would work best in such scenarios.
Thanks!