Home > Enterprise >  flutter: PlatformException(sign_in_failed, org.openid.appauth.oauth_token, invalid_audience: Audienc
flutter: PlatformException(sign_in_failed, org.openid.appauth.oauth_token, invalid_audience: Audienc

Time:06-02

I am trying to add google sign in (without firebase) to my flutter app.

I have created google cloud project, created oauth consent screen and credentials. I am using

  google_sign_in: ^5.3.2
  googleapis: ^9.0.0

Also i had to add

 <dict>
    <key>CFBundleTypeRole</key>
    <string>Editor</string>
    <key>CFBundleURLSchemes</key>
    <array>
        <string>com.googleusercontent.apps.618518636914-abc</string>
    </array>
</dict>

to allow ios to launch browser for google sign in, I am able to enter email and password, after that the app permission screen (This app wants to access your google drive... ) screen briefly appears and disappears, and i can see this error in terminal

   [VERBOSE-2:ui_dart_state.cc(209)] Unhandled Exception: PlatformException(sign_in_failed, org.openid.appauth.oauth_token, invalid_audience: Audience is not a valid client ID., null)
#0      StandardMethodCodec.decodeEnvelope (package:flutter/src/services/message_codecs.dart:607:7)
#1      MethodChannel._invokeMethod (package:flutter/src/services/platform_channel.dart:177:18)
<asynchronous suspension>
#2      MethodChannel.invokeMapMethod (package:flutter/src/services/platform_channel.dart:377:43)
<asynchronous suspension>
#3      GoogleSignIn._callMethod (package:google_sign_in/google_sign_in.dart:247:30)
<asynchronous suspension>
#4      GoogleSignIn.signIn.isCanceled (package:google_sign_in/google_sign_in.dart:377:5)
<asynchronous suspension>

This is the code used for login

class GoogleSignInApi {
  static final _googleSignIn = GoogleSignIn(
      hostedDomain: "",
      clientId:
          "618518636914-abd.apps.googleusercontent.com");

  static Future<GoogleSignInAccount?> login() => _googleSignIn.signIn();
}

i referred this post Google Api and android Oauth INVALID_AUDIENCE error, but my client id is correct and it's of type iOS client only (in google oauth credentials) and Google Sign in fails on iOS 13 GM this is for pure iOS project, it might be still relevant. But i am not able to figure out the version of iOS's AppAuth which is used by flutter's google_sign_in.

Any help will be highly appreciated, thank you.

CodePudding user response:

Please check the following steps

  1. Open xcode and select runner, then right click on the runner and select add files to runner. In the pop up window make sure that copy files is checked. Browse and select the Google services plist file.

  2. Make sure you added the reverse client id from GoogleServicesInfo.plist id in Info.plist

  3. Delete the existing app from device and install again.

  • Related