1
votes

I'm using Twitter API with CodeBird (PHP).

Here is a quote from Twitter's docs:

so for users already signed in to twitter.com who have authorized the application, no UI is shown - instead, they are automatically redirected back to the application.

In the case where the user is already signed in to twitter.com and has granted access to the website, this redirect happens immediately.

https://dev.twitter.com/web/sign-in/desktop-browser

Why this does not work for me? Twitter asks user's permission for each time.

My code for obtaining authorization URL:

    \Codebird\Codebird::setConsumerKey(
        $this->config['twitter']['consumer_key'],
        $this->config['twitter']['consumer_secret']
    );

    $cb = \Codebird\Codebird::getInstance();

    $reply = $cb->oauth_requestToken([
        'oauth_callback' => 'https://***/login/twitter'
    ]);

    $cb->setToken($reply->oauth_token, $reply->oauth_token_secret);

    $this->session->twitter_oauth_token = $reply->oauth_token;
    $this->session->twitter_oauth_token_secret = $reply->oauth_token_secret;
    $this->session->twitter_oauth_verify = true;

    return $this->redirect($cb->oauth_authorize());
1

1 Answers

2
votes

Solved!

oauth_authorize will always ask user for a permission.

oauth_authenticate will request it only once and will perform automatic redirect, if access already granted.