vanguardkras/simplegoogleauth

Small package to easily generate google auth link and retrieve users' information (email, name, etc).

v1.0.0 2020-02-04 07:33 UTC

This package is auto-updated.

Last update: 2024-05-04 17:33:01 UTC


README

Small package to easily generate google auth link and retrieve users' information (email, name, etc.).

Installation

Composer

For automatic installation using composer input in your terminal:

composer require vanguardkras/simplegoogleauth

Don't forget to include autoloader to your application:

require __DIR__ . '/vendor/autoload.php';

Manual

You can also download the package directly and include a file to your script.

require_once './simplegoogleauth/src/SimpleGoogleAuth.php';

Also, you need to install Google API PHP client. Follow the instructions here:

https://github.com/googleapis/google-api-php-client

Usage

Configuration

At first you need to create authorization credentials. Follow google instruction here:

Create Authorization credentials

Then download client_secret_*.json.

Code

Create new SimpleGoogleAuth instance and input path to the json config file from the previous step:

use Vanguardkras\SimpleGoogleAuth;

$google = new SimpleGoogleAuth('client_secret.json');

Use $google->getUrl() anywhere in your code to insert google_auth link. For example:

echo '<a href="' . $google->getUrl() . '">Google Login</a>';

On your redirect URI page use the next function:

$data = $google->getProfileInfo();

It will return you a class with user info as it's properties.

In case you want to receive an array use false for $object parameter:

$data = $google->getProfileInfo(false);

Now you can use the received data for your application authorization and registration logic.