Skip to content

Commit b6c7734

Browse files
committed
Added the ability to do $cert->sub.
The constructor takes a new optional parameter called $userEmail and $cert->sub is assigned to that if it is set.
1 parent b12deeb commit b6c7734

File tree

1 file changed

+12
-9
lines changed

1 file changed

+12
-9
lines changed

src/Client.php

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,9 @@ class Client
1818

1919
/**
2020
* @param array $config
21+
* @param string $userEmail
2122
*/
22-
public function __construct(array $config)
23+
public function __construct(array $config, $userEmail='')
2324
{
2425
$this->config = $config;
2526

@@ -41,9 +42,7 @@ public function __construct(array $config)
4142
$this->client->setDeveloperKey(array_get($config, 'developer_key', ''));
4243

4344
// auth for service account
44-
if (array_get($config, 'service.enable', false)) {
45-
$this->auth();
46-
}
45+
$this->auth($userEmail);
4746
}
4847

4948
/**
@@ -81,12 +80,13 @@ public function make($service)
8180
/**
8281
* Setup correct auth method based on type.
8382
*
83+
* @param $userEmail
8484
* @return void
8585
*/
86-
protected function auth()
86+
protected function auth($userEmail='')
8787
{
8888
// see (and use) if user has set Credentials
89-
if ($this->useAssertCredentials()) {
89+
if ($this->useAssertCredentials($userEmail)) {
9090
return;
9191
}
9292

@@ -102,10 +102,10 @@ protected function auth()
102102

103103
/**
104104
* Determine and use credentials if user has set them.
105-
*
105+
* @param $userEmail
106106
* @return boolean used or not
107107
*/
108-
protected function useAssertCredentials()
108+
protected function useAssertCredentials($userEmail='')
109109
{
110110
$account = array_get($this->config, 'service.account', '');
111111
if (!empty($account)) {
@@ -114,6 +114,9 @@ protected function useAssertCredentials()
114114
array_get($this->config, 'service.scopes', []),
115115
file_get_contents(array_get($this->config, 'service.key', ''))
116116
);
117+
if($userEmail){
118+
$cert->sub=$userEmail;
119+
}
117120
$this->client->setAssertionCredentials($cert);
118121

119122
return true;
@@ -159,4 +162,4 @@ public function __call($method, $parameters)
159162

160163
throw new \BadMethodCallException(sprintf('Method [%s] does not exist.', $method));
161164
}
162-
}
165+
}

0 commit comments

Comments
 (0)