Bdaya-Dev/oidc

fix: Error: TypeError: 3600: type 'int' is not a subtype of type 'Iterable<dynamic>' when setting `maxAge` in `OidcUserManagerSettings`

Closed this issue · 9 comments

When I attempt to set the maxAge duration for OidcUserManagerSettings, I get the following error:

Error: TypeError: 3600: type 'int' is not a subtype of type 'Iterable<dynamic>'
dart-sdk/lib/_internal/js_dev_runtime/private/ddc_runtime/errors.dart 297:3  throw_
dart-sdk/lib/_internal/js_shared/lib/rti.dart 1385:3                         _failedAsCheck
dart-sdk/lib/_internal/js_shared/lib/rti.dart 1363:3                         _generalAsCheckImplementation
dart-sdk/lib/core/uri.dart 2382:18                                           <fn>
dart-sdk/lib/_internal/js_dev_runtime/private/linked_hash_map.dart 21:7      forEach
dart-sdk/lib/core/uri.dart 2378:20                                           _makeQueryFromParametersDefault
dart-sdk/lib/_internal/js_dev_runtime/patch/core_patch.dart 937:12           _makeQueryFromParameters
dart-sdk/lib/core/uri.dart 2353:12                                           _makeQuery
dart-sdk/lib/core/uri.dart 4616:20                                           replace
packages/oidc_core/src/endpoints/authorize/req.dart 286:70                   generateUri
packages/oidc_web/oidc_web.dart 182:19                                       getAuthorizationResponse
dart-sdk/lib/_internal/js_dev_runtime/patch/async_patch.dart 84:54           runBody
dart-sdk/lib/_internal/js_dev_runtime/patch/async_patch.dart 127:5           _async
packages/oidc_web/oidc_web.dart 158:58                                       getAuthorizationResponse
packages/oidc/src/facade.dart 33:24                                          getPlatformAuthorizationResponse
dart-sdk/lib/_internal/js_dev_runtime/patch/async_patch.dart 84:54           runBody
dart-sdk/lib/_internal/js_dev_runtime/patch/async_patch.dart 127:5           _async
packages/oidc/src/facade.dart 27:73                                          getPlatformAuthorizationResponse
packages/oidc/src/managers/user_manager.dart 214:42                          _tryGetAuthResponse
dart-sdk/lib/_internal/js_dev_runtime/patch/async_patch.dart 84:54           runBody
dart-sdk/lib/_internal/js_dev_runtime/patch/async_patch.dart 127:5           _async
packages/oidc/src/managers/user_manager.dart 207:40                          [_tryGetAuthResponse]
packages/oidc/src/managers/user_manager.dart 164:12                          loginAuthorizationCodeFlow
dart-sdk/lib/_internal/js_dev_runtime/patch/async_patch.dart 45:50           <fn>
dart-sdk/lib/async/zone.dart 1661:54                                         runUnary
dart-sdk/lib/async/future_impl.dart 162:18                                   handleValue
dart-sdk/lib/async/future_impl.dart 838:44                                   handleValueCallback
dart-sdk/lib/async/future_impl.dart 867:13                                   _propagateToListeners
dart-sdk/lib/async/future_impl.dart 643:5                                    [_completeWithValue]
dart-sdk/lib/async/future_impl.dart 713:7                                    callback
dart-sdk/lib/async/schedule_microtask.dart 40:11                             _microtaskLoop
dart-sdk/lib/async/schedule_microtask.dart 49:5                              _startMicrotaskLoop
dart-sdk/lib/_internal/js_dev_runtime/patch/async_patch.dart 181:7           <fn>

Please note that I'm using FlutterSecureStorage.

Expected Behavior

I'd expect the OidcUserManagerSettings constructor to be able to handle the Duration type, with at least a better error output. If this isn't supported, the documentation should reflect this.

When maxAge is not set, I receive a null response from lines 213-221 of user_manager.dart.

      final response = await OidcFlutter.getPlatformAuthorizationResponse(
        metadata: metadata,
        request: request,
        options: options,
      );

hmm that's weird, will look into it

I see where the problem is now, it's in this method:

Uri generateUri(Uri authorizationEndpoint) => authorizationEndpoint.replace(
queryParameters: {
...authorizationEndpoint.queryParameters,
...toMap(),
},
);

which calls this line:

writeNotNull(
'max_age',
_$JsonConverterToJson<int, Duration>(
instance.maxAge, const OidcDurationSecondsConverter().toJson));

which uses this converter to convert duration to int:

class OidcDurationSecondsConverter extends JsonConverter<Duration, int> {
///
const OidcDurationSecondsConverter();
@override
Duration fromJson(int json) {
return Duration(seconds: json);
}
@override
int toJson(Duration object) {
return object.inSeconds;
}

however, query parameters only accept String or List<String>, which is why this error is there.

solution is to call .toString() on every serialized parameter, will make a PR for it soon.

When maxAge is not set, I receive a null response from lines 213-221 of user_manager.dart.

this is actually an unrelated issue, which is a limitation in package:url_launcher_web.

I also fixed it in the next version.

published version 0.6.2 that should fix both issues.

waiting for your feedback @jlambright

@ahmednfwela I can confirm that the maxAge is fixed.

However, requests fail instantly, and return null without throwing any exceptions. The strange part is that I await the future to be complete, and it completes almost instantly. Is there any guidance on this behavior?

Please note this is a flutter web app.

what navigation mode are you using?

I'm using the default new page.

have you checked the example ?
https://github.com/Bdaya-Dev/oidc/tree/main/packages/oidc/example
it works on web no problem

also please create a separate issue to track this preferable with sample code and the discovery document link (if it is a public idp)