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

Redirect uri #23

Closed
eugedebe opened this issue Sep 18, 2023 · 3 comments
Closed

Redirect uri #23

eugedebe opened this issue Sep 18, 2023 · 3 comments

Comments

@eugedebe
Copy link

eugedebe commented Sep 18, 2023

Hi,

First of all thanks for this library

I have implemented the code given in the example in pubdev. After pressing the button, I am able to receive in the callbacks of the widget (onIDToken and onAnyTokenRetrieved) receiving correctly the token given by B2c auth. The callback onRedirect is also being call correctly and i am able to navigate to another screen (my home screen). My only issue, is that after logging in the browser can't find the redirect url of the schema, the message shown in the browser of the mobile phone after login is: .com.example/authapp://oauthredirect/?code........ could not be loaded because net::ERR_UNKNOWN_URL_SCHEME

I had created (in android) a schema in the manifest adding in the activity tag

<intent-filter>
   <action android:name="android.intent.action.VIEW" />

   <category android:name="android.intent.category.DEFAULT" />
   <category android:name="android.intent.category.BROWSABLE" />

   <data
       android:scheme="com.example.authapp"
       android:host="oauthredirect"
       />
</intent-filter>

I tried to handle the url by installing the library uni_links and adding a listener in the main function :

class _MyAppState extends State<MyApp> {
  @override
  void initState() {
    initUniLinks();

    // TODO: implement initState
    super.initState();
  }

  void initUniLinks() async {
    getInitialLink().then((String? link) {
      if (link != null) {
        // Handle the link
      }
    });

    linkStream.listen((String? link) {
      if (link != null &&
          link.startsWith('com.example.authapp://oauthredirect')) {
        final Uri uri = Uri.parse(link);
        final String code = uri.queryParameters['code']!;
        // Now you have the code, proceed with your authentication flow
      }
      if (link != null) {
        // Handle the link
      }
    }, onError: (err) {
      // Handle the error
    });
  }

But when I debug the code, the breakpoint in the listener (breakpoint in line if (link != null &&
link.startsWith('com.example.authapp://oauthredirect')) ) is never reached.

I am a little bit lost what I need to do in order to show instead of a broken url text a loading progress or something like that during this fraction of second between the the token retrieved and the redirect callback that is sending the user to the home page.

Thanks.

@mohanajuhi166
Copy link
Collaborator

@eugedebe can you try providing the uri as a route within the flutter app ?
for example /home_screen or /app-screen etc?
what error do you get?

@filip8600
Copy link
Contributor

filip8600 commented Sep 29, 2023

For me, the solution was going from a redirect url like this:

msal<clientid>://auth

to a standard weburl like this:

https://<tenant>.b2clogin.com/oauth2/nativeclient

Both of these was configured in my tenant, so it was an easy fix. Otherwise you need to find you app-registration in Azure Portal and add a new allowed redirect-url.

@mohanajuhi166
Copy link
Collaborator

closing as solution provided by @filip8600 . Thanks!

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