Liferay sceenlet pass session to webview

thumbnail
Nikhil Nishchal, modified 9 Years ago. Regular Member Posts: 179 Join Date: 6/22/12 Recent Posts
Hello,

I created a android application and using Login screenlet I am able to login and connect with Liferay instance.
Now, I want to show the loggedin user's private page using webview of android.

Is there any way to pass the session from login screenlet and open private page as loggedin in webview.

Or, is there any screenlet to show the page.

Thanks.
thumbnail
Victor Galan, modified 9 Years ago. Regular Member Posts: 144 Join Date: 6/14/16 Recent Posts
Hi!

Next week we are going to release a new version of the library, this new version includes a new login method, cookie login!
This new login type will let you solve your problem in an easy way, once we release it we can give you indications on how to do it emoticon

Kind regards,

Víctor
thumbnail
Nikhil Nishchal, modified 9 Years ago. Regular Member Posts: 179 Join Date: 6/22/12 Recent Posts
Hello Victor,

Thanks a lot, I will wait for the new update.

For now we got some workaround through following ways:
1. open https://localhost:8080?login=username&password=pass in webview
Or, we can go pass some encrypted token and based on auto login we can login.

Will cookie login work in liferay 6.2 and 7 both?

Thanks.
thumbnail
Jose M. Navarro, modified 9 Years ago. Regular Member Posts: 138 Join Date: 1/24/14 Recent Posts
Nikhil Nishchal:

Will cookie login work in liferay 6.2 and 7 both?


It will (hopefully), but we'll have official support only for Liferay 7
deyuan lu, modified 8 Years ago. New Member Posts: 11 Join Date: 11/14/17 Recent Posts
I also have such a problem, how to solve now?
thumbnail
Javier Gamarra, modified 8 Years ago. Expert Posts: 348 Join Date: 2/12/15 Recent Posts
Cookie login is the way emoticon

Available on the latest screens version emoticon
deyuan lu, modified 8 Years ago. New Member Posts: 11 Join Date: 11/14/17 Recent Posts
Thank you for your reply. However, for some reason, I can only use the 6.2 version, open the webview prompt and need to login,Can I get cookies on version 6.2.
thumbnail
Javier Gamarra, modified 8 Years ago. Expert Posts: 348 Join Date: 2/12/15 Recent Posts
Yes, it will also work on 6.2
deyuan lu, modified 8 Years ago. New Member Posts: 11 Join Date: 11/14/17 Recent Posts
I'm still confused by the web view's cookie, and here's how I actually use it.

Log in using screnntlet
<com.liferay.mobile.screens.auth.login.loginscreenlet android:id="@+id/login_screenlet" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_centerhorizontal="true" android:layout_below="@+id/include" liferay:basicauthmethod="screen_name" liferay:companyid="@string/id_company" liferay:layoutid="@layout/view_login_main"></com.liferay.mobile.screens.auth.login.loginscreenlet>


Step 1: how to get cookie from Liferay?
Step 2: how to put cookie into webview?
thumbnail
Javier Gamarra, modified 8 Years ago. Expert Posts: 348 Join Date: 2/12/15 Recent Posts
Step 1: how to get cookie from Liferay?

Using liferay:loginMode="cookie" in your LoginScreenlet

Step 2: how to put cookie into webview?

It's done automatically if you use that loginMode emoticon
deyuan lu, modified 8 Years ago. New Member Posts: 11 Join Date: 11/14/17 Recent Posts
When I using liferay:loginMode="cookie" in your LoginScreenlet,then login failed。
<com.liferay.mobile.screens.auth.login.loginscreenlet android:id="@+id/login_screenlet" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_centerHorizontal="true" android:layout_below="@+id/include" liferay:basicAuthMethod="screen_name" liferay:companyId="@string/id_company" liferay:loginMode="cookie" liferay:layoutId="@layout/view_login_main" />


Below is the login error message.
Could not login
com.liferay.mobile.android.exception.AuthenticationException: Cookie invalid or empty
at com.liferay.mobile.android.auth.CookieSignIn.parseResponse(CookieSignIn.java:143)
at com.liferay.mobile.android.auth.CookieSignIn.signIn(CookieSignIn.java:55)
at com.liferay.mobile.screens.auth.login.interactor.LoginCookieInteractor.execute(LoginCookieInteractor.java:33)
at com.liferay.mobile.screens.base.interactor.BaseInteractor.doInBackground(BaseInteractor.java:38)
at com.liferay.mobile.screens.base.interactor.BaseInteractor$1.run(BaseInteractor.java:31)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1133)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:607)
at java.lang.Thread.run(Thread.java:761)
thumbnail
Victor Galan, modified 8 Years ago. Regular Member Posts: 144 Join Date: 6/14/16 Recent Posts
Hi!

This error normally appears when the credentials are incorrect
I see that are you using screen_name as the basicAuthMethod, do you have that configured in the server too?

Regards
deyuan lu, modified 8 Years ago. New Member Posts: 11 Join Date: 11/14/17 Recent Posts
If don't use loginMode,I can login successfully
Is server needs to configure cookies related Settings.
thumbnail
Victor Galan, modified 8 Years ago. Regular Member Posts: 144 Join Date: 6/14/16 Recent Posts
It's not needed, what version of the library are you using?
deyuan lu, modified 8 Years ago. New Member Posts: 11 Join Date: 11/14/17 Recent Posts
android sdk 6.2
thumbnail
Victor Galan, modified 8 Years ago. Regular Member Posts: 144 Join Date: 6/14/16 Recent Posts
I meant the Liferay screens version, and the portal version?
deyuan lu, modified 8 Years ago. New Member Posts: 11 Join Date: 11/14/17 Recent Posts
liferay-screens:2.1.1
portal version:6.2
thumbnail
Victor Galan, modified 8 Years ago. Regular Member Posts: 144 Join Date: 6/14/16 Recent Posts
Can you execute this cURL request and tell me if you are receiving a correct status code?


curl -X POST \
  <your-liferay-server>/c/portal/login \
  -H 'Content-Type: application/x-www-form-urlencoded' \
  -H 'Cookie: COOKIE_SUPPORT=true;' \
  -d 'login=<screen-name>&amp;password=<password>'
</password></screen-name></your-liferay-server>
deyuan lu, modified 8 Years ago. New Member Posts: 11 Join Date: 11/14/17 Recent Posts
Hi
I receiver status code 302.
But if I use
<your-liferay-server>/login?p_p_id=58&amp;p_p_lifecycle=0&amp;p_p_state=maximized&amp;p_p_mode=view&amp;saveLastPath=false&amp;_58_struts_action=%2Flogin%2Flogin</your-liferay-server>

I can receiving a correct status code.
deyuan lu, modified 8 Years ago. New Member Posts: 11 Join Date: 11/14/17 Recent Posts
Hi,Is there a way to solve this problem now?
thumbnail
Victor Galan, modified 8 Years ago. Regular Member Posts: 144 Join Date: 6/14/16 Recent Posts
Can you try with the version 3.1.0 of screens?
deyuan lu, modified 8 Years ago. New Member Posts: 11 Join Date: 11/14/17 Recent Posts
Today I tried the latest version(3.1.0) and failed.
thumbnail
Victor Galan, modified 8 Years ago. Regular Member Posts: 144 Join Date: 6/14/16 Recent Posts
It's very strange because internally it is doing the same request that you did with the cURL and that worked

Can you try this now:


CookieAuthentication authentication =
			new CookieAuthentication("", "", "<your-screen-name>", "<your-password>");

		Session session = new SessionImpl("<your-server-url>", authentication);

		CookieSignIn.signIn(session, new CookieSignIn.CookieCallback() {
			@Override
			public void onSuccess(Session session) {
				Log.d("LOGIN", "Login correct");
			}

			@Override
			public void onFailure(Exception e) {
				Log.e("LOGIN", "Login error", e);
			}
</your-server-url></your-password></your-screen-name>


Regards
deyuan lu, modified 8 Years ago. New Member Posts: 11 Join Date: 11/14/17 Recent Posts
Thank you for your reply. I am sorry that the server is being upgraded today, and I will test this method immediately after the server has been restored.