PHP code example of sadiq-bd / google-auth

1. Go to this page and download the library: Download sadiq-bd/google-auth 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/ */

    

sadiq-bd / google-auth example snippets




use SadiqBd\GoogleAuth\GoogleAuth;

$googleAuth = new GoogleAuth(
    'YOUR_CLIENT_ID',
    'YOUR_CLIENT_SECRET',
    'YOUR_REDIRECT_URI'
);

// Redirect to Google OAuth
header('Location: ' . $googleAuth->createAuthUrl());
exit();

// After redirect, handle the callback
if (isset($_GET['code'])) {
    $token = $googleAuth->fetchAccessToken($_GET['code']);
    $user = $googleAuth->getUserInfo($token['access_token']);
    // Do something with $user
}