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
*
Yes, you are right that I manage to get the access token using the authorization code. I have gone through your REST web service doc and found out that using a POST request to server with a valid authorization code, I can get the required parameters to generate an access token.
Here is my updated code for getting auth code in the callback and request server using HTTP POST method to generate access token...
The problem with the API is there is no mention of requesting server to POST method for getting the access token. Also there is no mention of the onAuthorizationCodeReceived() callback method in the doc.
And also, there should be a JAVA interface for doing this operation as everything else is doing that (OR at least in the doc they should mention the process).
Whatever, I have found out the solution yesterday evening on my own (14 hours ego) and now (today morning) I am posting the solution. Hope, this will help someone.
NOTE: I have used ION library as a network client.
You posted SO question as well. Plase, use the authorization code as per this sample you submitted - because it is confirmed from our logs that you managed to get a valid access token as a response (KA.eyJ2ZXJzaW9uIjoyLCJ*****). Also, you successfully initiate new ride request. So code you used to achieve it is a valid code.
If this does not answer your question please check Android SDK sample.