Skip to content
This repository has been archived by the owner on Jan 26, 2021. It is now read-only.

Failed assertion when doing clientViaUserConsent #26

Open
floitschG opened this issue Dec 6, 2017 · 7 comments
Open

Failed assertion when doing clientViaUserConsent #26

floitschG opened this issue Dec 6, 2017 · 7 comments

Comments

@floitschG
Copy link

From @floitsch on December 2, 2017 16:23

When doing a clientViaUserConsent I get the following assertion error:

When running without assertions, the code seems to work.

Unhandled exception:
'package:googleapis_auth/src/auth_http_utils.dart': Failed assertion: line 81 pos 12: 'credentials.refreshToken != null': is not true.
#0      _AssertionError._doThrowNew (dart:core-patch/dart:core/errors_patch.dart:37)
#1      _AssertionError._throwNew (dart:core-patch/dart:core/errors_patch.dart:33)
#2      new AutoRefreshingClient (package:googleapis_auth/src/auth_http_utils.dart:81:12)
#3      clientViaUserConsent.<anonymous closure> (package:googleapis_auth/auth_io.dart:53:32)
#4      _RootZone.runUnary (dart:async/zone.dart:1381)
#5      _FutureListener.handleValue (dart:async/future_impl.dart:129)
#6      _Future._propagateToListeners.handleValueCallback (dart:async/future_impl.dart:633)
#7      _Future._propagateToListeners (dart:async/future_impl.dart:662)
#8      _Future._complete (dart:async/future_impl.dart:467)
#9      _SyncCompleter.complete (dart:async/future_impl.dart:51)
#10     _completeOnAsyncReturn (dart:async-patch/dart:async/async_patch.dart:255)
#11     AuthorizationCodeGrantServerFlow.run (package:googleapis_auth/src/oauth2_flows/auth_code.dart:223:9)
#12     _RootZone.runUnary (dart:async/zone.dart:1381)
#13     _FutureListener.handleValue (dart:async/future_impl.dart:129)
#14     _Future._propagateToListeners.handleValueCallback (dart:async/future_impl.dart:633)
#15     _Future._propagateToListeners (dart:async/future_impl.dart:662)
#16     _Future._addListener.<anonymous closure> (dart:async/future_impl.dart:342)
#17     _microtaskLoop (dart:async/schedule_microtask.dart:41)
#18     _startMicrotaskLoop (dart:async/schedule_microtask.dart:50)
#19     _Timer._runTimers (dart:isolate-patch/dart:isolate/timer_impl.dart:376)
#20     _Timer._handleMessage (dart:isolate-patch/dart:isolate/timer_impl.dart:401)
#21     _RawReceivePortImpl._handleMessage (dart:isolate-patch/dart:isolate/isolate_patch.dart:163)
main() {
  clientViaUserConsent(new ClientId(_CLIENT_ID, _CLIENT_SECRET), _SCOPES, (String str) {
    print("asking for consent: $str");
  }).then((client) {
  });

Copied from original issue: google/googleapis.dart#26

@floitschG
Copy link
Author

From @mkustermann on December 4, 2017 11:58

This issue should probably moved to package:googleapis_auth.

The assertion is correct in the sense that the oauth2 access token you got back will most likely only be valid for 1h and expire afterwards. Getting a refresh token from the server allows the returned AutoRefreshingAuthClient to refresh the access token before it expires. That's why the assertion is in.

The real question is why the server hasn't returned the refresh token in the first place.

@floitschG
Copy link
Author

I tried removing the permission from my account, but that wasn't enough.
https://stackoverflow.com/questions/10827920/not-receiving-google-oauth-refresh-token

Some comments claim that one has to set the access_type to offline.
Given the assert, we should probably always set "access-type" to "offline" all the time.

@mkustermann
Copy link
Contributor

Could you describe how you created the client Id in the developers console?

@floitschG
Copy link
Author

I had created the my credentials for "webapp" and not "other".
Not sure, if we still want to do something.

@mkustermann
Copy link
Contributor

I think we can turn the assertion into a check and an exception. Although we can never know why the server did not return a refresh token, we could hint the user that the provided client credentials were wrong.

@floitschG
Copy link
Author

Sounds good to me, although I wonder if there should be a way to use web-tokens for scripts too.

@GuillermoDLCO
Copy link

I add parameter to fix this problem #79

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

No branches or pull requests

3 participants