omniphx / forrest

A Laravel library for Salesforce
https://omniphx.github.io/forrest/
MIT License
259 stars 120 forks source link

"No token available" in job #284

Closed CaptainCannabis closed 3 years ago

CaptainCannabis commented 3 years ago

I am trying to use WebServer authentication with client secret and key but cannot get beyond the verify method in TokenRepository.

If i switch to UserPassword method and and my login credentials it works with the same salesforec developer instance.

I tried out each of the storage options in config/forrest.php - everyone fails with the same message "no token available".

Forrest::authenticate(); is called in a laravel job on a queue which is triggered by the scheduler.

What could go wrong?

omniphx commented 3 years ago

Hi @CaptainCannabis, WebServer/OAuth isn't really the ideal use case for a scheduled job. UserPassword authentication is preferred/correct approach. If you don't feel comfortable using your password, you could also explore the JWT authentication which allows you to use an SSL certificate instead of a password. Documentation for that is here: https://github.com/omniphx/forrest#jwt-authentication-flow

For some background WebServer or Oauth is used to allows users to log into an app with their credentials. It's akin to logging into a site with Twitter, Google credentials. To set it up, you would need to configure a callback endpoint for Salesforce to send you a token after the user has successfully authenticated on the Salesforce end.

Hope that helps!