Extending Symfony2 Web Application Framework by 2014

Extending Symfony2 Web Application Framework by 2014

Author:2014
Language: eng
Format: mobi
Publisher: Packt Publishing


Before you start, you need to create an app on GitHub, which will give you a client_id and a secret_token. Then, we will create our simple controller as follows:

/** * @Route("/github") */ public function ghloginAction(Request $request) { $client = new \Guzzle\Http\Client( 'https://github.com/login/oauth/access_token'); $req = $client->post('', null, [ 'client_id' => 'your app client_id', 'client_secret' => 'your app secret_token', 'code' => $request->query->get('code') ])->setHeader('Accept', 'application/json'); $res = $req->send()->json(); $token = $res['access_token']; $client = new \Guzzle\Http\Client( 'https://api.github.com'); $req = $client->get('/user'); $req->getQuery()->set('access_token', $token); $username = $req->send()->json()['login']; return new Response($username); }



Download



Copyright Disclaimer:
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.