RE: Oauth2 login failed

László Tóth, modified 6 Years ago. Junior Member Posts: 36 Join Date: 5/9/19 Recent Posts
I tried to log in to life portal (7.1) via SDK on android.
implementation 'com.liferay.mobile:liferay-android-sdk:7.1.3'
implementation 'com.liferay.mobile:liferay-android-oauth:1.3.0'
implementation 'com.liferay.mobile:liferay-mobile-sdk-services:1.0'

I registreted a mobile app in portal's oath administration menu, created id and secret key.

When I try to log in like this:
OAuth2SignIn.signInWithUsernameAndPassword("<user_email>","<user_pwd>",new SessionImpl(SERVER),ID,SECRET,new ArrayList<string>(),new SessionCallback() {
  @Override
  public void onSuccess(Session newSession) {
    session=SessionContext.createOAuth2Session(newSession);
    LOG.info("LogIn success: " + session);
    LOG.info("LogIn success: " + SessionContext.isLoggedIn());

    loadUserData(callback);
  }

  @Override
  public void onFailure(Exception e) {
    e.printStackTrace();
    logout();
  }
});</string></user_pwd></user_email>
The login always fail with com.liferay.mobile.android.exception.ServerException: 
  at com.liferay.mobile.android.auth.oauth2.TokenRequester.parseResponse(TokenRequester.java:113)
  at com.liferay.mobile.android.auth.oauth2.TokenRequester.access$300(TokenRequester.java:25)
  at com.liferay.mobile.android.auth.oauth2.TokenRequester$1.onResponse(TokenRequester.java:99)
  at com.squareup.okhttp.Call$AsyncCall.execute(Call.java:177)
  at com.squareup.okhttp.internal.NamedRunnable.run(NamedRunnable.java:33)
  at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
  at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
  at java.lang.Thread.run(Thread.java:764)

When I try to log in as guest, like this: 

OAuth2SignIn.clientCredentialsSignIn(new SessionImpl(SERVER),ID,SECRET,new ArrayList<string>(),new SessionCallback() {
  @Override
  public void onSuccess(Session newSession) {
    session=SessionContext.createOAuth2Session(newSession);
    LOG.info("LogIn Guest success: " + session);
  }

  @Override
  public void onFailure(Exception e) {
    e.printStackTrace();
    logout();
  }
});</string>
the login is successful.

Why can't I log in with user / pwd?

Thanks for your help!
thumbnail
Victor Galan, modified 6 Years ago. Regular Member Posts: 144 Join Date: 6/14/16 Recent Posts
Hey!

​​​​​​​Can you share your oauth2 configuration? From the server
László Tóth, modified 6 Years ago. Junior Member Posts: 36 Join Date: 5/9/19 Recent Posts
I solved the problem. I use createBasicSession to authenticate user with email and pwd. I only use OAUTH2 credentials for guest users.