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

Access token is missing on Android when Google Play Service SDK version is 11.0.0 #398

Open
adriano-di-giovanni opened this issue Jun 13, 2017 · 46 comments

Comments

@adriano-di-giovanni
Copy link
Contributor

accessToken field is not returned on Android when Google Play Services SDK version is 11.0.0.

As a workaround, I forked the repo and changed framework version to 10+.

I'm going to investigate in a while.

@bondzi
Copy link

bondzi commented Jun 14, 2017

Did you succeed with downgrading version to 10+? It still won't work for me, even if the version is 10.+ (10.2.6 to be exact)

@adriano-di-giovanni
Copy link
Contributor Author

Yes, I did.

@bondzi
Copy link

bondzi commented Jun 14, 2017

Please can you specify the setup you have? I still cannot get accessToken...

@adriano-di-giovanni
Copy link
Contributor Author

Did you try a clean Cordova app?

@Ross-Rawlins
Copy link

is this live?

@bondzi
Copy link

bondzi commented Jun 15, 2017

I managed to get the token by downgrading to 10.+ and then reinstalling the platform. Thanks

@Ross-Rawlins
Copy link

this breaks my build with:
Execution failed for task ':transformClassesWithDexForDebug'.

com.android.build.api.transform.TransformException: com.android.ide.common.process.ProcessException: java.util.concurrent.ExecutionException: com.android.dex.DexException: Multiple dex files define Lcom/google/android/gms/auth/api/signin/internal/zzm;

@Nightbr
Copy link

Nightbr commented Jun 15, 2017

Same here, I'm using @bondzi fork so far

@bondzi
Copy link

bondzi commented Jun 15, 2017

Check the xml files for the plugins you use and make sure the dependencies are with the same mayor version (ex. 10.+ for Google Play Services). That may cause the issue with multidex

@dpa99c
Copy link

dpa99c commented Jun 16, 2017

@Ross-Rawlins If you're still encountering that error, I've just created a plugin which contains a Gradle workaround for plugins containing conflicting versions of the Play Services library: cordova-android-play-services-gradle-release. Should hopefully fix your problem.

@madding
Copy link

madding commented Jul 13, 2017

I have same problem: accessToken not returned. Library: cordova-android-play-services-gradle-release not help me. Are there any other solutions for this bug ?

@adriano-di-giovanni
Copy link
Contributor Author

adriano-di-giovanni commented Jul 13, 2017 via email

@dpa99c
Copy link

dpa99c commented Jul 13, 2017

Or cordova plugin add https://github.com/dpa99c/cordova-android-play-services-gradle-release#v10 which does the same thing

@madding
Copy link

madding commented Jul 13, 2017

I forked repo, changed version and it is working now. Plugin cordova-android-play-services-gradle-release don't work for me.

Thank for help !

@Sampath-Lokuge
Copy link

Sampath-Lokuge commented Jul 20, 2017

@adriano-di-giovanni Can you tell me which file you have changed and after changing it how did you use it with the Ionic app? I have used npm with this plugin.

@madding
Copy link

madding commented Jul 20, 2017

This

master...adriano-di-giovanni:master

@Sampath-Lokuge
Copy link

@madding Thanks.After that change how can I use it with the Ionic app.Because I normally use npm.

@madding
Copy link

madding commented Jul 20, 2017

I installed as
cordova plugin add https://github.com/.../cordova-plugin-googleplus --save

after in my package.json i found this
"cordova-plugin-googleplus": "git+https://github.com/.../cordova-plugin-googleplus.git",

mb it help u

@Sampath-Lokuge
Copy link

@madding Sorry I didn't get you.Above urls show 404 error.Please see that and correct it.Thanks.

@Sampath-Lokuge
Copy link

@madding We can do this originally cordova plugin add https://github.com/EddyVerbruggen/cordova-plugin-googleplus --save --variable REVERSED_CLIENT_ID=myreversedclientid.But how can I do that after changing it on my local machine?

@madding
Copy link

madding commented Jul 20, 2017

I hide my fork there :)

@madding
Copy link

madding commented Jul 20, 2017

U can do new fork or use this fork https://github.com/EddyVerbruggen/cordova-plugin-googleplus too. I do new fork for me.

@Nightbr
Copy link

Nightbr commented Jul 20, 2017

100% agree with @dpa99c and we use this in our app (in production):

cordova plugin add https://github.com/dpa99c/cordova-android-play-services-gradle-release#v10

or in package.json

"cordovaPlugins": [
    {
      "locator": "https://github.com/dpa99c/cordova-android-play-services-gradle-release#v10",
      "id": "cordova-android-play-services-gradle-release"
    },
]

@Sampath-Lokuge
Copy link

@Nightbr Are you using Ionic 2 or 3 app?

@Nightbr
Copy link

Nightbr commented Jul 20, 2017

@Sampath-Lokuge ionic 1.3 but ionic version doesn't matter here. It's plugin related so it's cordova matter.

to handle the cordovaPlugins into my package.json, I created an hook which will execute cordova plugin add command on all entries under cordovaPlugins.

010_install_plugins.js

#!/usr/bin/env node

/**
 * Install all plugins listed in package.json
/after_platform_add/install_plugins.js
 */
var exec = require('child_process').exec;
var path = require('path');
var sys = require('sys');

var packageJSON = null;

try {
  packageJSON = require('../../package.json');
} catch(ex) {
  console.log('\nThere was an error fetching your package.json file.')
  console.log('\nPlease ensure a valid package.json is in the root of this project\n')
  return;
}

var cmd = process.platform === 'win32' ? 'cordova.cmd' : 'cordova';
// var script = path.resolve(__dirname, '../../node_modules/cordova/bin', cmd);

packageJSON.cordovaPlugins = packageJSON.cordovaPlugins || [];
packageJSON.cordovaPlugins.forEach(function (plugin) {

    if(typeof plugin === 'string') {
        exec('cordova plugin add ' + plugin, function (error, stdout, stderr) {
          sys.puts(stdout);
        });
    } else {
        var pluginCmd = 'cordova plugin add ' ;
        pluginCmd += plugin.locator + ' ';
        if(plugin.variables) {
            Object.keys(plugin.variables).forEach(function(variable){
                pluginCmd += '--variable ' + variable + '="' + plugin.variables[variable] + '" ';
            });
            console.log(pluginCmd)
        }
        exec(pluginCmd, function (error, stdout, stderr) {
          sys.puts(stdout);
        });
        }
});

@Sampath-Lokuge
Copy link

@madding You have pointed me the same this repo no? Can you please put that url inside the code block.

@madding
Copy link

madding commented Jul 20, 2017

   cordova plugin add https://github.com/EddyVerbruggen/cordova-plugin-googleplus --save
   "cordova-plugin-googleplus": "git+https://github.com/EddyVerbruggen/cordova-plugin-googleplus.git",

@Sampath-Lokuge
Copy link

@madding If we use this cordova plugin add https://github.com/EddyVerbruggen/cordova-plugin-googleplus --save then it'll install same current plugin no (with no accsesToken)? How to install modified one(forked) which you have mentioned?

@madding
Copy link

madding commented Jul 20, 2017

sorry my mistake:

cordova plugin add https://github.com/adriano-di-giovanni/cordova-plugin-googleplus --save --variable REVERSED_CLIENT_ID=your_reserved_id

"cordova-plugin-googleplus": "git+https://github.com/adriano-di-giovanni/cordova-plugin-googleplus",

@Sampath-Lokuge
Copy link

Sampath-Lokuge commented Jul 20, 2017

@madding I have installed it correctly.But now it shows build error as shown below.Can you tell me what to do then?

The solution for the below error: stackoverflow

Checking the license for package SDK Patch Applier v4 in C:\Program Files (x86)\Android\android-sdk\licenses
Warning: License for package SDK Patch Applier v4 not accepted.
Checking the license for package Google Repository in C:\Program Files (x86)\Android\android-sdk\licenses
Warning: License for package Google Repository not accepted.

BUILD FAILED

* What went wrong:
A problem occurred configuring root project 'android'.
> You have not accepted the license agreements of the following SDK components:
[SDK Patch Applier v4, Google Repository].
Before building your project, you need to accept the license agreements and complete the installation of the missing components using the Android Studio SDK Manager.

Alternatively, to learn how to transfer the license agreements from one workstation to another, go to http://d.android.com/r/studio-ui/export-licenses.html

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.


[ERROR] Cordova encountered an error.
        You may get more insight by running the Cordova command above directly.

[ERROR] An error occurred while running cordova run android --device (exit code 1).

@Sampath-Lokuge
Copy link

@madding It is working.Thank you so much for your continuous support.One question though.Can you tell me what kind of side effects will happen to my app due to this change?

@madding
Copy link

madding commented Jul 20, 2017

I did not see any

@Sampath-Lokuge
Copy link

@madding Will above fork update with the latest changes and bug fixes from the main branch or with parent repo?

@madding
Copy link

madding commented Jul 21, 2017

For now fork has only one difference with main repo, hopefully the bug will be fixed soon and we can install original gem

@Sampath-Lokuge
Copy link

@madding Yes, You're right.Thanks a lot :)

@Spillo17
Copy link

Spillo17 commented Jul 28, 2017

I guys, someone can explain me why on iOs I receive "accessToken" but on Android not ?
How can request "accessToken" also in Android ? (at the moment on android I receive the "idToken" and "serverAuthCode" )

and is only in debug, I don't have play services

thanks a lot

@alesgenova
Copy link

Using @adriano-di-giovanni repo I am able to receive again the "accessToken".
However, it breaks building the app when the AdMobPro (or free) plugin is added as well.
Is anyone aware of a solution?

@alesgenova
Copy link

So I did some reading, and it looks like Google is phasing out the accessToken for Android clients, and it might get pulled from iOS clients as well in the future.
They suggest you use the idToken instead, which is basically a JWT token that you can validate server side against Google's public keys.
I didn't want to bother with it, and instead decided to use the serverAuthCode to authenticate the user on the server side. The serverAuthCode is the equivalent of the OAuth2 "code" and I already had the infrastructure in place to use it.
If using the ionic-native plugin, in order to get the serverAuthCode you have to specify in the login options your app's "webClientID" and offline:true
With this setup I'm able to switch back to the main cordova-plugin-googleplus repository, to log in with Google both in the client and the backend, and my build doesn't break anymore when using AdMobFree / AdMobPro

@MrHOY
Copy link

MrHOY commented Sep 1, 2017

Now, the orginal still not fix issue, no accessToken return

@Spillo17
Copy link

Spillo17 commented Sep 1, 2017

I just change the class GooglePlus.java using this https://gist.github.com/gylippus/84b85af586c6e12b034c987e8d0f564c and it works!
I hope can help you!

@MrHOY
Copy link

MrHOY commented Sep 1, 2017

@Spillo17
Which one you change ? inside node_module or plugins, or both ?

@Spillo17
Copy link

Spillo17 commented Sep 1, 2017

@MrHOY sorry I don't specify, I change on the Android platform (I've used Android Studio)

@MrHOY
Copy link

MrHOY commented Sep 1, 2017

@Spillo17 Oh, I used ionic3 and add this plugin, but no accessToken inside result

@edoardoo
Copy link

Still no news on this? I tried to revert using

cordova plugin add https://github.com/adriano-di-giovanni/cordova-plugin-googleplus --save  
"cordova-plugin-googleplus": "git+https://github.com/adriano-di-giovanni/cordova-plugin-googleplus",

but I'm not getting back any accessToken yet.

@amrsh
Copy link

amrsh commented Oct 16, 2017

I tried:

  • installing cordova-android-play-services-gradle-release and setting to 10.2.6 per @dpa99c
  • modifying plugin.xml to explicitly require 10.2.6 per @madding

I still do not get an accessToken. I then tried to get the accessToken from the serverAuthCode per @EddyVerbruggen , but the call always fails, for which I created a Stack Overflow question for Google here. No response yet.

So at this point I have no way whatsoever to get an accessToken on Android. @EddyVerbruggen , any pointers on what to try next?

@amrsh
Copy link

amrsh commented Oct 21, 2017

Finally managed to get the accessToken from the serverAuthCode, found that the encoding of the post wasn't correct. Especially weird since it was clear that the parameters were being recognized, yet nevertheless an error was being returned.

Still no idea why on Android the access_token suddenly stopped being returned, making this call necessary in the first place. Hopefully this will help others!

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

No branches or pull requests