What are recommended best practices for reusing the OAuth token for the ExactTarget Fuel SDK?

On my website once I get a valid OAuth token, I cache it for 15 minutes and use that same token for all requests. Are there any possible pitfalls to this approach? My website is made up of two web servers. Is the authenticated token based on IP at all?

Instantiate ET_Client:

$params = array("clientid" => $this->getClientId(),
                    "clientsecret" => $this->getClientSecret(),
                    "xmlloc" => 'ExactTarget'.DS.'FuelSDK'.DS.'ExactTargetWSDL.xml' );
$this->_client = new ET_Client(false, false, $params);

Response Object: the instantiated ET_Client returns a tenantToken with a DateTime authTokenExpiration property that is 20 minutes from the request time.

  array(1) {
    array(4) {
      string(24) "..."
      object(DateTime)#628 (3) {
        string(19) "2015-03-06 10:26:36"
        string(3) "UTC"
      string(257) "..."
      string(24) "..."

The token will expire after an hour from the time it is issued. It's best to use it that long before requesting another. Every 15 minutes will work, but requesting a token with every operation could result in throttling of your website. Correct, no other IP addresses will be able to use your token.

  • Thanks @Drew, I'll make sure each server has its own cached token. And regarding the 1 hr token expiration: my returned ET_Client authentication token has an authTokenExpiration DateTime object that is only 20 minutes from my request time, which is why I went with refreshing every 15 minutes. Is this configurable anywhere? – Peggy C Mar 4 '15 at 6:42
  • My guess is that the 20 minutes you saw was the time remaining for the original token. – Drew Simmons Mar 4 '15 at 14:54
  • Actually that was the response from getting a brand new token (no caching). – Peggy C Mar 4 '15 at 17:19
  • Can you include the request and response in your question? Are you able to duplicate it? – Drew Simmons Mar 4 '15 at 17:26
  • Yes I'm able to duplicate it every time. Included my calling code and the token object that is returned. Did not include the full ET_Client object - only the token property that included the expiration datetime object. – Peggy C Mar 6 '15 at 10:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.