I am configuring uber sdk with Request scope (Restricted). In the LoginManager callback method onAuthorizationCodeReceived() I am getting authorizationCode as a parameter, whereas the onLoginSuccess() callback method is not being called.
Here is my code...
config = initialiseUberSDK();
accessTokenManager = new AccessTokenManager(this);
loginManager = new LoginManager(accessTokenManager,
new LoginCallback() {
@Override
public void onLoginCancel() {
Toast.makeText(CustomActivity2.this, "Login cancelled", Toast.LENGTH_LONG).show();
}
@Override
public void onLoginError(@NonNull AuthenticationError error) {
Toast.makeText(CustomActivity2.this,
"Error: "+error.name(), Toast.LENGTH_LONG)
.show();
}
@Override
public void onLoginSuccess(@NonNull AccessToken accessToken) {
Toast.makeText(CustomActivity2.this, "Login success",
Toast.LENGTH_LONG)
.show();
createSession();
}
@Override
public void onAuthorizationCodeReceived(@NonNull String authorizationCode) {
Toast.makeText(CustomActivity2.this, "Your Auth code is: "+authorizationCode,
Toast.LENGTH_LONG)
.show();
}
},
config,
1113).setRedirectForAuthorizationCode(true);
customButton = (Button) findViewById(R.id.button);
customButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
loginManager.login(CustomActivity2.this);
}
});
And here is the initialiseUberSDK() method...
private SessionConfiguration initialiseUberSDK() {
config = new SessionConfiguration.Builder()
.setClientId(getResources().getString(R.string.client_id))
// .setServerToken(getResources().getString(R.string.server_token))
// .setClientSecret(getResources().getString(R.string.client_secret))
.setRedirectUri(getResources().getString(R.string.redirect_url))
.setEnvironment(SessionConfiguration.Environment.SANDBOX)
.setScopes(Arrays.asList(Scope.PROFILE, Scope.RIDE_WIDGETS, Scope.REQUEST))
.build();
// UberSdk.initialize(config);
return config;
}
Here onLoginSuccess() method never being called. Only onAuthorizationCodeReceived() method is being called (with access token object being null).
My question is
how to generate access token using the authorization code?
Below is the java doc of the onAuthorizationCodeReceived() method...
*
public void onAuthorizationCodeReceived(@NonNull String authorizationCode)
Description copied from interface: LoginCallback Called when authorization code has been returned to the redirect uri. AccessToken must be retrieved using Client Secret, see https://developer.uber.com/docs/authentication#section-step-two-receive-redirect Specified by: onAuthorizationCodeReceived in interface LoginCallback Parameters: authorizationCode - the authorizationCode that can be used to retrieve AccessToken
*