Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

A task was cancelled #41

Closed
Fr2eman opened this issue Sep 8, 2017 · 32 comments
Closed

A task was cancelled #41

Fr2eman opened this issue Sep 8, 2017 · 32 comments

Comments

@Fr2eman
Copy link

Fr2eman commented Sep 8, 2017

I have a problem with login with google. Exception throws when i am trying to login
Exception: "A task was cancelled" after i try call

var account = await AuthAsync(google);

I have tried to check example. But It throws the same exception.

@Clancey
Copy link
Owner

Clancey commented Sep 8, 2017

Is this on device or on an emulator? iOS or Android? Also, what api are you using? the standard Google Api, or did you activate the native google auth?

@Fr2eman
Copy link
Author

Fr2eman commented Sep 11, 2017

Android. This issue reproduces on devices and emulator. I use standard Google Api.

FindViewById<Button>(Resource.Id.loginGoogleNative).Click += async (sender, e) =>
  {
         // Create an OAuth credential and use its clientId
	var clientId = "419855213697-uq56vcune334omgqi51ou7jg08i3dnb1.apps.googleusercontent.com";

	var google = new SimpleAuth.Providers.GoogleApi("google", clientId) {//, "UwQ8aUXKDpqPzH0gpJnSij3i") {
                Scopes = new [] { "https://www.googleapis.com/auth/userinfo.profile" }
        };

        var account = await AuthAsync(google);
        var user = await google.GetUserInfo();
        // .. Do something with account
};
async Task<Account> AuthAsync(OAuthApi api)
  {
        Account result = null;
	try {
		result = await api.Authenticate ();
		Toast.MakeText (this, "Successfully Authenticated!", ToastLength.Long).Show ();
	} catch (TaskCanceledException) {
		Toast.MakeText (this, "Authentication Canceled!", ToastLength.Long).Show ();
	}
        catch (Exception ex)
        {
              Console.WriteLine(ex);
              Toast.MakeText(this, "Authentication Faild!", ToastLength.Long).Show();
        }

        if (result != null)
                Console.WriteLine(await result.ToJsonAsync());

         return result;
}

When i am trying to login, app always throws TaskCanceledException.
When i am trying to login in second time, app crashes with message "A task was cancelled".
You can check it on your example in project.

@Clancey
Copy link
Owner

Clancey commented Sep 11, 2017

I have tried multiple times, on both Sample.Droid, and Sample.Forms.Droid. I cannot reproduce this. Can you try debugging and see where the task canceled came from?

@Clancey Clancey closed this as completed Sep 11, 2017
@brittonbeckham
Copy link

@Fr2eman I just installed the SimpleAuth tonight and am testing the Google auth and am getting this exact same issue. Did either of you figure this out? I'm debugging on a physical device.

var scopes = new[]
{
	"https://www.googleapis.com/auth/userinfo.email",
	"https://www.googleapis.com/auth/userinfo.profile"
};
var api = new GoogleApi("google", "272476888206-4lulgfh45cjgqbnf3cnuddkbf3isi3so.apps.googleusercontent.com")
{
	Scopes = scopes
};
var account = await api.Authenticate();			

My app crashes and stack trace leads to:

OAuthApi+<PerformAuthenticate>d__32.MoveNext ()
System.Threading.Tasks.TaskCanceledException: A task was canceled.

@Clancey
Copy link
Owner

Clancey commented Oct 17, 2017

I am unable to duplicate this, would you mind debugging the sample and let me know what is calling canceled? I can help fix it if I can duplicate it. I do accept pull requests!

Also you should always Try Catch the real Authenticate call, incase the user really does cancel logging in.

@brittonbeckham
Copy link

brittonbeckham commented Oct 17, 2017

So I am using Clancey.SimpleAuth 1.0.40 and Clancey.SimpleAuth.Google.Droid 1.0.9 -- I don't see symbols for these nugets.

The exception is being thrown from the OnActivityResult method:
SimpleAuth.Native.OnActivityResult(requestCode, resultCode, data);

I tried a try {} catch{} on that line and forcing an "OK" result in the catch block, but the catch block is just skipped and it still throws an unhandled exception.

@Clancey
Copy link
Owner

Clancey commented Oct 17, 2017

Sorry for debugging info, would you mind cloning the repo and running one of the Android samples? See if you can still duplicate it. They reference the source. Also on the next version I will start shipping debug symbols. That has been on my todo list for awhile.

@brittonbeckham
Copy link

Will try that now.

@brittonbeckham
Copy link

In my own app, I hit login as google, it shows me the prompt to select a Google account. I tap the account I want to login as. Then the app crashes.

However, in your sample project Sample.Forms.Droid, the login worked fine... I tap Google button, it shows me the prompt to select a Google account. I tap the account I want to login as. It then shows me a success alert.

@Clancey
Copy link
Owner

Clancey commented Oct 17, 2017

:( That's the problem I have been having. I cannot duplicate it. You could try changing the secrets in the sample, and the signing so it matches. Maybe it is a config issue?

Or you can try referencing SimpleAuth from source in your app? That may lead to the exception.

@brittonbeckham
Copy link

I can try swapping the client Id/Secret... but can you tell me what GoogleApi.NativeClientSecret is?

@Clancey
Copy link
Owner

Clancey commented Oct 17, 2017

There isn't one. So here is how that works. Google doesn't require the secret unless you are going to refresh the tokens yourself. (It actually works better if you pass the secret). If you don't pass in a secret, Simple Auth handles it just fine. That variable is a temp value used to determine if you are not using a secret.

@brittonbeckham
Copy link

Ok swapping your clientId/secret with mine gives me a "user cancelled" alert. It appears I don't have something right with my creds. Thoughts?

@Clancey
Copy link
Owner

Clancey commented Oct 17, 2017

That could be. Getting that stuff right can be a pain. How did you generate your secret? I have a section in the readme on it.

@brittonbeckham
Copy link

Honestly, I read that like 3 times and I'm sorely confused at what to make. I already had a Web Application credential so I didn't make a new one. I made a new "App" credential and pulled the SHA1 signature from my signing key and put it in the there... don't know what I'm doing wrong ... or what I'm doing at all :)

@brittonbeckham
Copy link

Which clientId goes into the SimpleAuth ??? the Web Application one or the App one?

@Clancey
Copy link
Owner

Clancey commented Oct 17, 2017

Let me find the screenshot of the samples. Trying to remember

@Clancey
Copy link
Owner

Clancey commented Oct 17, 2017

Pass in the Web ClientID/Secret. The rest should auto work from the signing keys.

@Clancey
Copy link
Owner

Clancey commented Oct 17, 2017

Also they need to be in the same project. The Android and WebAPI should both be listed on the same tab here.

@brittonbeckham
Copy link

That is what I have, but I don't think I got the right signing key... what is the keystore for debug mode? I used my production keystore and I dont' think that works. Super confused here, but thanks for helping me troubleshoot this.

image

As you can see, I had the web application one created last year, and I just created the "Android" one today.

@Clancey
Copy link
Owner

Clancey commented Oct 17, 2017

So the key signing has to be right. When you created the android app, it asks for the fingerprint. For debugging you can find information about the default keys here You can change the debug key and use your production key there.

@Clancey
Copy link
Owner

Clancey commented Oct 17, 2017

Also the default Xamarin Debug keys are different on every machine. So use your keys signing stuff.

@Clancey
Copy link
Owner

Clancey commented Oct 17, 2017

You will notice, I include the keystore to ensure it works for everyone testing. CSProj using it for signing

@brittonbeckham
Copy link

Ok so does this mean I need to build my app with the same keystore when debugging and for production? Can I have two "app" in the google credentials store (one for dev and one for prod)?

@brittonbeckham
Copy link

brittonbeckham commented Oct 17, 2017

Looks like that last piece of advice helped. I swapped out my debug configuration in my CSProj to use the product keystore file in the build... restarted the app and it worked! Thanks a lot!

@Clancey
Copy link
Owner

Clancey commented Oct 17, 2017

I would sign both Debug and Production the same. As I said, default debug keys change per machine. Which would make things confusing as you switch dev machines and build servers.

@brittonbeckham
Copy link

Great point, I'll follow this approach.

One last thing. I'm not getting any UserData back in the account object. What would cause this?

@Clancey
Copy link
Owner

Clancey commented Oct 17, 2017

Using the native login the data you get back is limited. However there is a convenience method: https://github.com/Clancey/SimpleAuth/blob/master/src/SimpleAuth/Providers/Google.cs#L123-L134

@brittonbeckham
Copy link

Perfect

@brittonbeckham
Copy link

Huge help today! Much thanks my friend.

@mhmd-azeez
Copy link

mhmd-azeez commented Jan 13, 2018

It's also nice to know that if there is no internet connection and the user has never signed in into the app, when the user clicks sign in a pop up shows all the users account but when he/she clicks on one of them it results in a TaskCanceledException. So make sure there is internet connection before signing in.

@axanth
Copy link

axanth commented Feb 20, 2019

Hi there I am facing the same issue. Although it worked it suddenly started to throw this exception.
The things that changed are 1) I updated to the latest Packages Xamarin.Forms and SimpleAuth. and I created an Archive and publish the app as a Beta release to the store..... Is there a chance to be the sign issue you mentioned?? If yes can you be more specific about the solution steps? Thanks in advance

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants