artdarek / oauth-4-laravel

OAuth Service Provider for Laravel 4
684 stars 217 forks source link

Store Twitter credentials #119

Closed ndamnjanovic closed 9 years ago

ndamnjanovic commented 9 years ago

I have following scenario: User (admin of my website) wants to publish post on Twitter for the first time. App will redirect user to Twitter, so that he can login, and then it will publish post. Just like in example provided in Readme. When same user wants to publish another post, I would like to avoid need for authentication again. So, I stored in db, oauth_token and oauth_verifier that Twitter API returned when signing in for the first time (basically after this piece of code)

    // get request token
    $reqToken = $this->consumer->requestRequestToken();

    // get Authorization Uri sending the request token
    $url = $this->consumer->getAuthorizationUri(array('oauth_token' => $reqToken->getRequestToken()));

And now, I just want to use those stored values, request access token again (do I need to?), and to publish post (without redirecting user to Twitter sign in page again, if he is signed out for some reason ).

      $twitterAPI->getConsumer()->requestAccessToken($social->twitter_access_token, $social->twitter_verifier);
      $result = json_decode($twitterConsumer->request( 'https://api.twitter.com/1.1/statuses/update.json?status=Maybe%20he%27ll%20finally%20find%20his%20keys.%20%23peterfalk', 'POST'), true );

(where $social->twitter_access_token and $social->twitter_verifier are fetched from db)

but it keeps returning TokenResponseException with message Failed to request resource.

Am I missing something obvious regarding OAuth? I checked other issues, but couldn't find solution. Please let me know if this is possible at all.

ndamnjanovic commented 9 years ago

Everything is fine with token, error wasn't clear, actually publishing was denied because status messages were same.