Skip to content

Commit 1a644f2

Browse files
committed
Merge pull request #8 from avanderbergh/master
Add the ability to assign $cert->sub
2 parents b12deeb + fd64c0f commit 1a644f2

File tree

1 file changed

+12
-7
lines changed

1 file changed

+12
-7
lines changed

src/Client.php

Lines changed: 12 additions & 7 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

@@ -42,7 +43,7 @@ public function __construct(array $config)
4243

4344
// auth for service account
4445
if (array_get($config, 'service.enable', false)) {
45-
$this->auth();
46+
$this->auth($userEmail);
4647
}
4748
}
4849

@@ -81,12 +82,13 @@ public function make($service)
8182
/**
8283
* Setup correct auth method based on type.
8384
*
85+
* @param $userEmail
8486
* @return void
8587
*/
86-
protected function auth()
88+
protected function auth($userEmail='')
8789
{
8890
// see (and use) if user has set Credentials
89-
if ($this->useAssertCredentials()) {
91+
if ($this->useAssertCredentials($userEmail)) {
9092
return;
9193
}
9294

@@ -102,10 +104,10 @@ protected function auth()
102104

103105
/**
104106
* Determine and use credentials if user has set them.
105-
*
107+
* @param $userEmail
106108
* @return boolean used or not
107109
*/
108-
protected function useAssertCredentials()
110+
protected function useAssertCredentials($userEmail='')
109111
{
110112
$account = array_get($this->config, 'service.account', '');
111113
if (!empty($account)) {
@@ -114,6 +116,9 @@ protected function useAssertCredentials()
114116
array_get($this->config, 'service.scopes', []),
115117
file_get_contents(array_get($this->config, 'service.key', ''))
116118
);
119+
if($userEmail){
120+
$cert->sub=$userEmail;
121+
}
117122
$this->client->setAssertionCredentials($cert);
118123

119124
return true;
@@ -159,4 +164,4 @@ public function __call($method, $parameters)
159164

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

0 commit comments

Comments
 (0)