googleapis_auth
googleapis_auth copied to clipboard
allow clientViaUserConsent to specify which account to use
I'm not sure I got everything right but in my browser application I use the following code on start:
flow.clientViaUserConsent(immediate: true)
and it seems to always load the first user that was logged in the browser "session". I created a simple webapp here: https://github.com/alextekartik/dart-test/tree/master/googleapi_auths_test that can be tested here: http://gstest.tekartik.com/googleapis_auth_test
even if I switch to a different user (using flow.runHybridFlow(force: true)), the last authenticated user is not the one silently authenticated when the page reload which makes it impossible to always use the same account if the first one used was not the correct account the user wants to use.
I would to have a way to specify the "credentials" to try during flow.clientViaUserConsent(immediate: true), as I'm able to capture and save the last credentials used. Otherwise is there a way to "save" the next automatically authenticated user in the same window
Or maybe I'm missing something and in that case I could ask in stack overflow but that is a question rather specific to this package.
One trick would be to allow to specify the "user_id" during the login (gapi.auth.authorize call in implicit.dart). Unfortunately this parameter cannot be specified in the various api provider. Currently that is exactly what I use (I store the user_id of the last user logged in) to check that the automatic logged in user is the one I expected. That does require accessing the PlusApi though
So I made a quick app to support passing a userId in clientViaUserConsent. What it ends up doing is changing the json during the _login call
if (userId != null) {
json['authuser'] = -1;
json['user_id'] = userId;
}
I get the userId the first time using plus api and store it locally so it works well and I can expect to login with the user I want. The code and demo link is here The only issue is that the "Welcome back" popup from google+ does not match which is kind of bad so I'll find a way to hide it ;)
For me this is is a must have feature so that I can really make a standalone web app that can automatically sync data after loading with the account I have save previously
It would be great if there was an optional parameter to force the account selection again, as mentioned in this comment. https://github.com/dart-lang/googleapis_auth/issues/4#issuecomment-55610469