I'm currently developing a cordova app with an ADFS authentication through inappbrowser.
This works well so far. But I need to retrieve the session cookie stored in the webview instance and be able to use it in another application with the same mechanism, so the user doesn't need to log in twice, as both apps use the same corporate login.
I've tried recovering the cookie with CookieManager
CookieManager cookieManager = CookieManager.getInstance();
String cookies = cookieManager.getCookie(url);
However, it doesn't list the session cookie. It seems CookieManager doesn't return those cookies without expiration date.
I've been able to successfully terminate the session by running
CookieManager cookieManager = CookieManager.getInstance();
cookieManager.removeSessionCookies(null);
So I'm sure the session cookie is there, but I'm unable to get/manipulate it.
Related
I'm using Java code on an Android app to login and I receive cookies after I successfully login (using Retrofit).
What I want to do is if the login is successful and I go to a different tab which has a WebView that I'm automatically logged in with my browser cookie. On iOS this works perfectly. On Android I think I have to change something in my code so I'm using the following code to set the cookies in my CookieManager:
CookieManager cookieManager = CookieManager.getInstance();
cookieManager.setAcceptCookie(true);
for(String cookie: response.headers().values("Set-Cookie")){
System.out.println("cookie = " + cookie);
cookieManager.setCookie(Constants.baseURL, cookie);
}
This works fine and if I reload the WebView it seems to have all the right cookies, why am I not logged in in the WebView and does this work in iOS? Do I need to add something else?
May be you have forgotten to use CookieSyncManager.createInstance(..)
And call sync on obtained instance
I'm trying to send HTTP Post requests to my webservice. It seems to work, however the cookies are not enabled.
I tried to import android.webkit.CookieManager in my Application and then use this code :
CookieManager cookieManager = new CookieManager();
cookieManager.setAcceptCookie(true);
I get an error telling me that CookieManager cannot be instancied.
Is there a way to allow cookies when sending a POST request ?
Thanks for your help.
Try this for webview cookies
CookieManager.getInstance().setCookie();
http://developer.android.com/reference/android/webkit/CookieManager.html#setCookie(java.lang.String,java.lang.String,android.webkit.ValueCallback
I'm developing apps on iOS and Android where I have a web of shopping and when I buy an item, the web gives me a value on the cookie that I get and then I show the number of items that the client has purchased.
The way to take the cookies is:
CookieManager cookieManager = CookieManager.getInstance();
cookieManager.setAcceptCookie(true);
String cookies = cookieManager.getCookie(url);
so, when I have 20 products and I add one, it turns to 21 (obviously) but when I remove one item, it stays on the same number because the cookies don't get updated.
I'm using the same login with Objective C and it updates well.
Am I missing anything on Android?
Thanks in advance.
I'm writing a Cordova app and I would like to access its HTTP secure cookie from a plugin. I want to encrypt / disable it until the user enters a valid pin.
All help is greatly appreciated. Thank you.
The way I would do it would be to enable/disable the cookies for the entire application:
CookieManager mCookieManager = CookieManager.getInstance();
CookieSyncManager.createInstance(this);
mCookieManager.setAcceptCookie(false); //disables cookies for the WebView until the user enters a correct pin
if(getUsersPin()) { //getUsersPin() gets the pin from the user
mCookieManager.setAcceptCookie(true);
}
I'm failing at the moment in letting my app delete the browser cookies or some specific cookies.
The way I found was to implement the following:
CookieSyncManager.createInstance(this);
CookieManager cookieManager = CookieManager.getInstance();
cookieManager.removeAllCookie();
But nothing is happening. An with the method hasCookie() is get false as return. Is there no way for deleting a cookie from inside my app?
Thanks for your help!
You can use CookieSyncManager to delete cookies from your own WebView widget(s).
You cannot delete cookies from third-party applications that use WebView or other Web rendering engines.