1. Anuncie Aqui ! Entre em contato fdantas@4each.com.br

[Flutter] iOS requestScopes in google_sign_in package returns false even with granted...

Discussão em 'Mobile' iniciado por Stack, Outubro 25, 2024 às 17:52.

  1. Stack

    Stack Membro Participativo

    Issue Summary


    I'm facing an issue with the google_sign_in Flutter package when requesting additional scopes for Google Calendar access specifically on iOS. The standard Google Sign-In process works without issues. However, calling requestScopes to gain calendar access always returns false on iOS, even though permissions are granted. On Android, requestScopes works as expected, returning true after the user grants access.

    Environment

    • Platform: iOS
    • Flutter Version: 3.24.3
    • google_sign_in Package Version: 6.2.1
    • Device Tested: Multiple iOS devices and simulators (IOS 18)
    Steps to Reproduce

    1. Set up Firebase Authentication and Google Calendar API:
    • Firebase Authentication and Google Sign-In are configured in the Firebase Console.
    • Google Calendar API is enabled in Google Cloud Console.
    1. Create OAuth Credentials:
    • OAuth 2.0 credentials were generated for both Android and iOS within the Google Cloud Console.
    • For iOS, the REVERSED_CLIENT_ID is correctly set up in the app’s Info.plist.
    1. Sign In and Request Scopes:
    • After signing in with Google, calling requestScopes for calendar access prompts a permissions request. Even after granting permission, the method still returns false.

    static const _scopes = [
    CalendarApi.calendarReadonlyScope,
    CalendarApi.calendarEventsReadonlyScope,
    ];

    final isAuthorized = await _googleSignIn.requestScopes(_scopes);
    print(isAuthorized); // Returns false even after granting permission

    1. Expected Behavior:
    • requestScopes should return true upon successful granting of permissions, as it does on Android.
    1. Observed Behavior:
    • requestScopes always returns false on iOS, despite receiving an email from Google indicating that access was granted.
    What I’ve Tried

    1. Checked Google Cloud Console Configuration:
    • Verified that OAuth credentials were correctly set up for iOS and linked to Firebase.
    • Confirmed that Google Calendar API and Google Sign-In are enabled.
    • Ensured the user type is set to External and In Production status.
    1. Directly Requested Scopes via Access Token:
    • Attempted to bypass requestScopes by retrieving the accessToken directly after sign-in and manually accessing Google Calendar API. This approach works, but it bypasses Flutter’s requestScopes functionality.

    final GoogleSignInAccount? account = await _googleSignIn.signIn();
    final GoogleSignInAuthentication auth = await account!.authentication;

    final accessToken = auth.accessToken;

    // Manual API call using accessToken
    final response = await http.get(
    Uri.parse('https://www.googleapis.com/calendar/v3/users/me/calendarList'),
    headers: {
    'Authorization': 'Bearer $accessToken',
    },
    );

    if (response.statusCode == 200) {
    // Success
    }

    Request for Help


    This issue appears specific to iOS with google_sign_in. Any guidance on:

    • Why requestScopes always returns false on iOS, despite permissions being granted.
    • Possible workarounds or insights into the cause of this behavior.

    Continue reading...

Compartilhe esta Página