benjipelletier
benjipelletier

Reputation: 663

Clear Phonegap's InAppBrowser Cache Programmatically

I am using Oauth 2.0 for Google authorization into a hybrid app. I am using PhoneGap's InAppBrowser API and it works perfectly; however, I want to be able to clear the cache of the InAppBrowser after someone clicks the local logout button. I have tried adding "clearcache=yes" and "clearsessioncache=yes", but they do not seem to do anything. Without clearing the cache when someone tries to log back in it validates the token with the previously signed in account. The only way I can sign out is to keep trying to login until I get the Google permissions screen and can manually logout. Is there a way I can delete everything associated to the InAppBrowser programmatically?

Thanks

Upvotes: 5

Views: 17777

Answers (5)

Hrushikesh Sawant
Hrushikesh Sawant

Reputation: 74

iOS users please add this line to config file

iOS Quirks Since the introduction of iPadOS 13, iPads try to adapt their content mode / user agent for the optimal browsing experience. This may result in iPads having their user agent set to Macintosh, making it hard to detect them as mobile devices using user agent string sniffing. You can change this with the PreferredContentMode preference in config.xml.

<preference name="PreferredContentMode" value="mobile" />

The example above forces the user agent to contain iPad. The other option is to use the value desktop to turn the user agent to Macintosh.

Upvotes: 0

user917170
user917170

Reputation: 1641

The selected answer is out of date, you can now use the clearsessioncache flag in both iOS and Andriod. See documentation here:

https://github.com/apache/cordova-plugin-inappbrowser

So the correct solution is to just use

window.open("domain.com", "_blank", "location=no,clearsessioncache=yes"); 

In any case. Also note

The options string must not contain any blank space, and each feature's name/value pairs must be separated by a comma. Feature names are case insensitive.

Upvotes: 4

jjyepez
jjyepez

Reputation: 350

You may want to add a meta tag for no-cache in the head.

That worked for me.

Upvotes: -1

Kishore Barik
Kishore Barik

Reputation: 770

I think best way to logout from google in the inAppBrowser is open the url

'https://mail.google.com/mail/logout?hl=en'

from it, it will automatically log you out from google redirecting you to login page. If you need to do this by any button click of your app, you can open the inAppBrowser hidden.

window.open('https://mail.google.com/mail/logout?hl=en', '_blank', 'hidden=yes')

Also you can do another thing you can open this url in hidden mode before every time you call the Oauth url. It will make sure your previous session has been logged out letting you provide different login Id.

Upvotes: 1

AAhad
AAhad

Reputation: 2845

As said: clearcache or clearsessioncache is only for Android. read this API Doc

In case of Android so before re-opening:

window.open("domain.com", "_blank", "location=no,clearsessioncache=yes"); 

For iOS: check this out.

Alternatives:

  1. Clear the session cookie via javascript directly or indirectly (check this - JQuery Cookie clearing )
  2. Phonegap/Cordova plugin that allows you to clear cookies of the webview...see this

Upvotes: 13

Related Questions