waglpz/google-sso

Single sign on with Google. Minimal implementation.

v2.0.1 2023-06-07 08:01 UTC

This package is auto-updated.

Last update: 2024-05-07 09:58:26 UTC


README

The Google SSO Client Library enables you to work with single sign on via Google API.

Requirements

PHP 8.2 or higher

Installation

composer require waglpz/google-sso:"^1.0"

Authentication with OAuth

  1. Follow the instructions to Create Web Application Credentials
  2. Download the JSON credentials in some hidden directory and include this one path in config.
  3. Set the path to these credentials using config authConfig.
  4. Set the scopes required for the API you are going to call using config key scopes
  5. Set your application's redirect URI in config
  6. Set expected prompt when redirect to google. These can none, consent or select_account.
  7. In the script handling the redirect URI, exchange the authorization code for an access token:
Example
  $config = include __DIR__ . '/../config/sso.php';
  $googleSSO = new \GoogleSSO\GoogleSSO($config);
  $authorizationCodeUrl = $googleSSO->createAuthUrl();
  // Go to the $authorizationCodeUrl and select account you will authenticate against.
  // these will redirect you to defined/known redirect URI and a PHP script will use the code which sends back from Google.
  $accountData = $googleSSO->fetchAccountDataUsingAuthorizationCode($_GET['code']);
  // $accountData contains necessary information if one was founded by google

Code Quality and Testing

To check for coding style violations, run

composer waglpz:code:style:check

To automatically fix (fixable) coding style violations, run

composer waglpz:code:style:fix

To check for static type violations, run

waglpz:code:analyse

To check for regressions, run

composer waglpz:test:norma

To check all violations at once, run

composer waglpz:check:normal