Flutter App: cannot login with Google because the app does not match security policies OAuth 2.0

Viewed 231

i am developing a android app with Flutter but, when i try to log in with google to retrieve all events from Google Calendar, the app deploys an error 400: invalid_request. What can i do to my app match security policies (OAuth 2.0)?

Check the link with error printscreen.

Future<void> main() async {
  WidgetsFlutterBinding.ensureInitialized();
  await Firebase.initializeApp(
    options: DefaultFirebaseOptions.currentPlatform,
  );

  var _clientID = ClientId(Secret.getId(), "");
  const _scopes = [gCalendar.CalendarApi.calendarScope];
  AuthClient c = await clientViaUserConsent(_clientID, _scopes, prompt);
  signInWithGoogle(c);
  await FirebaseAuth.instance.signInAnonymously();
  runApp(const MyApp());
}

void prompt(String urla) async {
  Uri url = Uri.parse(urla);
  if (await launchUrl(url)) {
    print(
        "FUNFAOIFNOAIFNAPOIFNMAPEOFEAPIOFNPAEOIFJAPEIOFPEOJFPOAFJAPEOFJAPEOFJAPEOFJAOEIJFNP OIWNFR WIOAN COPIWAHNFKAWHFIWAJFHK");
  } else {
    print('XXXXXXXXCould not launch $url');
  }
}

final GoogleSignIn _googleSignIn = GoogleSignIn(
  scopes: <String>[
    gCalendar.CalendarApi.calendarScope,
  ],
);

signInWithGoogle(AuthClient c) async {
  await _googleSignIn.signIn();
  final headers = await _googleSignIn.currentUser.authHeaders;
  getEvent(headers, connectedVmServiceUri);
}

getEvent(headers, c) async {
  var calendar = gCalendar.CalendarApi(c);
  DateTime lastMonth = DateTime.utc(2022, 6, 1);
  DateTime firstMonth = DateTime.utc(2122, 6, 1);
  var calEvents =
      calendar.events.list("primary", timeMax: lastMonth, timeMin: firstMonth);
  calEvents.then((events) =>
      {events.items!.forEach((event) => print("EVENT: ${event.summary}"))});
}

Error printscreen

1 Answers

What works for me is there are multiple OAuth 2.0 Client IDs in the google console account I use the Android key for IOS and Android. It works pretty fine for me.

Related