private async void AuthorizeWithCallback(string oauthVerifier) { if (_authorizeStep == AuthorizeStep.TwitterAuthorize) { Tokens tokens; try { tokens = await _twitterOAuthSettion.GetTokensAsync(oauthVerifier); } catch { await new MessageDialog(_resourceLoader.GetString("AuthorizePopup_OAuthAuthorizeError")) .ShowAsync(); return; } finally { AuthorizePopupAuthorizeButton.IsEnabled = true; } _accountInfo = new AccountInfo { ConsumerKey = tokens.ConsumerKey, ConsumerSecret = tokens.ConsumerSecret, AccessToken = tokens.AccessToken, AccessTokenSecret = tokens.AccessTokenSecret, ScreenName = tokens.ScreenName, UserId = tokens.UserId, Service = "Twitter", Instance = "" }; } else if (_authorizeStep == AuthorizeStep.MastodonAuthorize) { try { var auth = await _mastodonOauthSettion.ConnectWithCode(oauthVerifier); var client = new MastodonClient(_mastodonAppRegistration, auth); var user = await client.GetCurrentUser(); _accountInfo = new AccountInfo { ConsumerKey = _mastodonAppRegistration.ClientId, ConsumerSecret = _mastodonAppRegistration.ClientSecret, AccessToken = auth.AccessToken, AccessTokenSecret = "", ScreenName = user.UserName, UserId = user.Id, Service = "Mastodon", Instance = _mastodonOauthSettion.Instance }; } catch { await new MessageDialog(_resourceLoader.GetString("AuthorizePopup_OAuthAuthorizeError")) .ShowAsync(); return; } finally { AuthorizePopupAuthorizeButton.IsEnabled = true; } } _authorizeStep = AuthorizeStep.Exit; }
private async void AuthorizePopupAuthorizeButton_Click(object sender, RoutedEventArgs e) { var pin = AuthorizePopupAuthorizePinTextBox.Text.Trim(); if (string.IsNullOrWhiteSpace(pin)) { await new MessageDialog(_resourceLoader.GetString("AuthorizePopup_PincodeIsEmpty")).ShowAsync(); return; } AuthorizePopupAuthorizeButton.IsEnabled = false; if (_authorizeStep == AuthorizeStep.TwitterAuthorize) { try { var tokens = await _twitterOAuthSettion.GetTokensAsync(pin); _accountInfo = new AccountInfo { ConsumerKey = tokens.ConsumerKey, ConsumerSecret = tokens.ConsumerSecret, AccessToken = tokens.AccessToken, AccessTokenSecret = tokens.AccessTokenSecret, ScreenName = tokens.ScreenName, UserId = tokens.UserId, Service = "Twitter", Instance = "" }; } catch { await new MessageDialog(_resourceLoader.GetString("AuthorizePopup_OAuthAuthorizeError")) .ShowAsync(); return; } finally { AuthorizePopupAuthorizeButton.IsEnabled = true; } } else if (_authorizeStep == AuthorizeStep.MastodonAuthorize) { try { var auth = await _mastodonOauthSettion.ConnectWithCode(pin); var client = new MastodonClient(_mastodonAppRegistration, auth); var user = await client.GetCurrentUser(); _accountInfo = new AccountInfo { ConsumerKey = _mastodonAppRegistration.ClientId, ConsumerSecret = _mastodonAppRegistration.ClientSecret, AccessToken = auth.AccessToken, AccessTokenSecret = "", ScreenName = user.UserName, UserId = user.Id, Service = "Mastodon", Instance = _mastodonOauthSettion.Instance }; } catch { await new MessageDialog(_resourceLoader.GetString("AuthorizePopup_OAuthAuthorizeError")) .ShowAsync(); return; } finally { AuthorizePopupAuthorizeButton.IsEnabled = true; } } _authorizeStep = AuthorizeStep.Exit; }