Cevin Thomas
Cevin Thomas

Reputation: 397

React Native Linking Listener?

Description:

Built an app, need to implement Swedish BankID. This means, when user presses a button, the Swedish BankID App opens, and when the user has signed in, the Swedish BankID App sends the user back to my app (which it does automatically), in which I need to retrieve data (if sign in was successful or not).

What needs to be accomplished:

Open Swedish BankID on the device from my app. Need to be able to receive a payload from Swedish BankID App in my app (Swedish BankID sends user automatically back to my app).

Current Code:

const url = `https://app.bankid.com/?${autoStartToken}`;
            const supported = await Linking.canOpenURL(url);

            if (supported) {
                const answer = await Linking.openURL(url);
            } else {
                Alert.alert(`Don't know how to open this URL: ${url}`);
            }

Currently, the Swedish BankID App opens correctly, my question is, is there any way to receive data from the other app? I know this is possible with Native Modules (running Objective-C etc), however I am using Expo Client and do not wish to eject.

I have yet to find anything that suggests that React-Native can listen to the other app.

Upvotes: 0

Views: 979

Answers (2)

smuda
smuda

Reputation: 101

Since the BankID app can even be on another device (if you present the url as a QR code) it's kind of hard to communicate with the app. Also, from a privacy perspective the app isn't supposed to give a lot of information away.

What you can do is to "bounce" information via the app using the "redirect" parameter. That's especially useful when you want to tie back to the existing session. There are however a few caveats, especially when using multiple browsers, so make sure to read the Relying Party Gudelines.

Upvotes: 0

Sergey Ivchenko
Sergey Ivchenko

Reputation: 1617

You can use expo WebBrowser to open url. For authentication you will want to use WebBrowser.openAuthSessionAsync, and if you just want to open a webpage WebBrowser.openBrowserAsync Exemple:

  ...
    import * as WebBrowser from 'expo-web-browser';
    ....
    
    const handleLinkAsync = async () => {
      let result = await WebBrowser.openBrowserAsync('https://google.com');
      console.log(result)
    };

Upvotes: 0

Related Questions