@@ -18,8 +18,9 @@ class Client
18
18
19
19
/**
20
20
* @param array $config
21
+ * @param string $userEmail
21
22
*/
22
- public function __construct (array $ config )
23
+ public function __construct (array $ config, $ userEmail = '' )
23
24
{
24
25
$ this ->config = $ config ;
25
26
@@ -42,7 +43,7 @@ public function __construct(array $config)
42
43
43
44
// auth for service account
44
45
if (array_get ($ config , 'service.enable ' , false )) {
45
- $ this ->auth ();
46
+ $ this ->auth ($ userEmail );
46
47
}
47
48
}
48
49
@@ -81,12 +82,13 @@ public function make($service)
81
82
/**
82
83
* Setup correct auth method based on type.
83
84
*
85
+ * @param $userEmail
84
86
* @return void
85
87
*/
86
- protected function auth ()
88
+ protected function auth ($ userEmail = '' )
87
89
{
88
90
// see (and use) if user has set Credentials
89
- if ($ this ->useAssertCredentials ()) {
91
+ if ($ this ->useAssertCredentials ($ userEmail )) {
90
92
return ;
91
93
}
92
94
@@ -102,10 +104,10 @@ protected function auth()
102
104
103
105
/**
104
106
* Determine and use credentials if user has set them.
105
- *
107
+ * @param $userEmail
106
108
* @return boolean used or not
107
109
*/
108
- protected function useAssertCredentials ()
110
+ protected function useAssertCredentials ($ userEmail = '' )
109
111
{
110
112
$ account = array_get ($ this ->config , 'service.account ' , '' );
111
113
if (!empty ($ account )) {
@@ -114,6 +116,9 @@ protected function useAssertCredentials()
114
116
array_get ($ this ->config , 'service.scopes ' , []),
115
117
file_get_contents (array_get ($ this ->config , 'service.key ' , '' ))
116
118
);
119
+ if ($ userEmail ){
120
+ $ cert ->sub =$ userEmail ;
121
+ }
117
122
$ this ->client ->setAssertionCredentials ($ cert );
118
123
119
124
return true ;
@@ -159,4 +164,4 @@ public function __call($method, $parameters)
159
164
160
165
throw new \BadMethodCallException (sprintf ('Method [%s] does not exist. ' , $ method ));
161
166
}
162
- }
167
+ }
0 commit comments