PHP code example of edisonthk / google-oauth-laravel4
1. Go to this page and download the library: Download edisonthk/google-oauth-laravel4 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/ */
edisonthk / google-oauth-laravel4 example snippets
class HomeController extends BaseController {
public function getIndex()
{
$authUrl = GoogleOAuth::getAuthorizationUri();
$message = "<a href='$authUrl'>Login with Google</a>";
die($message);
}
public function getSuccess()
{
$googleService = GoogleOAuth::consumer();
if(Input::has("code")){
$code = Input::get("code");
$googleService->requestAccessToken($code);
return Redirect::to("/success");
}
if(!GoogleOAuth::hasAuthorized()){
die("Not authorized yet");
}
$result = json_decode( $googleService->request( 'https://www.googleapis.com/oauth2/v1/userinfo' ), true );
$message = 'Your unique Google user id is: ' . $result['id'] . ' and your name is ' . $result['name'];
die($message. "<br/>");
}
public function getLogout()
{
GoogleOAuth::logout();
return Redirect::to("/");
}
}
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.