artdarek / oauth-4-laravel

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

Redirect loop on twitter #71

Open ghost opened 10 years ago

ghost commented 10 years ago

I am using Artdarek's lib for Laravel but I have a problem.

when users try to login with Twitter they are redirected to Twitter authenticate page and asked for permission. But if they authorize that app Twitter redirects them to page

"Redirecting you back to the application. This may take a few moments." and then redirect back to authenticate page on Twitter. authenticate?oauth_token=UNbRevLchuLCYxsDlgqHODQMmA4osBHoOKbzPLdkCs

Here is my config app/config/packages/artdarek/oauth-4-laravel/config.php

'storage' => 'Session', 
'consumers' => array(
    'Twitter' => array(
        'client_id'         => 'xxxxxxAPI key',
        'client_secret'     => 'xxxxxxAPI secret'
    )       
)

and here is my login function

public function twiiter() {
    $code = Input::get('code');
    $oauth_verifier = Input::get( 'oauth_verifier' );
    $twitterService = OAuth::consumer('Twitter');
    if(!empty($code)) {
        $token = $twitterService->getStorage()->retrieveAccessToken('Twitter');
        $twitterService->requestAccessToken( $code, $oauth_verifier, $token->getRequestTokenSecret() );
        $result = json_decode( $twitterService->request(     'account/verify_credentials.json')     );
        $user = User::where( [ 'twitter_id' => $result->id ] )->first();
        if ( $user ) {
            $user->twitter_id = $result->id;
            $user->save();
            Auth::login($user);
            return Redirect::to('/');
        } else {

        }
    } else {
        $token = $twitterService->requestRequestToken();
        $url = $twitterService->getAuthorizationUri(['oauth_token' => $token->getRequestToken()]);
        return Redirect::to((string)$url);
    }
}

How to fix this problem? I checked in apps.twitter and my app can Sign in with Twitter, where did I made mistake?

joshhornby commented 10 years ago

You need to set the redirect URL on twitter.