PHP code example of jkbennemann / laravel-4-social-oauth
1. Go to this page and download the library: Download jkbennemann/laravel-4-social-oauth library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
jkbennemann / laravel-4-social-oauth example snippets
/**
* Login user with github
*
* @return void
*/
public function loginWithGithub() {
// get data from input
$code = Input::get( 'code' );
// get github service
$service = OAuth::provider( 'github' );
// check if code is valid
// if code is provided get user data and sign in
if ( !empty( $code ) ) {
// This was a callback request from github, get the token
$accessToken = $service->getAccessTokenByRequestParameters(Input::all());
// fetch information for authorized token
$user = $service->getIdentity($accessToken);
var_dump($user);
//perform user lookup e.g. User::findByEmail($user->email);
//login User
//redirect the user to any page
exit();
} else {
// if not ask for permission first
// get service authorization
$url = $service->makeAuthUrl();
// return to auth page
return Redirect::to($url);
}
}