Closed aishmuru closed 3 months ago
To summarize you are looking to regenerate the access token and update the sfClient object with the new access token
Hey @aishmuru , thanks for bringing this up. It's a feature that I've wanted to implement but hadn't decided how yet. But I'll definitely look into it now 😄
I'd love to be able to use a refresh token
, but unfortunately it is only generated from the web server, user-agent, or hybrid app token flow.
One option that I think would work for now would be to simply call the Init()
method again, passing the same credentials, and set the value to your existing sfClient
instance.
Here's some thoughts on a new solution.
refreshSession()
that resubmits your credentials and generates a new AccessToken
RefreshSession()
a public method and let the user manually handle calling itI like the idea of doing it automatically, but I'll have to verify that I can reliably catch the right error. What error message/status code did you get for an expired session?
@k-capehart Thanks for your response.
Can you please take this feature enhancement on priority? This is problem for all, who are using client credentials flow. The token will expire so the existing package is only be useful for few hours after starting server.
@aishmuru Did you try the temporary solution I mentioned above? If you get an INVALID_SESSION
error you can call Init()
again to manually refresh your session.
You can also extend your timeout value to 24 hours in your Session Settings in your Salesforce org.
I'll let you know when the full solution is rolled out.
See above for the PR. It's mostly done, just needs some extra tests. Feel free to check out the branch and point your project to it if you need it ASAP. I won't have a chance again until Monday or Tuesday. But again, you should be able do a work-around like I mentioned above.
@aishmuru This has been implemented as part of v2.1.0. Let me know if you run into any more issues!
To upgrade: go get github.com/k-capehart/go-salesforce/v2@v2.1.0
thanks @k-capehart will check
@k-capehart I observed that DoRequest() generates a requestPayload{} without retry flag.
How should we set this flag to ensure a rety logic is triggered on token expiration?
Thanks in advance!
Hey @jozephp , anytime a request is made and returns the INVALID_SESSION_ID
error, it will set the retry flag to true and attempt again. It is always submitted initially as false. The flag is just to ensure you don't get caught in an endless loop.
I just tested it with the DoRequest()
method and it works as expected. That is, it will refresh the session and attempt to retry. If you're still noticing an issue or have a specific example where it's failing then please open a new Issue so I can look into it further.
@k-capehart,
We are using client credentials flow to generate the token at the starting of Golang server. Can you please suggest how to use this package to have the non-expiring token / the token that refreshes before the older one expires. Is there any middleware that handles token expiry. If the solution does not exist already, can we add a new feature to handle the refresh token.
We are using Init() method at starting of server.
Thanks! Aishwarya