Android WebView loadUrl after postUrl - android

I have a problem using loadUrl after postUrl.
First I use postUrl to login to a website and after that I want to load another page from the same website with loadUrl. But after using loadUrl Im asked again to login.

Probably you need to handle cookie with WebView.

You need to store the COOKIE returned by the POST request (i.e., the login request). Then, whenever you send a GET request, you need to pass along the cookie so the sever knows you've already logged in.

Related

How to manage http(server side) session in android?

in my application I'm having three activities where first activity is for an intro, 2nd one is login/register and the third one is webView. how can I manage the session between all three activities? when someone login in login activity server will send the JSESSIONID in the cookies. how to use that same JSESSIONID and set it to webView cookies.
I'm using volley JsonObjectRequest
How session can be managed in andorid:
One of the way for session management in android is by Cookies.
The flow is simple, Whenever the User is successfully logged in then in response of that login API call you will get a Response Header named set-cookie which is the newly generated sessionId by the server. You can save it in SharedPreferences and then on every next API call Headers send that same cookie by the key cookie and the value that have saved in SharedPreferences.
How you can set the cookie to WebView:
In your case you have a WebView that you want to set the Cookie so check this link:
Android WebView Cookie Problem
How you can get and Set the headers in Volley
check this link:
https://github.com/google/volley/issues/37

Oauth2 Redirect URI for android application

I have created my own webservice which is protected by Oauth2. I am currently using restlet for this. It makes sense providing a redirect url when you are developing a javascript client on a certain url, but what redirect uri do you provide when you are calling from a WebView.
I currently just make it redirect to localhost and register that to the oauth authorization server. Can anyone tell me if that is the correct way of handling this or am I getting this completely wrong? The redirect page can ofcourse not be found on the android device, but you can fetch the token from the url which was appended to the localhost url.
you can make your own URL schema and use it for redirect URL check this link for customize your schema

PhoneGap redirect From server html file to local file

I am in the process of developing an iPhone PhoneGap application and have stumbled into a problem redirecting the user after login.
The flow is as follows:
Application is loading.
I am redirecting the user to a login page which is located on a remote server and passing a parameter of the current page so the user will be redirected after a successful login.
e.g. http://www.myloginserver.co.il?ret='this is the url of the local html file'.
The problem is I cant get the login page to redirect back to the local html.
i have tried passing the following urls:
window.location.href
window.location.href.substring(window.location.href.indexOf("www/")
"file:////" + window.location.href.substring(window.location.href.indexOf("www/")
Has anyone encountered this problem?
Thanks,
Udi
Interesting question. I'm not sure if it is possible...what I would do instead is create the login form locally in your /www/ and use AJAX to query the server and see if they were able to login. Then in the callback function of your AJAX request you can determine if you can send them to the next page or if they need to retry the login.

carry forms authentication cookie over from HttpClient (webapi call) to WebView

I have created an android app that is using a custom-rolled authentication method by calling a web service (webapi on .net mvc 4) with HttpClient. When the user is authenticated, the action method on the server is setting the forms authentication cookie and then returns a user model back to the android client. That user model contains the internal user id and a few other properties.
After the user is authenticated, I'm opening up a WebView on android to serve up a viewport for some simple navigation elements. That WebView needs to be handed the authentication cookie from the webapi call in the previous step. I assume that the forms authentication cookie is being held in the HttpClient (though I can't confirm this) and if so, is there a way to pass that cookie over to the WebView so the web page that is served up in the WebView knows who the user is based on the first step?
If this isn't possible, can someone guide me with some steps to make this work.
TIA
This looks like a very similar problem. Set a cookie to a webView in Android.
Hopefully this can assist you.

Silently authentication from webview

Here's what I want to have figured out : I'm using a webview to access a feature of a site that requires authentication. Therefore whenever that particular link is loaded the login page is displayed . Is is possible to somehow authenticate silently so that the particular feature is displayed directly ? Perhaps by using the "webView.setHttpAuthUsernamePassword" (which does not seem to work for me, or I don't do it right) or by making some POST or GET before I load the page , or other possibility ?
On logging in the server is simply supposed to send me a cookie.
That method only works for HTTP Basic Auth, not for form-based login.
Your best bet would be to use the onLoadResource method of the WebViewClient to detect that the page is about to load, then override the content of the WebView using loadData with a chunk of HTML/js that posts to the login form with the proper parameters, then detect the successful cookie return and forward on to the original url.
Depending on the site it may be messy: you may have to set the proper referer headers or CSRF tokens and other things of that nature.
Good luck.
See, you could do the task this way, I am not sure if this is what you want:
#Override
public void onReceivedHttpAuthRequest(
WebView view,
HttpAuthHandler handler,
String host,
String realm) {
String currentUrl = yourWebView.getUrl();
if(currentUrl.equals("www.yourwebsite.com")){
handler.proceed("username","password");
}
}

Categories

Resources