/* * ============================================ * Event * ============================================ */ private void Browser_Navigating(object sender, System.Windows.Navigation.NavigatingCancelEventArgs e) { // We need to ignore all navigation that isn't to the redirect uri. if (!e.Uri.ToString().StartsWith(REDIRECT_URI, StringComparison.OrdinalIgnoreCase)) { return; } try { DropboxApi.OAuth2Response result = DropboxApi.DropboxOAuth2Helper.ParseTokenFragment(e.Uri); // The state in the response doesn't match the state in the request. if (result.State != this.oauth2State) { return; } this.accessToken = result.AccessToken; this.Uid = result.Uid; this.result = true; } catch (ArgumentException) { // There was an error in the URI passed to ParseTokenFragment } finally { e.Cancel = true; this.Close(); } }
public Task<bool> Claim(Uri uri, string documentTitle) { var cs = new TaskCompletionSource<bool>(); try { var result = DropboxOAuth2Helper.ParseTokenFragment(uri); if (result.State != _state) { // The state in the response doesn't match the state in the request. cs.SetResult(false); return cs.Task; } _oauthResponse = result; cs.SetResult(true); return cs.Task; } catch { cs.SetResult(false); return cs.Task; } }