Bin will be removed on June 1, 2014 in favor of http://gist.github.com. Please save all your pastes before then. So long, and thanks for all the fish!×
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
    public function token_request()
    {
 
        $consumer = $this->__createConsumer();
        $requestToken = $consumer->getRequestToken($this->Twitter->getUrl('oauth/request_token'), 'http://planamatch.com/webservices/twitter/callback/');
        $this->Session->write('webservices.requestToken', $requestToken);
       
        # OAUTH NORMAL AUTHORIZE
       # $this->Session->write('webservices.grantRedirect', '/');
       # $this->redirect($this->Twitter->getUrl('oauth/authorize').'?oauth_token='.$requestToken->key);      
       
        # TWITTER OAUTH AUTHENTICATE
       # http://apiwiki.twitter.com/Sign-in-with-Twitter
       $this->Session->write('webservices.grantRedirect', '/users/login');
        $this->redirect($this->Twitter->getUrl('oauth/authenticate').'?oauth_token='.$requestToken->key);
       
    }
   
    /**
     * Handles Twitter authentication response
     * @return unknown_type
     */
    public function callback()
    {
 
        $requestToken = $this->Session->read('webservices.requestToken');
        $consumer = $this->__createConsumer();
        $accessToken = $consumer->getAccessToken($this->Twitter->getUrl('oauth/access_token'), $requestToken);
       
//      var_dump($requestToken);
//      var_dump($accessToken);
//      pr($_SERVER['QUERY_STRING']);
           
        if (isset($accessToken))
        {
            $this->Session->write('webservices.twitterToken', $accessToken);
            $redirectUrl = $this->Session->read('webservices.grantRedirect');
            $this->Session->del('webservices.grantRedirect');
            $this->redirect($redirectUrl);
        }
       
    }