Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

authorizationInteractive on iOS Failed to redirect app #10

Open
benji-bou opened this issue Oct 13, 2021 · 4 comments
Open

authorizationInteractive on iOS Failed to redirect app #10

benji-bou opened this issue Oct 13, 2021 · 4 comments

Comments

@benji-bou
Copy link

Hi,

Thanks for this lib!
I succeed using it on flutter web app. But when testing on iOS, I have an error when the redirectURI is called by the webview

flutter: Error Domain= Code=0 "Redirection to URL with a scheme that is not HTTP(S)" UserInfo={_WKRecoveryAttempterErrorKey=<WKReloadFrameErrorRecoveryAttempter: 0x6000024f9c80>, NSErrorFailingURLStringKey=com.myapp.test://login-callback?code=HvXMEgiCMbMhhBqU, NSErrorFailingURLKey=com.myapp.test://login-callback?code=HvXMEgiCMbMhhBqU, NSLocalizedDescription=Redirection to URL with a scheme that is not HTTP(S)}

As the error says, webview doesn't redirect to non http(s) scheme. So the onPageFinished callback in android_ios.dart#OpenIdConnectAndroidiOS is never called.

I managed to by pass this error adding

  navigationDelegate: (navigation) {
                if (navigation.url.startsWith(redirectUrl)) {
                  Navigator.pop(dialogContext, navigation.url);
                  return flutterWebView.NavigationDecision.prevent;
                }
                return flutterWebView.NavigationDecision.navigate;
              },

I think, I'm not using correctly the lib for mobile app. What should I do to make it work without modifying the lib?

My implementation is


class Auth0Service {
  Future<AuthorizationResponse> login(
      BuildContext context, Auth0Configuration conf) async {
    final jsonConf = await OpenIdConnect.getConfiguration(
        "https://" + conf.auth0Domain + "/.well-known/openid-configuration");

    return OpenIdConnect.authorizeInteractive(
            context: context,
            title: "Interactive Login",
            request: await InteractiveAuthorizationRequest.create(
              clientId: conf.auth0ClientID,
              redirectUrl: conf.auth0RedirectURI,
              scopes: ["openid", "offline_access"],
              configuration: jsonConf,
              autoRefresh: false,
              useWebPopup: true,
            ))
        .asStream()
        .where((event) => event != null)
        .map((event) => event!)
        .first;
  }
}

class Auth0Configuration {
  final String auth0Domain;
  final String auth0ClientID;
  final String auth0RedirectURI;
  final String auth0Issuer;

  const Auth0Configuration(
      {required this.auth0Domain,
      required this.auth0ClientID,
      required this.auth0RedirectURI})
      : auth0Issuer = "https://" + auth0Domain;
}

Where the Auth0Service class is available in a flutter package that I would like to reuse in my different projects

Best

@jhancock4d
Copy link
Contributor

You have to define iOS and Android deep linking. There is a Google doc for flutter on how to do it.

@PranavBhatt1
Copy link

PranavBhatt1 commented Sep 26, 2024

@jhancock4d & @benji-bou Let me know if you got any solution. Redirect URI is stuck popup, not close!
It is working fine for android but stuck in iOS!

@benji-bou
Copy link
Author

Hello,
Sorry I used it in an old project. One I don't work on anymore, so I don't have access to the code base anymore .

@PranavBhatt1
Copy link

Hi @benji-bou ,
It's okay brother, My issue is already resolved.
I implemented it into my flutter (Dart) cross platform mobile app.

redirectionURL = "com.example.untitled/callback"
Above URL working in Android webview callback got into onPageFinished but unable to called onPageFinished in iOS so i changed it to
"https://com.example.untitled/callback"
and then it's working in Android but in iOS it's gone to onWebResourceError because it's not correct URL and there I'm handling for iOS only and navigating to previous activity where I got authentication response of my 3rd party auth, so issue in OpenIdConnect library, so I changed it into my project now.
Will generate PR for the same.

Thank you for everything.

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

No branches or pull requests

3 participants