SimpleAuth icon indicating copy to clipboard operation
SimpleAuth copied to clipboard

Determine if Google Sign-In is cancelled

Open mr5z opened this issue 4 years ago • 2 comments

Hi, can we have a way of knowing if the Google auth is cancelled? Right now, it just throws a generic Exception with a message:

"Error Domain=com.google.GIDSignIn Code=-5 "The user canceled the sign-in flow." UserInfo={NSLocalizedDescription=The user canceled the sign-in flow.}"

mr5z avatar Sep 11 '19 02:09 mr5z

I am catching System.Threading.Tasks.TaskCanceledException in this case. Works for me.

trevoriancox avatar Nov 11 '19 19:11 trevoriancox

@trevoriancox this is how I authenticate with Google:

try {

OAuthApi api = ...

api.ResetData();
var account = await api.Authenticate();
if (!account.IsValid())
{
    return new DataResponse<AuthResponse>
    {
        ErrorType = HttpErrorType.Authentication
    };
}

var authAccount = account as OAuthAccount;

} catch (Exception ex) {

if (ex is TaskCanceledException)
{
    return new DataResponse<AuthResponse>
    {
        ErrorType = HttpErrorType.Cancelled
    };
}
// TODO hack. wait for the issue to be fixed
// https://github.com/Clancey/SimpleAuth/issues/101
if (ex.Message.Contains("com.google.GIDSignIn Code=-5"))
{
    ...
}

...

}

It does not go into if (ex is TaskCanceledException) part when I cancel the sign-in flow since I'm always receiving a generic type Exception where I need to make a hack.

mr5z avatar Nov 14 '19 02:11 mr5z