mirror of
https://github.com/sakaljurgis/actions-api.git
synced 2026-07-08 22:07:40 +00:00
26 lines
612 B
PHP
26 lines
612 B
PHP
<?php
|
|
|
|
namespace App\Services\Google;
|
|
|
|
use Google\Client;
|
|
|
|
class ApiAuthService
|
|
{
|
|
/**
|
|
* @throws \Google\Exception
|
|
*/
|
|
public function getAccessToken(): string
|
|
{
|
|
$client = new Client();
|
|
$serviceAccountKeyPath = env('GOOGLE_APPLICATION_CREDENTIALS');
|
|
$client->setAuthConfig($serviceAccountKeyPath);
|
|
$client->addScope('https://www.googleapis.com/auth/cloud-platform');
|
|
$client->fetchAccessTokenWithAssertion();
|
|
|
|
// todo - cache, refresh, etc
|
|
$accessToken = $client->getAccessToken();
|
|
|
|
return $accessToken['access_token'];
|
|
}
|
|
}
|