Basic salesforce integration with yii2 httpclient

Hi guys, I’d need to integrate yii2 with salesforce api. I have 2 main questions:
1- how to create the auth system? I have static params to connect to the external api endpoint and get the jwt token.
2- after getting the jwt, i should use session to store the jwt and then pass it as bearer on every request?

The code must do the login autamatically, because the jwt expires after 2 days. Give me pls some advice. Thanks.

  1. About the auth system:
    In my case, I set up a small helper service that handles the JWT authentication flow automatically. Instead of hardcoding, I used the connected app credentials (client id, client secret, private key) to generate a signed JWT and exchange it for an access token. That way, I didn’t need to refresh manually, it handled the login whenever required.

  2. About storing and reusing the JWT:
    Yes, you’ll want to store the token (I used a cache layer like Redis, but a session works too) and pass it as a bearer on every request. Since JWTs expire in 2 days, I built a check to detect expiry and re-generate a fresh token before making the next call. That saved me from broken requests mid-flow.

I ran into a very similar issue when I was working on an integration between monday.com and Salesforce, so I get where you’re coming from.