Asif Sb
Asif Sb

Reputation: 805

How to authenticate user in Uber SDK in Android?

With reference to this link, I integrated the Uber sdk into my app.before that I registered my application in the Uber developer site got my client id and the client secret.

I added the below code in my application class:

UberSdk.initialize(this, "MY_CLIENT_ID");

UberSdk.setRedirectUri("MY_REDIRECT_URI");

UberSdk.setSandboxMode(true);

Then in my fragment:

oncreate():

accessTokenManager = new AccessTokenManager(getContext());
    loginManager = new LoginManager(accessTokenManager);
    List<Scope> scopes = new ArrayList<Scope>();
    scopes.add(Scope.PROFILE);
    scopes.add(Scope.RIDE_WIDGETS);

    Date expirationTime = new Date(System.currentTimeMillis());
    String token = "Token";
    AccessToken accessToken = new AccessToken(expirationTime, scopes, token);

    accessTokenManager.setAccessToken(accessToken);

    Log.d("ttt", "accessToken: " + accessTokenManager.getAccessToken());


    loginManager.loginWithScopes(getActivity(), scopes);

onActivityResult():

LoginCallback loginCallback = new LoginCallback() {
    @Override
    public void onLoginCancel() {
        // User canceled login
        Log.d("ttt", " User canceled login " );
        Toast.makeText(getContext(), "User canceled login", Toast.LENGTH_SHORT).show();
    }

    @Override
    public void onLoginError(@NonNull AuthenticationError error) {
        // Error occurred during login
        Log.d("ttt", "Error occurred during login" );
        Toast.makeText(getContext(),"Error occurred during login",Toast.LENGTH_SHORT).show();
    }

    @Override
    public void onLoginSuccess(@NonNull AccessToken accessToken) {
        // Successful login!  The AccessToken will have already been saved.
        Log.d("ttt", "Successful login! " );
        Toast.makeText(getContext(),"Successful login!",Toast.LENGTH_SHORT).show();
    }
};

loginManager.onActivityResult(requestCode, resultCode, data, loginCallback);

I have no idea how to add redirect uri and from where I will get the redirect uri. And what is the actual use of it (searched a lot still not clear with what it does).

Once I click the Uber ride button it navigates to some loginactivity and a popup shows up saying "There was a problem authenticating you".

What I am doing wrong here?

Upvotes: 0

Views: 573

Answers (1)

Ty Smith
Ty Smith

Reputation: 2594

Here's a great write up of what a Redirect URI is used for in Oauth 2.0. What's a redirect URI? how does it apply to iOS app for OAuth2.0?.

TLDR: Your application may exist on the web and for mobile app, and the redirect URI is the endpoint that is redirected back to after the flow is completed. For mobile clients, you could easily set your redirect URI to "http://localhost" in the Uber developer dashboard, since it doesn't have the same requirements as on the web.

We're investigating simplifying this further, so keep an eye out on our future releases!

Upvotes: 2

Related Questions