0

I'm following through this link: https://developers.google.com/identity/protocols/oauth2/service-account#httprest_1 in order to have my flutter app log to a log bucket in a google cloud project. Currently getting a

{
  "error": "invalid_client",
  "error_description": "The OAuth client was not found."
}

when I run the code below to get the access token in dart:

  var jsonFile =
      await File(jsonPath).readAsString();
  var map = jsonDecode(jsonFile);

  final jwt = JWT(
    {
      'iss': map['client_email'],
      'sub': map['client_email'],
      'aud': map['token_uri'],
      'iat': (DateTime.now().millisecondsSinceEpoch / 1000).floor(),
      'exp':
          (DateTime.now().add(Duration(hours: 1)).millisecondsSinceEpoch / 1000)
              .floor(),
    },
    issuer: map['private_key_id'],
  );

  final token = jwt.sign(SecretKey(map['private_key']));

  print(token);

  final accessToken = await http.post(
    Uri.parse(map['token_uri']),
    headers: {
      HttpHeaders.contentTypeHeader: 'application/x-www-form-urlencoded',
    },
    body: {
      'grant_type': 'urn:ietf:params:oauth:grant-type:jwt-bearer',
      'assertion': token,
    },
  );

The JSON file is the credentials of a service account with logging admin role in the GCP project.

neil_ruaro
  • 368
  • 3
  • 15

1 Answers1

0

Invalid client means that the client id or the client secret that you are using are not valid.

As per the official documentation,

When attempting to get an access or refresh token, you will get an "Invalid client" error if you provide an incorrect OAuth 2.0 Client Secret. Make sure the client_secret value you're using in access and refresh token calls is the one for the OAuth 2.0 Client ID being used, as found in your GCP Credentials page.

Also refer to this SO link Github link for more information.

Fariya Rahmat
  • 2,123
  • 3
  • 11