flutter_appauth icon indicating copy to clipboard operation
flutter_appauth copied to clipboard

Failed to authorize

Open markbeij opened this issue 3 years ago • 7 comments

Sometimes the app is unable to show the login screen. We see this in the logging as: PlatformException(authorize_and_exchange_code_failed, 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 avatar Apr 15 '21 06:04 markbeij

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());
});

markbeij avatar Apr 15 '21 08:04 markbeij

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

MaikuB avatar Apr 15 '21 13:04 MaikuB

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

markbeij avatar Apr 16 '21 05:04 markbeij

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

MaikuB avatar Apr 23 '21 23:04 MaikuB

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

shubhamkatore avatar Jun 06 '21 14:06 shubhamkatore

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

Jemshi101 avatar Jun 07 '21 06:06 Jemshi101

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 avatar Jun 27 '21 05:06 MaikuB

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

MaikuB avatar Oct 08 '22 05:10 MaikuB