Index: Src/GoogleApis.Auth.WP/OAuth2/WebAuthenticationBrokerUserControl.xaml.cs
===================================================================
--- a/Src/GoogleApis.Auth.WP/OAuth2/WebAuthenticationBrokerUserControl.xaml.cs
+++ b/Src/GoogleApis.Auth.WP/OAuth2/WebAuthenticationBrokerUserControl.xaml.cs
@@ -36,6 +36,10 @@
public WebAuthenticationBrokerUserControl()
{
InitializeComponent();
+
+ PhoneApplicationFrame rootFrame = Application.Current.RootVisual as PhoneApplicationFrame;
+ PhoneApplicationPage rootPage = rootFrame.Content as PhoneApplicationPage;
+ rootPage.BackKeyPress += RootPage_BackKeyPress;
}
/// Displays the loading animation.
@@ -66,7 +70,16 @@
{
if (!tcsAuthorizationCodeResponse.Task.IsCompleted)
{
- tcsAuthorizationCodeResponse.SetException(e.Exception);
+ // See https://code.google.com/p/google-api-dotnet-client/issues/detail?id=431.
+ // If we encounter a null exception, cancel the task because the WP app crashed.
+ if (e.Exception != null)
+ {
+ tcsAuthorizationCodeResponse.SetException(e.Exception);
+ }
+ else
+ {
+ tcsAuthorizationCodeResponse.SetCanceled();
+ }
}
}
@@ -86,5 +99,17 @@
browser.Navigate(uri);
return tcsAuthorizationCodeResponse.Task;
}
+
+ /// A callback handler for when the user presses the back key.
+ void RootPage_BackKeyPress(object sender, System.ComponentModel.CancelEventArgs e)
+ {
+ // Remove this callback.
+ PhoneApplicationFrame rootFrame = Application.Current.RootVisual as PhoneApplicationFrame;
+ PhoneApplicationPage rootPage = rootFrame.Content as PhoneApplicationPage;
+ rootPage.BackKeyPress -= RootPage_BackKeyPress;
+
+ e.Cancel = true;
+ tcsAuthorizationCodeResponse.SetCanceled();
+ }
}
}