MaikuB / flutter_appauth

A Flutter wrapper for AppAuth iOS and Android SDKs
274 stars 246 forks source link

Failed to authorize #203

Closed markbeij closed 2 years ago

markbeij commented 3 years ago

Sometimes the app is unable to show the login screen. We see this in the logging as: _PlatformException(authorize_and_exchange_codefailed, Failed to authorize: De bewerking kan niet worden voltooid. (org.openid.appauth.general fout -3.), null, null)

This seems to be specific to iOS. The error code (-3) suggests that the user cancelled, but that doesn't seem to be the case. There is just no login screen. Is this a common problem? I'm not sure how to handle this better.

markbeij commented 3 years ago

Most of the times this happens during startup I think. In main.dart we have code to ensure new push notification tokens are sent to our api. We're using bloc-pattern. NotificationSettingsChangedEvent triggers retrieving an access token and calling the API with that token.

_firebaseMessaging.onTokenRefresh.listen((event) async {
  //During startup it is likely that there is no currentContext just yet
  //By waiting just a tiny bit we are certain we don't miss any events
  while (GlobalVariable.navState.currentContext == null) {
    await Future.delayed(Duration(milliseconds: 50));
  }
  BlocProvider.of<ProfileBloc>(GlobalVariable.navState.currentContext).add(NotificationSettingsChangedEvent());
});
_firebaseMessaging.onIosSettingsRegistered.listen((event) async {
  //During startup it is likely that there is no currentContext just yet
  //By waiting just a tiny bit we are certain we don't miss any events
  while (GlobalVariable.navState.currentContext == null) {
    await Future.delayed(Duration(milliseconds: 50));
  }
  BlocProvider.of<ProfileBloc>(GlobalVariable.navState.currentContext).add(NotificationSettingsChangedEvent());
});
MaikuB commented 3 years ago

I don't recall others reporting this nor do I know what the cause could be. Perhaps your app is doing this at certain points where it shouldn't do so (before runApp is called?) but this is really just a guess

markbeij commented 3 years ago

Thanks for your reply. Any suggestions what such point might be?

MaikuB commented 3 years ago

Only what I mentioned before, which again was just a guess. You'd need to debug to find out what's going on and may need to introduce more logging in your own app to help with that

shubhamkatore commented 3 years ago

I am getting PlatformException(authorize_and_exchange_code_failed, null, null, null) After upgrading to flutter 2.2.1

Code Block:

await _appAuth.authorizeAndExchangeCode(
              AuthorizationTokenRequest(
                configuration.clientId,
                configuration.redirectUrl,
                serviceConfiguration: _serviceConfiguration,
                scopes: configuration.scopes,
                preferEphemeralSession: preferEphemeralSession,
              ),
            );

Am I missing something, or is it platform version specific?

@MaikuB

Jemshi101 commented 3 years ago

This is happening for me as well. But only getting reported in the crashlytics image @MaikuB

MaikuB commented 3 years ago

These crash logs don't necessarily indicate an issue with the plugin and if there is an issue with the plugin, this would need a minimal app that can reproduce the problem. It may be possible that your app is initiating multiple requests at the same time. The code is publicly available as well so you could use that diagnose and debug

MaikuB commented 2 years ago

Closing this as there's been no further info on how to reproduce this issue. If you can provide a way to reproduce this then please file a new issue and include a link to a repository hosting a minimal app that can reproduce the problem and include steps to reproduce as well