attraction / google-iap-authentication
Authenticate users using Google IAP
This package's canonical repository appears to be gone and the package has been frozen as a result.
2.0.0
2021-01-13 16:36 UTC
Requires
- php: >=7.3
- google/auth: ^1.12
- google/cloud-core: ^1.39
- kelvinmo/simplejwt: ^0.4.1
This package is auto-updated.
Last update: 2024-05-14 00:13:56 UTC
README
A simple class to help you authenticate the users accessing your ressources thru Google Identity-Aware Proxy.
Installation
It's recommended that you use Composer to install google-iap-authentication.
$ composer require attraction/google-iap-authentication:^2.0
This will install google-iap-authentication and all required dependencies. google-iap-authentication requires PHP 7.3 or newer.
Usage
use Attraction\GoogleIAPAuthentication; // Project ID and Number are available in Google Cloud Project Settings - https://console.cloud.google.com/iam-admin/settings $projectId = 'YOUR_PROJECT_ID'; $projectNumber = 'YOUR_PROJECT_NUMBER'; // You can also use your preferred framework to fetch the headers, here we use getallheaders() to make it simple. $idToken = getallheaders()['X-Goog-Iap-Jwt-Assertion'] ?? ''; $iap = new GoogleIAPAuthentication($projectId, $projectNumber); try { $user = $iap->validateAssertion($idToken); } catch(Throwable $e) { print(sprintf('Unable to proceed: %s',$e->getMessage())); } print(sprintf('User logged in - Email Address: %s - User ID: %s',$user->emailAddress,$user->userId));