Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Receiving onLoginCancel after successful login on some devices #73

Open
DaniloT opened this issue Mar 22, 2017 · 6 comments
Open

Receiving onLoginCancel after successful login on some devices #73

DaniloT opened this issue Mar 22, 2017 · 6 comments

Comments

@DaniloT
Copy link

DaniloT commented Mar 22, 2017

I am having an issue where some devices of mine receive onLoginCancel after a SSO attempt, even when the user clicks on "Allow" after the permission screen, though other devices it works as intended and I correctly receive onLoginSuccess. So far, it seems the issue is related to Android OS 4.4.2, as all 3 devices I have that presented this issue are on that version, and the successful ones were on higher OS versions. The devices that presented the error were:

  • Samsung Galaxy Ace 4 Lite Duos SM-G313M
  • Samsung Galaxy gt-s5310c
  • Samsung Tablet (though the tester did not specify which)

I am using sdk version 0.6.0 and the devices all have Uber app version v4.144.11 installed and working. The user just clicks login, uber app opens, asks for permission, user hits "Allow", gets sent back to login screen with "Login cancel" message. I have made a video showing the behavior (the message at the end reads "User cancelled the login" in portuguese, hope that is ok): https://youtu.be/Uh7oxd6Vz4s

Below is my login code extracted from my app (the screen is just some images/text with a login button)

public static final String CLIENT_ID = BuildConfig.CLIENT_ID;
public static final String REDIRECT_URI = "http://localhost:8000";
private static final String LOG_TAG = "LoginActivity";
private static final int CUSTOM_BUTTON_REQUEST_CODE = 1113;

private Button customButton;
private AccessTokenManager accessTokenManager;
private LoginManager loginManager;
private SessionConfiguration configuration;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_login);

    configuration = new SessionConfiguration.Builder()
            .setClientId(CLIENT_ID)
            .setRedirectUri(REDIRECT_URI)
            // same issue with PRODUCTION environment
            .setEnvironment(SessionConfiguration.Environment.SANDBOX)
            .setScopes(Arrays.asList(Scope.PROFILE, Scope.RIDE_WIDGETS))
            .build();

    validateConfiguration(configuration);

    accessTokenManager = new AccessTokenManager(this);

    //Use a custom button with an onClickListener to call the LoginManager directly
    loginManager = new LoginManager(accessTokenManager,
            new MyLoginCallback(),
            configuration,
            CUSTOM_BUTTON_REQUEST_CODE);

    customButton = (Button) findViewById(R.id.custom_uber_button);
    customButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            loginManager.login(LoginActivity.this);
        }
    });
}

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    Log.i(LOG_TAG, String.format("onActivityResult requestCode:[%s] resultCode [%s]",
            requestCode, resultCode));

    if (requestCode == CUSTOM_BUTTON_REQUEST_CODE) {
        //Allow each a chance to catch it.
        loginManager.onActivityResult(this, requestCode, resultCode, data);
    }
}

private class MyLoginCallback implements LoginCallback {

    @Override
    public void onLoginCancel() {
        Log.d(LOG_TAG, "Login cancel");
        Toast.makeText(LoginActivity.this, R.string.user_cancels_message, Toast.LENGTH_LONG).show();
    }

    @Override
    public void onLoginError(@NonNull AuthenticationError error) {
        Log.d(LOG_TAG, "Login error: " + error.name());
        Toast.makeText(LoginActivity.this,
                getString(R.string.login_error_message, error.name()), Toast.LENGTH_LONG)
                .show();
    }

    @Override
    public void onLoginSuccess(@NonNull AccessToken accessToken) {
        Intent myIntent = new Intent(LoginActivity.this, Main.class);
        myIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        myIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK);
        startActivity(myIntent);
    }

    @Override
    public void onAuthorizationCodeReceived(@NonNull String authorizationCode) {
    }
}

/**
 * Validates the local variables needed by the Uber SDK used in the sample project
 * @param configuration
 */
private void validateConfiguration(SessionConfiguration configuration) {
    String nullError = "%s can't be empty";
    String sampleError = "Please update your %s in the gradle.properties of the project before " +
            "using the Uber SDK Sample app. For a more secure storage location, " +
            "please investigate storing in your user home gradle.properties ";

    checkNotNull(configuration, String.format(nullError, "SessionConfiguration"));
    checkNotNull(configuration.getClientId(), String.format(nullError, "Client ID"));
    checkNotNull(configuration.getRedirectUri(), String.format(nullError, "Redirect URI"));
    checkState(!configuration.getClientId().equals("insert_your_client_id_here"),
            String.format(sampleError, "Client ID"));
    checkState(!configuration.getRedirectUri().equals("insert_your_redirect_uri_here"),
            String.format(sampleError, "Redirect URI"));
}
@tyvsmith
Copy link
Member

tyvsmith commented Apr 4, 2017

Hey @DaniloT, sorry for the delay, I was OOO. I think you may be getting an intent flag into the behavior so onActivityResult is being called with a cancel. Please see http://stackoverflow.com/questions/7910840/android-startactivityforresult-immediately-triggering-onactivityresult and validate your activity flags in your manifest/programmatically.

@DaniloT
Copy link
Author

DaniloT commented Apr 6, 2017

@tyvsmith thanks for the reply, but I am not setting any flags in my manifest for singletask or singletop, and I commented out all my intent calls to simplify the screen as much as possible (so no intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK) being called either), and I am still getting this error on android 4.4.2 devices. Also, I placed a log.d inside onActivityResult and it is not being called as the login screen is launched like on that issue, it is properly called after it ends, but with resultCode 0 (Activity.RESULT_CANCELED) and a null data intent.

Below my login activity as it is on the manifest (it is the activity that launches the app)

<activity
        android:name=".LoginActivity"
        android:screenOrientation="portrait">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.DEFAULT" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>

@priyanshugupta45
Copy link

priyanshugupta45 commented Apr 19, 2017

Hi there facing the same issue as specified by @DaniloT, have you resolved it?

@DaniloT
Copy link
Author

DaniloT commented Apr 19, 2017

@priyanshugupta45 For me I had to limit my app on the manifest to only work on androids with api versions 20+ as the issue persists on apis under that version, haven't received a reply about this issue since that last one from @tyvsmith 15 days ago.

@tyvsmith
Copy link
Member

Sorry for the delay folks, this is on our roadmap to investigate and try to resolve if necessary early next week.

@luckcoolla
Copy link

luckcoolla commented May 19, 2017

Hello,

I've faced the issue on Samsung Tab 3 devices (OS 4.4.2).
I see the problem both in webView, when I'm trying to get auth code and then to get access token.
WebView is being showing, I fill-in the e-mail/password fields, than I have Permissions confirmation screen and both DENY and ALLOW button are not clickable. There is nothing to show from logcat. Meanwhile the form is working on phone Samsung S3(OS 4.3) and Nexus 7(4.4.4).
Just to clarify, here I'm talking about this login option:
loginManager.loginForAuthorizationCode(LoginActivity.this);

Then I've tried to switch login option to just sign-in using installed Uber app. I've just changed the call to this one:

loginManager.login(LoginActivity.this);

like @DaniloT did. And I see onLoginCancelled callback method being called when user clicks ALLOW button on the permissions confirmation screen.

This means There is no option to get signed-in to uber integrated app on the Samsung Tab 3.
I hope, webView issue will be fixed in the current issue scope, if no - please @tyvsmith tell me, I'll create a separate issue on github

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants