October 15, 2015

[SOLVED] "The state token is invalid or has expired. Please try again."


If you are getting the "The state token is invalid or has expired. Please try again." while building an Add-on for Google Drive Documents/Sheets with oAuth.

 
It is possible that your OAuth server just cuts off the part of the state token parameter.
   


In case of magento just increase the size of oauth callback_url columns from 255 to 512 chars.

 
ALTER TABLE oauth_consumer MODIFY callback_url VARCHAR(512);
ALTER TABLE oauth_consumer MODIFY rejected_callback_url VARCHAR(512);
ALTER TABLE oauth_token MODIFY callback_url VARCHAR(512);


Or via update script (something like that)

$adapter = $installer->getConnection(); 
$tagsTableName = $installer->getTable('oauth/consumer'); 
$adapter->modifyColumn($tagsTableName, 'callback_url', 'VARCHAR(512)'); 
$adapter->modifyColumn($tagsTableName, 'callback_url', 'VARCHAR(512)'); 
$tagsTableName = $installer->getTable('oauth/token'); 
$adapter->modifyColumn($tagsTableName, 'callback_url', 'VARCHAR(512)'); 
$installer->endSetup();