Skip to content
This repository has been archived by the owner on Feb 22, 2023. It is now read-only.

[google_sign_in] Fix Server Authorization code on android #2792

Conversation

zeeshanhussain
Copy link

@zeeshanhussain zeeshanhussain commented May 22, 2020

Description

The serverAuthCode on an android device was coming null. This pull request resolves that issue.

Related Issues

flutter/flutter#57712
flutter/flutter#57741

Checklist

Before you create this PR confirm that it meets all requirements listed below by checking the relevant checkboxes ([x]). This will ensure a smooth and quick review process.

  • I read the Contributor Guide and followed the process outlined there for submitting PRs.
  • My PR includes unit or integration tests for all changed/updated/fixed behaviors (See Contributor Guide).
  • All existing and new tests are passing.
  • I updated/added relevant documentation (doc comments with ///).
  • The analyzer (flutter analyze) does not report any problems on my PR.
  • I read and followed the Flutter Style Guide.
  • The title of the PR starts with the name of the plugin surrounded by square brackets, e.g. [shared_preferences]
  • I updated pubspec.yaml with an appropriate new version according to the pub versioning philosophy.
  • I updated CHANGELOG.md to add a description of the change.
  • I signed the CLA.
  • I am willing to follow-up on review comments in a timely manner.

Breaking Change

Does your PR require plugin users to manually update their apps to accommodate your change?

  • Yes, this is a breaking change (please indicate a breaking change in CHANGELOG.md and increment major revision).
  • No, this is not a breaking change.

@googlebot
Copy link

Thanks for your pull request. It looks like this may be your first contribution to a Google open source project (if not, look below for help). Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

📝 Please visit https://cla.developers.google.com/ to sign.

Once you've signed (or fixed any issues), please reply here with @googlebot I signed it! and we'll verify it.


What to do if you already signed the CLA

Individual signers
Corporate signers

ℹ️ Googlers: Go here for more info.

@zeeshanhussain
Copy link
Author

@googlebot I signed it!

@googlebot
Copy link

CLAs look good, thanks!

ℹ️ Googlers: Go here for more info.

@abhishek199-dhn
Copy link

abhishek199-dhn commented Jun 3, 2020

I need this fix to get the serverAuthCode such that I can get a refresh token at the backend side to use google API. Currently, it returns serverAuthCode as null
By when we can expect this to be merged?

@zeeshanhussain zeeshanhussain changed the title Fix Server Authorization code on android [google_sign_in] Fix Server Authorization code on android Jun 3, 2020
@zeeshanhussain
Copy link
Author

Please review @cyanglaz @mehmetf

@abhishek199-dhn
Copy link

abhishek199-dhn commented Jun 3, 2020

@zeeshanhussain I tried cloning your branch and gave it a shot. But it's not working for me.

dependencies:
  google_sign_in:
    path: ../plugins/packages/google_sign_in/google_sign_in
Launching lib/main.dart on sdk gphone x86 arm in debug mode...
Running Gradle task 'assembleDebug'...

Compiler message:
../plugins/packages/google_sign_in/google_sign_in/lib/google_sign_in.dart:48:32: Error: The getter 'serverAuthCode' isn't defined for the class 'GoogleSignInUserData'.
 - 'GoogleSignInUserData' is from 'package:google_sign_in_platform_interface/src/types.dart' ('../../../../lib/flutter/.pub-cache/hosted/pub.dartlang.org/google_sign_in_platform_interface-1.1.2/lib/src/types.dart').
Try correcting the name to the name of an existing getter, or defining a getter or field named 'serverAuthCode'.
        _serverAuthCode = data.serverAuthCode {
                               ^^^^^^^^^^^^^^

Compiler message:
../plugins/packages/google_sign_in/google_sign_in/lib/google_sign_in.dart:48:32: Error: The getter 'serverAuthCode' isn't defined for the class 'GoogleSignInUserData'.
 - 'GoogleSignInUserData' is from 'package:google_sign_in_platform_interface/src/types.dart' ('../../../../lib/flutter/.pub-cache/hosted/pub.dartlang.org/google_sign_in_platform_interface-1.1.2/lib/src/types.dart').
Try correcting the name to the name of an existing getter, or defining a getter or field named 'serverAuthCode'.
        _serverAuthCode = data.serverAuthCode {
                               ^^^^^^^^^^^^^^
Target kernel_snapshot failed: Exception: Errors during snapshot creation: null
build failed.

FAILURE: Build failed with an exception.

I can see the exact same error message in some git checks

@zeeshanhussain
Copy link
Author

zeeshanhussain commented Jun 3, 2020

@abhishek199-dhn There are some changes in google_sign_in_platform_interface as well so you have to clone that locally as well and that's why it was failing few checks.

@abhishek199-dhn
Copy link

abhishek199-dhn commented Jun 3, 2020

@zeeshanhussain which changes you are referring to? can you please give me the link of the PR?

@zeeshanhussain
Copy link
Author

@abhishek199-dhn it's in the same pr, this pr has changes in both google_sign_in and google_sign_in_platform_interface. I should probably split it into 2 pr after getting this reviewed.

@abhishek199-dhn
Copy link

Thanks @zeeshanhussain, it woking now. I pointed both the dependencies google_sign_in_platform_interface and google_sign_in_web of google_sign_in to local package.

@scaraux
Copy link

scaraux commented Jun 16, 2020

@zeeshanhussain I pulled your branch and pointed google_sign_in_platform_interface as well. Still getting null as server code. Any idea ?

@zeeshanhussain
Copy link
Author

Thanks @zeeshanhussain, it woking now. I pointed both the dependencies google_sign_in_platform_interface and google_sign_in_web of google_sign_in to local package.

Can you show us how you defined this in your pubspec.yaml?

you can copy all the 3 packages in your project folder which includes [google_sign_in], [google_sign_in_platform_interface] , [google_sign_in_web].

In your project's pubspec.yaml you can add the [google_sign_in] dependency.

  google_sign_in:
    path: ./google_sign_in

In google_sign_in/pubspec.yaml you can add both [google_sign_in_web] and [google_sign_in_platform_interface].

  google_sign_in_platform_interface:
    path: ../google_sign_in_platform_interface/
  google_sign_in_web:
    path: ../google_sign_in_web

in google_sign_in_web/pubspec.yaml you can add [google_sign_in_platform_interface]

  google_sign_in_platform_interface:
    path: ../google_sign_in_platform_interface/

@zeeshanhussain
Copy link
Author

zeeshanhussain commented Jun 16, 2020

@zeeshanhussain I pulled your branch and pointed google_sign_in_platform_interface as well. Still getting null as server code. Any idea ?

@scaraux go to firebase/authentication/sign in methods/google
in google sign in go to the web client and update client id and client secret. Download the updated google-services.json file and you are good to go.

@scaraux
Copy link

scaraux commented Jun 16, 2020

@zeeshanhussain I pulled your branch and pointed google_sign_in_platform_interface as well. Still getting null as server code. Any idea ?

@scaraux go to firebase/authentication/sign in methods/google
in google sign in go to the web client and update client id and client secret. Download the updated google-services.json file and you are good to go.

Yes I created a new clientId this morning, added it to the whitelist clientIds sections and downloaded the google-services.json. Still no server auth code though :/

@zeeshanhussain
Copy link
Author

zeeshanhussain commented Jun 16, 2020

@zeeshanhussain I pulled your branch and pointed google_sign_in_platform_interface as well. Still getting null as server code. Any idea ?

@scaraux go to firebase/authentication/sign in methods/google
in google sign in go to the web client and update client id and client secret. Download the updated google-services.json file and you are good to go.

Yes I created a new clientId this morning, added it to the whitelist clientIds sections and downloaded the google-services.json. Still no server auth code though :/

@scaraux you have to add web client id and web client secret in Web SDK configuration, then use the updated google-services.json.
I think the process of adding client id in firebase needs to be documented somewhere.

@scaraux
Copy link

scaraux commented Jun 16, 2020

@zeeshanhussain I pulled your branch and pointed google_sign_in_platform_interface as well. Still getting null as server code. Any idea ?

@scaraux go to firebase/authentication/sign in methods/google
in google sign in go to the web client and update client id and client secret. Download the updated google-services.json file and you are good to go.

Yes I created a new clientId this morning, added it to the whitelist clientIds sections and downloaded the google-services.json. Still no server auth code though :/

@scaraux you have to add web client id and web client secret in Web SDK configuration, then use the updated google-services.json.
I think the process of adding client id in firebase needs to be documented somewhere.

I can give it a try, I know how to access my "OAuth 2.0 Client IDs" from the https://console.developers.google.com/. But which clientId should I copy ?

@zeeshanhussain
Copy link
Author

@zeeshanhussain I pulled your branch and pointed google_sign_in_platform_interface as well. Still getting null as server code. Any idea ?

@scaraux go to firebase/authentication/sign in methods/google
in google sign in go to the web client and update client id and client secret. Download the updated google-services.json file and you are good to go.

Yes I created a new clientId this morning, added it to the whitelist clientIds sections and downloaded the google-services.json. Still no server auth code though :/

@scaraux you have to add web client id and web client secret in Web SDK configuration, then use the updated google-services.json.
I think the process of adding client id in firebase needs to be documented somewhere.

I can give it a try, I know how to access my "OAuth 2.0 Client IDs" from the https://console.developers.google.com/. But which clientId should I copy ?

You should use the one which you want to use in your application. Give it a try and it will definitely work.

@scaraux
Copy link

scaraux commented Jun 17, 2020

@zeeshanhussain I pulled your branch and pointed google_sign_in_platform_interface as well. Still getting null as server code. Any idea ?

@scaraux go to firebase/authentication/sign in methods/google
in google sign in go to the web client and update client id and client secret. Download the updated google-services.json file and you are good to go.

Yes I created a new clientId this morning, added it to the whitelist clientIds sections and downloaded the google-services.json. Still no server auth code though :/

@scaraux you have to add web client id and web client secret in Web SDK configuration, then use the updated google-services.json.
I think the process of adding client id in firebase needs to be documented somewhere.

I can give it a try, I know how to access my "OAuth 2.0 Client IDs" from the https://console.developers.google.com/. But which clientId should I copy ?

You should use the one which you want to use in your application. Give it a try and it will definitely work.

All good now, thank you so much.

@scaraux
Copy link

scaraux commented Jul 8, 2020

@zeeshanhussain any idea when this will be merged ?

@zeeshanhussain
Copy link
Author

@zeeshanhussain any idea when this will be merged ?

No idea, it has to be reviewed first. you can tag one of the developers for a faster response.

@scaraux
Copy link

scaraux commented Aug 5, 2020

@zeeshanhussain any idea when this will be merged ?

No idea, it has to be reviewed first. you can tag one of the developers for a faster response.

I have no idea who I can tag 😟
We need your PR merged for production, let me know if there's anything I can do

@HaitianZhuu
Copy link

For anyone look into this issue and this PR:

  1. Download this branch and move google_sign_in, google_sign_in_platform_interface and google_sign_in_web under your project.
  2. Edit the local dependency as author said
  3. If the serverAuthCode is still null, you need to know your client id. Refer to this discussion,
    you can whether download google-services.json, edit root gradle and app gradle.(I didnt try this way, but I think it will work).
    I just add
    <string name="default_web_client_id">YOUR_WEB_CLIENT_ID</string>
    in android/app/../Strings.xml. Then it works.

@stuartmorgan
Copy link
Contributor

Thanks for the submission! We’re currently working through a large backlog of PRs, and this will require non-trivial review, so it will take some time before we’re able to review it. As explained in CONTRIBUTING.md, votes for the corresponding issue are the primary way we’re prioritizing non-trivial reviews, so we encourage anyone interested in this PR to vote for the corresponding issue.

@stuartmorgan
Copy link
Contributor

Note that per Flutter policy, this will need tests before it can move forward. (You've checked the box indicating that you've added tests, but I'm not seeing them; if you did write tests already please ensure that part of the PR is pushed.)

@zeeshanhussain
Copy link
Author

zeeshanhussain commented Apr 20, 2021

@stuartmorgan the previous pr added few tests. 88e85c6

Let me know if you need more tests.

@stuartmorgan
Copy link
Contributor

@stuartmorgan the previous pr added few tests. 88e85c6

Let me know if you need more tests.

The tests in that PR are passing, so clearly aren't testing the issue that this PR is intended to address.

@sahilmehra98
Copy link

sahilmehra98 commented Oct 15, 2021

@zeeshanhussain @stuartmorgan Any update on this? I used the workaround to use local copy of this branch but these 3 packages have not been migrated to null safety. Hence, this didnot work for me. Any idea when this branch will be migrated to null safety or when this issue will be fixed?

@stuartmorgan
Copy link
Contributor

Closing as obsoleted by #4180. Thanks again for the submission!

@jainkrati
Copy link

Thanks for the fix. Somehow I am still getting null serverAuthCode. Is this change already pushed in latest published package for google_sign_in?

Also, are you aware of any ongoing or past fix for ios for this scenario? I am integrating google sign in for my app and need both these fixes. Will appreciate any help :)

cc @zeeshanhussain @stuartmorgan

@sahilmehra98
Copy link

@jainkrati I am also facing the issue of null serverAuthCode for ios. For android, it is working fine. @zeeshanhussain @stuartmorgan Please suggest some fixes.

@stuartmorgan
Copy link
Contributor

Please report issues via the issue tracker; PRs are not an issue tracking system.

@stuartmorgan stuartmorgan reopened this Nov 26, 2021
@flutter-dashboard
Copy link

It looks like this pull request may not have tests. Please make sure to add tests before merging. If you need an exemption to this rule, contact Hixie on the #hackers channel in Chat.

If you are not sure if you need tests, consider this rule of thumb: the purpose of a test is to make sure someone doesn't accidentally revert the fix. Ask yourself, is there anything in your PR that you feel it is important we not accidentally revert back to how it was before your fix?

Reviewers: Read the Tree Hygiene page and make sure this patch meets those guidelines before LGTMing.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

9 participants