Saving credentials in Android / jQuery Mobile App

We are porting the jQuery mobile app using the Webview control in Android. The jQuery mobile app has a login page. We want to allow the user to save their login information.

The trick is that the client would prefer that we do not use cookies for this.

Solution / Problem No. 1:

We thought about the possibility of creating an Android login screen that calls the authentication service and stores the token. Then the token is passed to webview via querystring in the url property. The jQuery mobile app can then grab the token from the query string and validate it, allowing you to bypass the login screen of the mobile app.

The problem with this, however, is this: what happens when the user exits the application through the jQuery mobile application? How can a mobile application inform the Android wrapper about the removal of a token?

Solution # 2, but the same problem

The same Android login screen, but instead of passing it using the query string parameter, use javascript on the Android side, going through the Webview DOM and fill in the username and password on the mobile jQuery login screen. If this token exists on the Android side when the application starts, just bypass the Android login screen and automatically fill in the user credentials.

This problem still has the same problem: the user manually logs out.

Don't we think about it right?

Ideas?

+4
source share
1 answer

You can use your localstorage webview. You must include it in your webview using the WebViewSettings class:

WebSettings settings = webview.getSettings(); settings.setDomStorageEnabled(true); 

You should now have access to localStorage with javascript, as in any other browser that supports it:

 window.localStorage // Set value window.localStorage.setItem("username", "XXX"); // getting the value var username = window.localStorage.getItem("username"); 

Alternative 2: Create a javascript interface for your applications. This will allow you to create and call a javascript function that runs Java code in an Android application. This section is described here: http://developer.android.com/guide/webapps/webview.html in the section "Linking JavaScript code to Android code"

+3
source

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


All Articles