teranetsrl / oauth2_client

Simple Dart library for interacting with OAuth2 servers.
BSD 2-Clause "Simplified" License
91 stars 112 forks source link

NoSuchMethodError: The method 'cast' was called on null #64

Open bat79a opened 3 years ago

bat79a commented 3 years ago

Hi all.

I just update the lib oauth2_client 1.3.0 to 1.7.1 but now my openid connection failed.

Here is the error message that I have :


[VERBOSE-2:ui_dart_state.cc(186)] Unhandled Exception: NoSuchMethodError: The method 'cast' was called on null.
Receiver: null
Tried calling: cast<String>()
#0      Object.noSuchMethod (dart:core-patch/object_patch.dart:54:5)
#1      TokenStorage.getToken.<anonymous closure> (package:oauth2_client/src/token_storage.dart:36:59)
#2      Iterable.firstWhere (dart:core/iterable.dart:513:15)
#3      TokenStorage.getToken (package:oauth2_client/src/token_storage.dart:28:40)
<asynchronous suspension>
#4      OAuth2Helper.getTokenFromStorage (package:oauth2_client/oauth2_helper.dart:105:12)
<asynchronous suspension>
#5      OAuth2Helper.getToken (package:oauth2_client/oauth2_helper.dart:80:19)
<asynchronous suspension>
#6      OAuth2Helper._request (package:oauth2_client/oauth2_helper.dart:287:19)
<asynchronous suspension>
#7      _MyHomePageState.apiUserInfo (package:myproject_mobile/main.dart:358:34)
<asynchronous suspension>

If someone can help me to fix this, it will be awesome.

Thx a lot.

okrad commented 3 years ago

Hi @bat79a, can you try upgrading to the latest version (2.0.1)?

ghost commented 2 years ago

I have the same issue during token refresh (version 2.2.2). In my case, AccessTokenResponse has null scope after AccessTokenResponse.fromHttpResponse.

ernestoA92 commented 2 years ago

I'm having the same issue on version 2.3.0.

The problem is on this line: package:oauth2_client/src/token_storage.dart:41:59

okrad commented 2 years ago

Hi @ernestoA92, can you try with the newest release (2.3.1)?

ghost commented 2 years ago

64

xolf commented 1 week ago

Hey guys,

I came across the same issue. Honestly, I'm not sure why access tokens with a null scope are being saved on the device, but I'm still encountering the error. I've opened a small PR that might resolve this problem.