SSO between React Native application and browser works, but it doesn't work if the browser is in WebView

I have a use-case that seems to be very popular in the questions asked here, but I can’t find a concrete answer to how it should be handled. The use-case is as follows:

I have a React Native application that does not yet support all pages/screens, which is why it is using WebView to render some of those unsupported pages by rendering the web application.

The problem is this - Once I am logged in React Native, I would like to automatically authenticate in the WebView web page as well, instead of having to input my username and password first.

From what I understand, this is supposed to happen out of the box:

For Android, the session is shared between my React Native application and my Chrome browser, however, it it seems to not be shared between the web application and the WebView.

For iOS it seems that the session is not shared between my React Native application and the Safari browser at all.

Is this simply not possible if I must use WebView? I’ve gone through multiple threads of people asking for the same thing and not getting any answer, or the answer states that the WebView uses different cookie jar therefore they would need to re-authenticate again.

2 Likes

Wandering if setting the WebView property sharedCookiesEnabled to true gives you the desired result?

WebView managing cookies

const App = () => {
  return (
    <WebView
      source={{ uri: 'http://example.com' }}
      sharedCookiesEnabled={true}
    />
  );
};

Hello and thank you for the response,

Unfortunately even though I’ve set sharedCookiesEnabled={true}, the session is not shared.

The WebView allows us to pass cookies to it, so I was wondering if it is possible to somehow fetch the required cookies inside the React Native application, before passing them to the WebView.