react-native-azure-auth sign out web view not automatically closing and getting back to the mobile app

Viewed 487

I have a react native app that uses the react-native-azure-auth library for B2B and B2C authentication on Azure AD. The MFA sign-in works as expected but after the successful logout, the web view saying you have successfully signed out remains open and does not go back to the mobile app. It needs to be manually closed by the user to go back to the mobile app. This happens only for the B2B sign-in. using B2C on the same library automatically closes the sign-out web view/window.

I also checked out the other libraries similar to it but either they need to revoke access or id tokens for logging out which is not applicable in AAD or they are explicitly for B2C only. I have also tried if it's possible to forcibly close the webview/window or put the mobile app in the foreground but so far I am not successful.

This has been raised with the library contributors and got a response that this is more of a Microsoft behavior. I was just wondering if anyone else encountered this and found a workaround?

I saw a suggestion to revoke the refresh token via graph but that will also affect other applications so that is the last thing we want to do.

1 Answers

The issue you are facing is the bug in react-native-azure-auth library. Here is the link of the reported bug.

For logging out you would need to use this code:

_onLogout = () => {
azureAuth.webAuth
.clearSession()  // If you are using .clearSession({}) then remove this {}
.then(success => {
this.setState({ accessToken: null, user: null });
})
.catch(error => console.log(error));
};

In validate.js file there is a bug so remove the bug.

Your old code:

if (parameter && value) {}

New Code:

if (parameter && value !== undefined) { }

In your react-native app for closing the webview you need to handle the onNavigationStateChange props of webview. You can use this props to check the current state or the currentURL of webview and add some condition to close the webview. Read more here on how to close the webview when signing out from MSAL. You can read more about the webview component here.

Related