infusionsoft / infusionsoft-php

PHP client library for the Infusionsoft API.
https://developer.infusionsoft.com/
Other
129 stars 126 forks source link

Get a Token Laravel #232

Open andikas opened 4 years ago

andikas commented 4 years ago

I want to use infusionsoft server to server connection. Anyone have done getting the infuison token without clicking the authorization url? or anyone have done some "work around" how to done it? Kindly please help me with this one

ajohnson6494 commented 4 years ago

Checkout https://github.com/ajohnson6494/infusionsoft-php/wiki/Server-to-Server-Communication

MCKLtech commented 4 years ago

Edit:

Hold up, I'm wrong. I'll leave the below as a record of my thinking.

Solution: When refreshing a token, do not pass expires_in, only pass endOfLife. This will set the variable correctly and hence the token will know when it is expired.


I think there is a problem with that methodology @ajohnson6494

When I refresh the token, I get the following:

( [accessToken] => e4an4jb8dwnfr39wzb1234546 [refreshToken] => s7abn5tckk58fkgm123456 [endOfLife] => 1579011650 [extraInfo] => Array ( [token_type] => bearer [scope] => full|example.infusionsoft.com ) )

As you can see, we don't have an 'expired_in' field but rather a timestamp of 'endOfLife'. If we subtract the current time() from this, we get the time between now and when the token expires, which logically is expires_in

The issue comes if you save this to the db. When you instanciate a token, say a few hours later, it calculates endOfLife as:

$this->setEndOfLife(time() + $data['expires_in']);

Which means a token will never be marked as expired as it will always be adding expired_in to the current time, not the time the token was issued actually issued.

If I'm not really mistaken, the Token class should instead take endOfLife as an argument and base the expiry on this, rather than calculate it at instantiation.