Skip to content

Commit

Permalink
Added support for service authentication with API client v2
Browse files Browse the repository at this point in the history
  • Loading branch information
aschempp committed Aug 4, 2016
1 parent fc8acb2 commit 0862e7e
Showing 1 changed file with 21 additions and 7 deletions.
28 changes: 21 additions & 7 deletions Services/GoogleClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,27 @@ public function __construct(array $config, LoggerInterface $symfonyLogger = null

case 'service':
$client->setAccessType('offline');
$client->setAssertionCredentials(
new \Google_Auth_AssertionCredentials(
$config['oauth2_client_email'],
$config['oauth2_scopes'],
$config['oauth2_private_key']
)
);

if (class_exists('\Google_Auth_AssertionCredentials')) {
//BC for Google API 1.0
$client->setAssertionCredentials(
new \Google_Auth_AssertionCredentials(
$config['oauth2_client_email'],
$config['oauth2_scopes'],
$config['oauth2_private_key']
)
);
} else {
$client->setScopes($config['oauth2_scopes']);
$client->setAuthConfig(
array(
'type' => 'service_account',
'client_id' => $config['oauth2_client_id'],
'client_email' => $config['oauth2_client_email'],
'private_key' => $config['oauth2_private_key'],
)
);
}
break;
}

Expand Down

0 comments on commit 0862e7e

Please sign in to comment.