authenticatedClient method

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? oauthTokenString = auth?.accessToken;
  if (oauthTokenString == null) {
    return null;
  }
  final gapis.AccessCredentials credentials = gapis.AccessCredentials(
    gapis.AccessToken(
      'Bearer',
      oauthTokenString,
      // TODO(kevmoo): Use the correct value once it's available from authentication
      // See https://github.com/flutter/flutter/issues/80905
      DateTime.now().toUtc().add(const Duration(days: 365)),
    ),
    null, // We don't have a refreshToken
    debugScopes ?? scopes,
  );

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