BenExile / Dropbox

UNMAINTAINED: PHP 5.3 SDK for the Dropbox REST API
MIT License
521 stars 134 forks source link

Token is Invalid #65

Closed Blacx closed 11 years ago

Blacx commented 11 years ago

Dear @BenTheDesigner ,

I got this notice :

Notice: Undefined property: stdClass::$oauth_token in C:\xampp\htdocs\dropbox\Dropbox\OAuth\Consumer\ConsumerAbstract.php on line 165

Notice: Undefined property: stdClass::$oauth_token_secret in C:\xampp\htdocs\dropbox\Dropbox\OAuth\Consumer\ConsumerAbstract.php on line 197
array(3) { ["code"]=> string(3) "401" ["body"]=> object(stdClass)#7 (1) { ["error"]=> string(17) "Token is invalid." } ["headers"]=> array(7) { ["server"]=> string(5) "nginx" ["date"]=> string(29) "Fri, 04 Jan 2013 17:29:50 GMT" ["content-type"]=> string(16) "application/json" ["transfer-encoding"]=> string(7) "chunked" ["connection"]=> string(10) "keep-alive" ["www-authenticate"]=> string(38) "OAuth realm="https://api.dropbox.com/"" ["access-control-allow-origin"]=> string(1) "*" } }

It happens when I revoke application from dropbox. Now I can not access all of the examples, although I've tried to recreate the token using the $storage-> delete (); method. Please help.

BenExile commented 11 years ago

Hi @Blacx

You will need to delete the invalid token and re-authenticate. Which storage handler are you using? I'll try and replicate this issue.

Blacx commented 11 years ago

Hi @BenTheDesigner ,

I've tried to delete a token record in the database and even tried to remove all the session even though I am using PDO storage. But still It can't, because the problem is I do not understand how and using what methods to do re-authentication. Thank's for your fast response.

BenExile commented 11 years ago

Hi,

Re-authentication should simply be running one of the examples again. The storage object should fail to retrieve a token for you redirect to the authentication page.

If you've deleted the token from the database and from the session, it could suggest the token you deleted is not the correct one. Have you double checked there is no token stored for your user ID?

Blacx commented 11 years ago

Hi @BenTheDesigner ,

The real problem occurs when I remove my application permissions from dropbox. Then I try to re-access the examples and hope to perform a page "Api Request Authorization" again from dropbox, but not so. All of the examples you have gives me an error "Token is invalid" and "Authentication failed".

Then I try to run $storage->delete() method, clear the records from the tables, and clean up all instances of session but still showing error.

BenExile commented 11 years ago

Removing the application from Dropbox will cause the API to return a 401 and authentication will fail. This is the intended behaviour.

I have tested this morning by revoking access to my application, deleting the token form the database and clearing my session. Once this is done and I access the examples again, all works as expected.

Are you able to Pastebin the code that sets up the Dropbox objects and tries to delete the token?

Blacx commented 11 years ago

Yes, I create the logout php:

<?php require_once('bootstrap.php'); $storage->delete(); // I'm using PDO storage session_unset(); session_destroy(); header('location:accountinfo.php'); ?>

cmiww.. :(

Blacx commented 11 years ago

Dropbox

BenExile commented 11 years ago

Thanks for the detailed description of the error. I'll investigate and get back to you, hopefully tonight but maybe tomorrow - sorry it can't be sooner.

Blacx commented 11 years ago

I hope so. Thank you very much in advance.

Blacx commented 11 years ago

Dropbox2

henrylevak commented 11 years ago

Any progress on this guys? I'm running into the same issue..

BenExile commented 11 years ago

Hi @Blacx & @henrylevak

Unfortunately I am unable to replicate this issue. When I revoke a token a \Dropbox\Exception is thrown as expected. I have modified the cURL consumer to use the response code as the Exception code so we can handle this.

I have also updated the accountInfo example to catch this Exception and handle it appropriately, deleting invalid tokens and re-authenticating. I've uploaded a video which demonstrates what happens when I revoke an access token using this updated example. See http://vimeo.com/57197882

Can I ask you both to try the example in commit fa4cc2e5bf and post your findings? If the problem persists are you able to provide details about your PHP version/OS?

Blacx commented 11 years ago

Hi @BenTheDesigner ,

I have tried your update and it worked! on accountInfo.php, getFile.php, metaData.php, putStream.php, chunkedUpload.php, and shares.php, now an invalid token has been erased from the storage so that the re-auth has returned to work. (@henrylevak)

I am very grateful for your efforts in helping me. I think this issue should I close, but there are still issues which I will send it back to you. I'll create a new issue, please check back at.

For the future, I use the Windows 8 operating system and uses PHP version 5.3.1

Thank's

BenExile commented 11 years ago

Hi @Blacx

There was no fundamental change to the library that would have fixed this, just the way the 401 returned from Dropbox was handled. Please send over the additional issues.

henrylevak commented 11 years ago

@BenTheDesigner Hey Ben, thanks for the quick turnaround on this. I can also confirm that the changes you made resolved my issue. Funny how we two of us ran into the exact same issue - almost at the same time. Thank you!