PHP code example of codeinc / google-oauth2-middleware
1. Go to this page and download the library: Download codeinc/google-oauth2-middleware 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/ */
codeinc / google-oauth2-middleware example snippets
use CodeInc\GoogleOAuth2Middleware\GoogleOAuth2Middleware;
use CodeInc\GoogleOAuth2Middleware\AuthTokenStorage\JwtStorageDriver;
$googleOAuth2Middleware = new GoogleOAuth2Middleware(
// a fully configured Google client (the client redirect URI must be set)
new Google_Client(),
// storing the auth token using a JWT cookie
new JwtStorageDriver("a_very_secret_key"),
// the lifespan of the authentication (optionnal, 30 minutres by default)
DateInterval::createFromDateString("1 hour")
);
// You can (optionnally) specify a request handler which will be called for unauthenticated requests.
// If not request handler is set the middleware will generate a PSR-7 redirect response toward the
// Google Oauth 2 page
$googleOAuth2Middleware->setUnauthenticatedRequestHandler(new A_PSR7_Request_Handler());