19

We have an android app where we want to open a url.To avoid user re entering user name and password, we want to pass the session cookies. We can use webview inside our app to do this but we want to avoid webviews.

Another solution we found is using chrome custom tabs. As per the documentation https://developer.chrome.com/multidevice/android/customtabs chrome custom tabs supports:

Shared Cookie Jar and permissions model so users don't have to log in to sites they are already connected to, or re-grant permissions they have already granted.

I am trying the example from https://github.com/GoogleChrome/custom-tabs-client But i am not able to figure out how to pass the session data.

Can anyone help me by pointing to documentation or way to achieve this ?

Pranay Airan
  • 1,855
  • 6
  • 28
  • 52

2 Answers2

14

The shared cookie jar means that the Custom Tab shares the cookie jar with Chrome. As of today, it is not possible to set a cookie from the application inside a Custom Tab.

On the other hand, you may want to check Smart Lock for Passwords, which enables automatic sign-in across applications and websites (and will work inside a Custom Tab)

andreban
  • 4,621
  • 1
  • 20
  • 49
  • 2
    This answer is a few years old now. Do you know if the statement "As of today, it is not possible to set a cookie from the application inside a Custom Tab" is still true? – Locksleyu Apr 26 '18 at 17:22
  • Yes, it remains true. – andreban Apr 28 '18 at 08:03
  • Seems that Branch SDK can read cookies (but with reflection): https://github.com/BranchMetrics/android-branch-deep-linking-attribution/blob/master/Branch-SDK/src/io/branch/referral/BranchStrongMatchHelper.java – artem Aug 28 '19 at 17:25
  • it seems that Smart lock for passwords can only save credentials not a session. So login methods such as OTP verification can't be shared, and user cannot be auto logged in – gaurav5430 Oct 02 '22 at 19:28
  • @andreban is it possible to set cookies in the custom tab now or yet we can't set it? – Dharanidharan Aug 22 '23 at 05:34
  • I'm assuming you mean setting Cookies from the Android app. If that's the case, it's not possible. You can add query parameters or some request headers. – andreban Aug 22 '23 at 07:18
0

This feature appears to be something the Chromium team wanted to do, but hasn't implemented yet. Here is the bug-report/feature-request that suggests a possible workaround.

Rich Ehmer
  • 2,764
  • 23
  • 18