Open the web browser from a flutter application, and then redirect to the application again

1.3k views Asked by At

I am developing a mobile application using Flutter, and i have the web version using angular, and the back is using nodejs.

For some reason, i want to do the following work flow: When the user is logging in, the application should redirect him to the web application, login in in the browser, and then bring him back to the application.

The reason behind that, is my application implement the 2FA using hardware keys, which can be used only on the domain name they are registered in.

I tried to work with url launcher, also the web widget. However i can go from the mobile application to the browser, login, but i cannot come back from the web to the mobile application.

2

There are 2 answers

1
Mostafa Soliman On BEST ANSWER

The best way to do it is using Deep Linking, This article will help.

1
Katay On

I did that before with WebView, here(sphagetti code warning): https://github.com/KatayR/googleAkademiMobilUygulama/blob/master/lib/webView_File.dart

Basically, the website I tried to login was redirecting users to a certain page if login is successful.So I used onNavigationRequest and added a condition like:

onNavigationRequest: (NavigationRequest request) async {
            // 
            if (request.url
                .startsWith('https://somewebsite.com/profilePage')) {
                Navigator.pushReplacement(
                context,
                MaterialPageRoute(builder: (context) {
                  return const HomePage();
                }),
              );
    }

Just think about which condition(s) you can use in order to decide that used logged in successfuly.

If you check that github page and get lost because it's coded terribly, just let me know where you got stuck and I can help further.