waglpz / google-sso
Single sign on with Google. Minimal implementation.
Installs: 1 698
Dependents: 1
Suggesters: 0
Security: 0
Stars: 1
Watchers: 2
Forks: 0
Open Issues: 0
Requires
- php: ^8.2
- ext-json: *
- google/apiclient: ^2.13
- waglpz/webapp: ^v2.0
- waglpz/webapp-security: ^v2.0
Requires (Dev)
- doctrine/coding-standard: ^11.1
- phpstan/extension-installer: ^1.1
- phpstan/phpstan: ^1.10
- phpstan/phpstan-deprecation-rules: ^1.0
- phpstan/phpstan-doctrine: ^1.3
- phpstan/phpstan-phpunit: ^1.1
- phpstan/phpstan-strict-rules: ^1.5
- phpstan/phpstan-symfony: ^1.1
- phpstan/phpstan-webmozart-assert: ^1.1
- phpunit/phpunit: ^10.0
- roave/security-advisories: dev-latest
- squizlabs/php_codesniffer: ^3.7
- symfony/var-dumper: ^5.4
This package is auto-updated.
Last update: 2025-03-07 11:47:48 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
- Follow the instructions to Create Web Application Credentials
- Download the JSON credentials in some hidden directory and include this one path in config.
- Set the path to these credentials using config
authConfig
. - Set the scopes required for the API you are going to call using config key
scopes
- Set your application's redirect URI in config
- Set expected prompt when redirect to google. These can
none
,consent
orselect_account
. - 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