@@ -46,13 +46,18 @@ import 'utils.dart';
4646/// // Explicitly generate a new access token
4747/// final token = await impersonated.generateAccessToken();
4848/// ```
49+ ///
50+ /// [baseClient] is an optional [http.Client] that will be used for
51+ /// the returned client's authenticated requests. If not provided, a new
52+ /// [http.Client] will be instantiated.
4953Future <ImpersonatedAuthClient > clientViaServiceAccountImpersonation ({
5054 required AuthClient sourceClient,
5155 required String targetServiceAccount,
5256 required List <String > targetScopes,
5357 List <String >? delegates,
5458 String universeDomain = defaultUniverseDomain,
5559 Duration lifetime = const Duration (hours: 1 ),
60+ http.Client ? baseClient,
5661}) async {
5762 final impersonatedClient = ImpersonatedAuthClient (
5863 sourceClient: sourceClient,
@@ -61,6 +66,7 @@ Future<ImpersonatedAuthClient> clientViaServiceAccountImpersonation({
6166 delegates: delegates,
6267 universeDomain: universeDomain,
6368 lifetime: lifetime,
69+ baseClient: baseClient,
6470 );
6571
6672 // Generate initial credentials
@@ -113,13 +119,18 @@ class ImpersonatedAuthClient extends AutoRefreshDelegatingClient {
113119 ///
114120 /// [lifetime] specifies how long the access token should be valid. Defaults
115121 /// to 3600 seconds (1 hour). Maximum is 43200 seconds (12 hours).
122+ ///
123+ /// [baseClient] is an optional [http.Client] that will be used for
124+ /// the returned client's authenticated requests. If not provided, a new
125+ /// [http.Client] will be instantiated.
116126 ImpersonatedAuthClient ({
117127 required AuthClient sourceClient,
118128 required this .targetServiceAccount,
119129 required List <String > targetScopes,
120130 List <String >? delegates,
121131 String universeDomain = defaultUniverseDomain,
122132 Duration lifetime = const Duration (hours: 1 ),
133+ http.Client ? baseClient,
123134 }) : _sourceClient = sourceClient,
124135 _targetScopes = List .unmodifiable (targetScopes),
125136 _delegates = delegates != null ? List .unmodifiable (delegates) : null ,
@@ -130,7 +141,10 @@ class ImpersonatedAuthClient extends AutoRefreshDelegatingClient {
130141 null ,
131142 targetScopes,
132143 ),
133- super (sourceClient, closeUnderlyingClient: false );
144+ super (
145+ baseClient ?? http.Client (),
146+ closeUnderlyingClient: baseClient == null ,
147+ );
134148
135149 @override
136150 AccessCredentials get credentials => _credentials;
0 commit comments