The Exception is throwed as follows:
Activity xamarin.auth.WebAuthenticatorActivity has leaked window [email protected] that was originally added here
android.view.WindowManager$BadTokenException: Unable to add window -- token [email protected] is not valid; is your activity running?
Work flow of Xamarin.Auth is as follows (I debugged inside the Xamarin.Auth source code):
1 -> You create an instance of Oauth2Authenticator, that will create an activty with a Webview inside. The Webview will open the Facebook login page.
2 -> You type login information and press Login.
3 -> You manually handle Completed event which fired by Xamarin.Auth if the login information was correct.
4 -> Xamarin.Auth finishs the activity.
5 -> Xamarin.Auth make a request to redirect_uri which was passed to Oauth2Authenticator.
As everyone can see, the step 4 & 5 is crazy. The author of Xamarin.Auth should fix this problem.
Posts
I ran into this recently. Do you have "NoHistory=true"? After I removed this it worked just fine for me. It most likely had to do with Android's activity lifecycle because once you navigate away you can't get back to it.
So I kept getting this randomly and on different versions of Android. I cloned Xamarin.Auth and commented what is inside of ActivityEx.cs's method "ShowError". I still need to research more, but that cleared it up for me. I will add an issue on it.
I should say that this is probably not the real issue though, I would have to debug more and see why ShowError is being called and that is the real issue.
James - any further update on this?
One of my testers is getting this same error that I can't reproduce. It looks like it's happening when I make a call to Google's https://www.googleapis.com/plus/v1/people/me/openIdConnect, so the initial Google login has completed successfully.
By adding a hook into the .Error method of the OAuth2Authenticator I can see that I am consistently getting this error when running on Android 2.3.3 when trying to make the openIdConnect call. The .Completed method is firing, so it looks like the initial Google login is good.
Expected access_token in response, but did not receive one.
It's working on KitKat
Hi,
I am trying to get authorized to access LinkedIn API. I could not figure out how to give a redirect url to my android app. Can anyone help me on what to provide as redirect url ?
Thank You
I was still getting this so decided to include the Xamarin.Auth.Android source in my solution as a project rather than linked DLL and 'have a hack'.
What I've found to get it to work on both 2.3 and 4.4 Android:
The OP issue is caused (as James points out) by an Alert in ActivityEx.cs. My hack for this - wrap it in a try/catch and just dump the output to Android log if there's an error.
My problem with Android 2.3 authentication failing with an "Expected access_token in response, but did not receive one." message. This seems to be caused by some of the redirect handling in WebRedirectAuthenticator.cs. On an initial call, the fragment parameter is nicely populated with access_token et al, but a secondary call is a plain Uri without the parameters. This overwrites the initial set and causes the error. My hack - simply ignore any calls that don't have the full fragment set expected.
Really cheap hacks, but for want of better understanding the reason behind the redirect hiding, it "works for me"! :-)
Some additional information. I updated my Authentication module to use one directly linked from the store rather than a downloaded one, not sure if it's updated or not. Here is the log from the latest crash from the user.
He has a Samsung Galaxy SII, witnesses the crash. I logged on with his credentials (he's a relative and trusts me!) on my Note II and have no crash, so it's not account related. I'm running an AOSP custom KitKat ROM, not sure yet what version he has.
The crash seems to occur on making a call to
Some additional information. I updated my Authentication module to use one directly linked from the store rather than a downloaded one, not sure if it's updated or not. Here is the log from the latest crash from the user.
He has a Samsung Galaxy SII, witnesses the crash. I logged on with his credentials (he's a relative and trusts me!) on my Note II and have no crash, so it's not account related. I'm running an AOSP custom KitKat ROM, not sure yet what version he has.
The crash seems to occur on making a call to
Any update on this?
Bump, has anyone found a solution other than including the source for the Auth library?
add this tag on your activity. NoHistory=false
Doesn't solve my problem at all. I am not using that in my activity.
for anyone who is still have this error and want for now to avoid it, use this:
auth.ShowUIErrors = false;
Does anybody has any solutions for this? I am using it with my Xamarin Forms project. It's an old project. Everything was well until I found this issue yesterday. With auth.ShowUIErrors = false; also its not working. The error is not consistent. Sometimes it runs well and sometimes it crashes the app. Can anybody please help.
Thanks
Well, got it resolved. If anybody need here is what I did-
Download the project from https://github.com/xamarin/Xamarin.Auth . Open the project Xamarin.Auth.Android.
In the ActivityEx.cs file modify the following line of code-
`public static void ShowError (this Activity activity, string title, string message)
{
try {
var b = new AlertDialog.Builder (activity);
b.SetMessage (message);
b.SetTitle (title);
b.SetNeutralButton ("OK", (s, e) => {
((AlertDialog)s).Cancel ();
});
var alert = b.Create ();
alert.Show();
}
catch(Exception ex) { }
In the file WebAuthenticatorActivity.cs modify the following code for OnReceivedSslError() in last line
try { builder.Create ().Show (); } catch { }
This resolved the issue.
Thanks