phpfui / ConstantContact

MIT License
16 stars 7 forks source link

Long lived token still returning empty refresh token #20

Open handoyo opened 6 months ago

handoyo commented 6 months ago

Hi,

apparently long lived token still returning empty refresh token.

Are there any way to check if the scopes are called if we didn't specify the scopes during the init?

phpfui commented 6 months ago

It is entirely possible that Constant Contact has changed the API somehow and this library is no longer working according to the new specs. I have not had any issues myself, but that does not mean it works in all cases.

The valid scopes I know about are:

private array $validScopes = ['account_read', 'account_update', 'contact_data', 'campaign_data', 'offline_access', ];

The scopes get set in the Client::getAuthorizationURL method. Put in some debugging there to see if the request is properly formed according to current Constant Contact API specs.

The token refresh is done in Client::refreshToken method. You should also add some debug there to make sure it is correct. I had a problem recently where I had changed the URL of my Constant Contact integration, but did not change the URL in the Constant Contact API portal. This caused my integration to stop working after the token expired. So check that your redirectURL is working as you expect. I would also add debug there to see if it actually being called when you expect it to be (on a token refresh for sure).

Let me know what you find and I will see if there is anything else I can think of that may be the problem. I also find that trying to explain the problem to someone else with detailed steps will also allow you to figure it out as you try to describe the problem.

Good luck.

phpfui commented 6 months ago

PS. An example of what could be the cause of the token not to refresh is some sort of PHP runtime error in your redirect URL. I have seen that as well. One of the problems of interpreted (vs compiled) languages.

handoyo commented 6 months ago

Thanks for the suggestion, i will add debugging in the places that you mention.

i will let you know my findouts.

handoyo commented 5 months ago

Hi,

apparently i still getting empty token with some time.

Should we still call refresh token if we use long lived token?

phpfui commented 5 months ago

Yes. You will need to refresh the token at some point. Not sure how long that is, but it will need to be done. Set up a cron job to do it every week, then you will never have to worry about it.

handoyo commented 5 months ago

I have the refresh token called when customer open the website, but it appears it still get the empty tokens.

phpfui commented 5 months ago

I think you have a classic race condition in your code. Since you don't know when a web request came come in, it is possible that one request for a new token is overlapping with another. The first token refresh request is in progress when a second one comes in. The second one can fail, since the first request changed the token, but the second request used the original old token, because the first request had not completed to update the database with the new token value. The second request fails with a blank token returned.

The best way to avoid this (besides checking for error returns) would be to use a cron job to fetch a new token at a low traffic time. In case of the race condition, you will only use the current user transaction (check error status and retry the transaction). Then you only have one refresh token call happening at any one time.

handoyo commented 5 months ago

Hi,

I contacted Constant Contact technical support via email.

They asked me to provide thrm with the full request(s) where i am receiving the response (including URL, headers, timestamp, and request body), and the full response body.

Is it possible to get these information by using your library?

Thanks.

phpfui commented 5 months ago

I don't have access to my laptop for a few days, so I can't give a specific answer right now, but the library uses Guzzle. So I would look at the Guzzle docs to see how to get that info, then log it in my library at the correct point, probably in the Client class towards the end.

On Sun, Apr 21, 2024, 4:21 AM yonghan79 @.***> wrote:

Hi,

I contacted Constant Contact technical support via email.

They asked me to provide thrm with the full request(s) where i am receiving the response (including URL, headers, timestamp, and request body), and the full response body.

Is it possible to get these information by using your library?

Thanks.

— Reply to this email directly, view it on GitHub https://github.com/phpfui/ConstantContact/issues/20#issuecomment-2067974638, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABYW6S2WWBTCZ4WJBYROBHLY6OAKDAVCNFSM6AAAAABFBVEEEKVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDANRXHE3TINRTHA . You are receiving this because you commented.Message ID: @.***>