Cookie caching in inappbrowser iOS 10 (clearcache = no;) does not work when the application is restarted - Cordova / Ionic

I ran into a problem in the ionic iOS application where my site does not save cookies and clear the cache and clear the session cache does not work. I am using the Cordova Inappbrowser plugin.

It works great on Android.

var ref = window.open(url, '_blank','location=no,toolbar=yes,clearcache=no,clearsessioncache=no'); 

But on iOS, it does not work. When I first provide my credentials and go to the application, and then I exit the application and open it again, it again asks for my credentials (which works great in ANDROID)

After further digging, I found that the cookie that should have been saved is marked as isSessionOnly = true and expires = null .

This way I see a cookie inside the session, but clears when the application is closed

I found my result by writing the following code in the CDVinAppbrowser.m class:

 - (void)openInInAppBrowser:(NSURL*)url withOptions:(NSString*)options { NSHTTPCookie *cookie; NSHTTPCookieStorage *cookieJar = [NSHTTPCookieStorage sharedHTTPCookieStorage]; for (cookie in [cookieJar cookies]) { NSLog(@"%@", cookie); } 

So how to save cookies or make inappbrowser with options working with clearcache = no and clearsessioncache = no in iOS.

Note. I am completely new to iOS / Swift. So, I need to know where to place the code in fast classes.

Edit for Bounty (AndroidMechanic)

I have the same problem when it works fine for android, but on iOS it asks for credentials every time the application restarts. I suggest generosity for a solution where you can avoid using your own code.

+5
source share
2 answers

@AndroidMechanic, I posted a question, and that’s how we solved it.

We figured that iOS inappbrowser webview does not process cookies properly, but android webview does. Our initial login process was through our identity provider (which was ADFS in our case). The identity provider was configured using SAML (which works through cookies).

Solution 1: (Make sure Cookies work as long as they are valid)

So, we used cordova cookiemperor cordova, where we saved the cookie after a successful login and passed it to the URL when someone logs in again. This worked until the cookie ran out.

But we needed a better solution to this problem, solution 2.

Solution 2: (do not use cookies, use an access token)

We changed our authentication from SAML to OAuth2.0, where we used access tokens and token updates to verify the identity of the user.

So, whenever the login controller starts, it checks the following before invoking the URL:

 A) Check if any access token is present B) If present, whether it is expired or not. C) If expired, use the refresh token to get the new access token. 

If any of the above conditions fails, we call the URL where the user must log in again, otherwise the user will be able to use the single sign-on capabilities of iOS and Android without worrying about cookies.

thanks

Sourav

0
source

@AndroidMechanic, the problem you pointed out for iOS is a known problem, and we faced the same one, so we came to the next solution, instead of saving data in a session or in cookies, we preferred to save it in KeyChain Here is the link which supports Ionic Native .

1.Install Cordova and Ionic Native plugins:

 $ ionic cordova plugin add cordova-plugin-ios-keychain $ npm install --save @ionic-native/keychain 

2. Add this plugin to your application module . ...

 import { Keychain } from '@ionic-native/Keychain'; ... @NgModule({ ... providers: [ ... Keychain ... ] ... }) export class AppModule { } 

3. Use

 import { Keychain } from '@ionic-native/keychain'; constructor(private keychain: Keychain) { } ... this.keychain.set(key, value).then(() => { this.keychain.get(key) .then(value => console.log('Got value', value)) .catch(err => console.error('Error getting', err)); }) .catch(err => console.error('Error setting', err)); 
0
source

Source: https://habr.com/ru/post/1263855/


All Articles