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 @@ -96,6 +96,10 @@ public Task Launch(Uri uri) { tcsAuthorizationCodeResponse = new TaskCompletionSource(); + tcsAuthorizationCodeResponse.Task.ContinueWith(t => + { + RemoveBackKeyPressCallback(); + }, TaskScheduler.FromCurrentSynchronizationContext()); StartLoading(); browser.Navigate(uri); return tcsAuthorizationCodeResponse.Task; @@ -104,13 +108,16 @@ /// A callback handler for when the user presses the back key. void RootPage_BackKeyPress(object sender, System.ComponentModel.CancelEventArgs e) { - // Remove this callback. + e.Cancel = true; + tcsAuthorizationCodeResponse.SetCanceled(); + } + + /// Removes + void RemoveBackKeyPressCallback() + { PhoneApplicationFrame rootFrame = Application.Current.RootVisual as PhoneApplicationFrame; PhoneApplicationPage rootPage = rootFrame.Content as PhoneApplicationPage; rootPage.BackKeyPress -= RootPage_BackKeyPress; - - e.Cancel = true; - tcsAuthorizationCodeResponse.SetCanceled(); } } }