authenticatedClient method Null safety

Future<AuthClient?> authenticatedClient(
  1. {@visibleForTesting GoogleSignInAuthentication? debugAuthentication,
  2. @visibleForTesting List<String>? debugScopes}
)

Retrieve a googleapis authenticated client.

Implementation

Future<gapis.AuthClient?> authenticatedClient({
  @visibleForTesting GoogleSignInAuthentication? debugAuthentication,
  @visibleForTesting List<String>? debugScopes,
}) async {
  final GoogleSignInAuthentication? auth =
      debugAuthentication ?? await currentUser?.authentication;
  final String? oathTokenString = auth?.accessToken;
  if (oathTokenString == null) {
    return null;
  }
  final gapis.AccessCredentials credentials = gapis.AccessCredentials(
    gapis.AccessToken(
      'Bearer',
      oathTokenString,
      // We don't know when the token expires, so we assume "never"
      DateTime.now().toUtc().add(const Duration(days: 365)),
    ),
    null, // We don't have a refreshToken
    debugScopes ?? scopes,
  );

  return gapis.authenticatedClient(http.Client(), credentials);
}