AccessTokenHandler
in package
Manages the access token that is needed to authenticate the Google Firebase API calls.
Table of Contents
Constants
- CACHE_ACCESS_TOKEN_NAME = 'mve_fcm_php_token'
- SCOPE_FIREBASE_MESSAGING = 'https://www.googleapis.com/auth/firebase.messaging'
Properties
- $cache : CacheInterface
- $logger : LoggerInterface|null
- $serviceAccount : array<string|int, mixed>
Methods
- __construct() : mixed
- getProjectId() : string
- Returns the project ID.
- getToken() : string
- Returns a non expired access token from the cache, or if there isn't one, from the Google API and stores this one in the cache.
- base64EncodeUrl() : string
- Returns a base64 encoded URL safe string.
- fetchTokenFromGoogleAPI() : array<string|int, mixed>
- Requests an access token from the Google API.
- generateJWT() : string
- Generates a JWT token that we need to request an access token.
Constants
CACHE_ACCESS_TOKEN_NAME
public
mixed
CACHE_ACCESS_TOKEN_NAME
= 'mve_fcm_php_token'
SCOPE_FIREBASE_MESSAGING
public
mixed
SCOPE_FIREBASE_MESSAGING
= 'https://www.googleapis.com/auth/firebase.messaging'
Properties
$cache
private
CacheInterface
$cache
$logger read-only
private
LoggerInterface|null
$logger
$serviceAccount
private
array<string|int, mixed>
$serviceAccount
Methods
__construct()
public
__construct(CacheInterface $cache, string $jsonFile, LoggerInterface|null $logger) : mixed
Parameters
- $cache : CacheInterface
-
A CacheInterface implementation, used to cache the access token.
- $jsonFile : string
-
The Google private key JSON file.
- $logger : LoggerInterface|null
-
An optional LoggerInterface implementation.
getProjectId()
Returns the project ID.
public
getProjectId() : string
Return values
stringgetToken()
Returns a non expired access token from the cache, or if there isn't one, from the Google API and stores this one in the cache.
public
getToken([bool $forceFromApi = false ]) : string
Parameters
- $forceFromApi : bool = false
-
If true, then it gets the access token from the Google API always, even there is still one in the cache.
Tags
Return values
string —A non expired access token that can be used to authenticate the API calls.
base64EncodeUrl()
Returns a base64 encoded URL safe string.
private
base64EncodeUrl(string $data) : string
Parameters
- $data : string
Return values
stringfetchTokenFromGoogleAPI()
Requests an access token from the Google API.
private
fetchTokenFromGoogleAPI() : array<string|int, mixed>
Tags
Return values
array<string|int, mixed> —Array of the response. Contains the 'access_token' and 'expires_in' fields.
generateJWT()
Generates a JWT token that we need to request an access token.
private
generateJWT() : string