sadiq-bd/google-auth

There is no license information available for the latest version (1.1.0) of this package.

Google Auth lib for PHP

1.1.0 2024-04-11 08:30 UTC

This package is auto-updated.

Last update: 2025-08-12 17:36:30 UTC


README

Repo views

Google Auth

A simple and efficient Google Authentication Library for PHP.

Table of Contents

Features

  • 🔒 Easy integration with Google OAuth2
  • 📦 Lightweight & dependency friendly
  • 📝 Well-documented and simple API
  • ⚡ Fast and secure authentication
  • 🛡️ Follows best security practices

Installation

Install via Composer:

composer require sadiq-bd/google-auth

Quick Start

require 'vendor/autoload.php';

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();

Usage

1. Configure Google Console

2. Authenticate and Get User Info

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

Configuration

Option Description
client_id Google OAuth2 Client ID
client_secret Google OAuth2 Client Secret
redirect_uri Your App's Redirect URI

API Reference

Method Description
getAuthUrl() Generates the Google OAuth2 authorization URL
fetchAccessToken() Exchanges code for an access token
getUserInfo() Retrieves authenticated user's information

Contributing

Contributions are welcome! Please open issues or submit pull requests for improvements or bug fixes.

License

This project is licensed under the MIT License.