laravel 4 - How to handle Twitter authentication? -
laravel 4 - How to handle Twitter authentication? -
i'm trying integrate functionality in webapp, user clicks button tweet how awesome webapp is. (i know, know, stupid, hey, boss wants it)
i set route below using thujohn's twitter laravel 4 - https://github.com/thujohn/twitter-l4
route::get('/twitter/callback', function() { // should set route on twitter application settings callback // https://apps.twitter.com/app/your-app-id/settings if(session::has('oauth_request_token')) { $request_token = array( 'token' => session::get('oauth_request_token'), 'secret' => session::get('oauth_request_token_secret'), ); twitter::set_new_config($request_token); $oauth_verifier = false; if(input::has('oauth_verifier')) { $oauth_verifier = input::get('oauth_verifier'); } // getaccesstoken() reset token $token = twitter::getaccesstoken( $oauth_verifier ); if( !isset( $token['oauth_token_secret'] ) ) { homecoming redirect::to('/')->with('flash_error', 'we not log in on twitter.'); } $credentials = twitter::query('account/verify_credentials'); if( is_object( $credentials ) && !isset( $credentials->error ) ) { // $credentials contains twitter user object info user. // add together here own user logic, store profiles, create new users on tables...you name it! // typically you'll want store @ least, user id, name , access tokens // if want able phone call api on behalf of users. // moment log in users if you're using laravel's auth class // auth::login($user) should trick. var_dump($credentials); //return redirect::to('/')->with('flash_notice', "congrats! you've signed in!"); } homecoming redirect::to('/')->with('flash_error', 'crab! went wrong while signing up!'); } });
however, don't know should in part:
// $credentials contains twitter user object info user. // add together here own user logic, store profiles, create new users on tables...you name it! // typically you'll want store @ least, user id, name , access tokens // if want able phone call api on behalf of users. // moment log in users if you're using laravel's auth class // auth::login($user) should trick.
what need create sure user doesn't need authenticate himself every time?
if inspect $credentials object, should see oauth access tokens. save these along user info (username, email, name, etc) in database, , can utilize them next time create phone call twitter api.
twitter laravel-4
Comments
Post a Comment