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

Expo Support #17

Closed
antoniogoulao opened this issue Jan 21, 2020 · 17 comments
Closed

Expo Support #17

antoniogoulao opened this issue Jan 21, 2020 · 17 comments
Labels
enhancement New feature or request proposal

Comments

@antoniogoulao
Copy link

Feature Request

Add Expo Support. With Expo growing and more developers joining the RN community, many of them will start with Expo and face the same issue I'm facing, cookie management in the app.

Why it is needed

I'm trying to develop an app made to authenticate through a webpage and then get redirected to the app. WebBrowser and AuthSession from Expo are ruled out since we can't cover all the use cases, leaving us with WebView. We can't access and we don't want to access the cookies in the WebView, we want to decouple the login from the REST API calls that we do after and only get the cookie in that moment.

Possible implementation

I have no experience in this area

Code sample

The perfect outcome would be to run the command: expo install @react-native-community/react-native-cookies

@safaiyeh
Copy link
Member

Thanks for the issue @antoniogoulao the Expo team has expressed a need for it as well here: expo/expo#6756

I'll follow up with them to see how we can proceed.

@safaiyeh safaiyeh added enhancement New feature or request proposal labels Jan 21, 2020
@Djokic
Copy link

Djokic commented Feb 4, 2020

Hey @safaiyeh, are there any news about Expo support?

@safaiyeh
Copy link
Member

safaiyeh commented Feb 6, 2020

Still in discussion @Djokic

@brentvatne
Copy link
Contributor

@antoniogoulao - can you clarify your use case?

I'm trying to develop an app made to authenticate through a webpage and then get redirected to the app. WebBrowser and AuthSession from Expo are ruled out since we can't cover all the use cases

what use cases aren't covered?

leaving us with WebView.

apple will not allow you on the store if you provide authentication through a webview, they will tell you to use SFSafariViewController/SFAuthenticationSession

We can't access and we don't want to access the cookies in the WebView, we want to decouple the login from the REST API calls that we do after and only get the cookie in that moment

so you want to get the cookies via login in webview and then use that to make api calls in react-native, right?

@brentvatne
Copy link
Contributor

@Djokic - can you explain in detail what your use case is? I want to make sure that whatever we come up with for Expo managed workflow will work for you

@Djokic
Copy link

Djokic commented Feb 7, 2020

I’m trying to log in to external service though a WebView, read cookies from WebView (including HTTPOnly) and use them to make requests in react-native. In the end I would like to clear cookies from both RN and WebView.

This service does not support OAuth so I can not use AuthSession.

@antoniogoulao
Copy link
Author

Hi @brentvatne, it's the same case as @Djokic. In my use case, the app needs to support SAML Auth. I can't change, from the app, the RelayState to where the SSO is going to redirect the user to a URI that makes the app redirect and in some custom implementations of the protocol, it's not possible to ask to configure the SSO service to redirect after login according to the app (using a custom header for instance) accessing the service.

Could HTTPCookieStorage.shared.cookies be used in this case?

@brentvatne
Copy link
Contributor

which functions from this library do you need specifically to be able to accomplish your goal? is there any way you can provide me with access and an example of integrating with an endpoint so i can ensure that whatever we include in expo ends up meeting your requirements?

@antoniogoulao
Copy link
Author

@brentvatne from this library I would need to get the cookies for a given hostname, delete the cookies for that hostname, and optionally set from response. Unfortunately I don't have any instance or endpoint I can provide

@antoniogoulao
Copy link
Author

Any way I can help you more with this request? Was it clear enough?

@brentvatne
Copy link
Contributor

we plan to work on this for sdk38!

i understand the request. if you can give me access to some endpoint and demonstrate how you would build this with react-native-cookies in it's current form that would be helpful for me to understand further!

@NickCis
Copy link

NickCis commented Apr 5, 2020

@brentvatne Is there any ETA for the feature?

@brentvatne
Copy link
Contributor

we do quarterly sdk releases so if it makes it in to sdk38 it will be available in the managed workflow at the end of june

@NickCis
Copy link

NickCis commented Apr 7, 2020

For the time being, I've found a workaround to manage cookies in expo that others might find interesting. I've only tested it on Android using the expo app (expo: 37).

@pdandradeb
Copy link

@antoniogoulao I'm facing something similar. Tried many different alternatives and end up creating a PR react-native-webview/react-native-webview#1465 to include a clearCookies method in the react-native-webview for iOS and Android. Let's see if it will be merged.

In RN 0.62.2, the RCTNetwork interface was exposed so, in theory, you could do something like this:

import React, { useRef } from 'react';
import { Button } from 'react-native';
import WebView from 'react-native-webview';
import Networking from 'react-native/Libraries/Network/RCTNetworking';

const App = () => {

  const webView = useRef();
  const reload = () => webView.current.reload();
  const clearCookies = () => Networking.clearCookies((cleared) => console.log(cleared));

  return (
    <>
      <Button title="Clear cookies" onPress={clearCookies} />
      <Button title="Reload" onPress={reload} />
      <WebView
        ref={webView}
        style={{ height: 500 }}
        source={{uri: 'https://www.theguardian.com/international'}}
      />
    </>
  );
};

But, as commented here, it doesn't work on iOS.

While it's not possible to clearCookies at client side, I think the best option would be to configure your idP to force reauthentication (thanks @brentvatne for the tip). If you're using Azure AD and SAML, this article might be helpful.

@thargenediad
Copy link

For which SDK version is this feature to be included?

@safaiyeh
Copy link
Member

Closing as this package will not be included with expo

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request proposal
Projects
None yet
Development

No branches or pull requests

7 participants