1

I am stuck in very simple issue , not able to get the clue hence need your suggestions. So I am trying to authenticate lets say GoogleDrive APIs for that I use net.openid.appauth.AuthorizationRequest I create an Pending intent and pass this to authorization service to performAuthorizationRequest.Below is the sample code for the same :

AuthorizationServiceConfiguration serviceConfiguration = new AuthorizationServiceConfiguration(
        Uri.parse(AUTH_ENDPOINT_URL),
        Uri.parse(TOKEN_ENDPOINT_URL)
);
Uri redirectUri = Uri.parse(getRedirectURI());
AuthorizationRequest.Builder builder = new AuthorizationRequest.Builder(
        serviceConfiguration,
        “Xyzzy….”,
        AuthorizationRequest.RESPONSE_TYPE_CODE,
        redirectUri
);

    builder.setScopes("https://www.googleapis.com/auth/drive", "https://www.googleapis.com/auth/drive.readonly");

AuthorizationRequest request = builder.build();
if (authorizationService != null) {
    authorizationService.dispose();
}
authorizationService = new AuthorizationService(activity);

Intent postAuthorizationIntent = new Intent(“HANDLE_YOUTUBE_AUTHORIZATION_RESPONSE_ACTION”);
postAuthorizationIntent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_CLEAR_TOP);
PendingIntent pendingIntent = PendingIntent.getActivity(context, request.hashCode(), postAuthorizationIntent, 0);
authorizationService.performAuthorizationRequest(request, pendingIntent);

Now this redirects to the Permission page of google drive and when I click on allow (permissions) I shall receive an intent back to the Activity which is added in pendingIntent . I can see that the RedirectUriReceiverActivity activity's onCreate is called and it sends the intent to the target

try {
    target.send(this, 0, responseData);
} catch (CanceledException var10) {
    Logger.errorWithStack(var10, "Unable to send pending intent", new Object[0]);
} 

above try catch code from RedirectUriReceiverActivity onCreate() function

Code from Manifest file: RedirectUriReceiverActivity is added in Manifest file :

<activity android:name="net.openid.appauth.RedirectUriReceiverActivity">

and have added view browse permission as well.

The issue which I am facing is I am not able to receive this intent. I override onNewIntent() in my activity where I expect this pendingIntent to return. But no help. Do I need to override any other function or am I missing something.

The AuthorizationService API is called from the Fragment that is created in the activity.

Can anyone suggest why the intent is not received in the Activity. Any help/guidance is highly appreciated.

David Wasser
  • 93,459
  • 16
  • 209
  • 274
Dixit
  • 71
  • 1
  • 5
  • What `Activity` should be opened when the `PendingIntent` is triggered? – David Wasser Jan 23 '20 at 16:47
  • You've created an `Intent` like this: ` new Intent(“HANDLE_YOUTUBE_AUTHORIZATION_RESPONSE_ACTION”);` What `Activity` should be opened with this `Intent`? – David Wasser Jan 23 '20 at 16:49
  • Actually this will open the GoogleDrive activity and this is taken care by `authorizationService.performAuthorizationRequest(request, pendingIntent); ` internally performAuthorizationRequest internally starts activity. This is the google client library API. The code that I have pasted above is in model and I have main Activity which internally creates a fragment and the above code is called from that fragment. I have overriden onNewIntent() in my main activity but nothing is received in that new intent. – Dixit Jan 23 '20 at 17:57
  • Thanks for the help. I was able to get the response with the different login credentials. I was using the wrong credentials and I provided API access on another credentials. When allowed with correct credentials, I received intent in onNewIntent() API and from intent I could fetch the response. – Dixit Feb 03 '20 at 11:35
  • I think we can close this discussion. – Dixit Feb 03 '20 at 11:35
  • @Dixit Hi I am in kind of similar situation, please have a look at following question https://stackoverflow.com/questions/62670226/onnewintent-is-never-gets-called-android – Karan Jul 02 '20 at 06:01

0 Answers0