uber / uber/rides-android-sdk

Receiving onLoginCancel after successful login on some devices

Open
#73 6 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Java
Stars
293
Forks
132
PR merge metrics
No merged PRs in 30d

Description

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"));
}

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the flow on Android 4.4.2 with SDK 0.6.0, using the LoginManager.login call and the Activity's onActivityResult forwarding shown in the report. Trace how the successful permission response reaches MyLoginCallback and compare it with newer Android versions. Done means the same login attempt reaches onLoginSuccess rather than onLoginCancel on the affected devices.

Written by the indexing model from the issue text.

Assessment

Tech stack
android, java
Domain
authentication, mobile-dev
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.