Ejemplo n.º 1
0
        public Task <OAuthResult> AuthorizeAsync(Uri startUri, Uri redirectUri, OAuthUIOptions options = null)
        {
            var window = new OAuthWindow(startUri, redirectUri, options);
            var tcs    = new TaskCompletionSource <OAuthResult>();

            if (window.ShowDialog() == true)
            {
                tcs.SetResult(window.Result);
            }
            else
            {
                tcs.SetResult(new OAuthResult(string.Empty, OAuthStatus.Cancelled));
            }
            return(tcs.Task);
        }
Ejemplo n.º 2
0
        private void AfterSignIn(bool needOpenAuthWindow)
        {
            string memberUId = null; // used only for client-side

            // could not use the token, opens the auth Window
            if (needOpenAuthWindow && SelectedProvider!=null) {
                SelectedProvider.SignOut();
                Show();
                if (SelectedProvider.LoginType == Services.AuthProviders.TokenGet.SERVER_SIDE) {
                    OAuthWindow oauthWindow = new OAuthWindow();
                    oauthWindow.ShowDialog(SelectedProvider);
                }
                else {
                    OAuthWindowClientSide oauthWindow = new OAuthWindowClientSide();
                    oauthWindow.ShowDialog(SelectedProvider);
                    memberUId = oauthWindow.MemberUId;
                }

                if (SelectedProvider != null && !String.IsNullOrEmpty(SelectedProvider.ACCESS_TOKEN))
                    SignIn(SelectedProvider, memberUId);
                else
                    IsSigning = false;

                return;
            }

            // sucess!!
            if (authorizator.SignedMemberProfile != null) {

                // closes the loginview model, and tells everyone the new signed member
                Close();

                ScrumFactory.Windows.Helpers.Converters.MemberAvatarUrlConverter.SignedMember = authorizator.SignedMemberProfile;
                ScrumFactory.Windows.Helpers.Converters.MemberAvatarUrlConverter.ResetCache();

                aggregator.Publish<MemberProfile>(ScrumFactoryEvent.SignedMemberChanged, authorizator.SignedMemberProfile);

                // not signing any more
                IsSigning = false;

                return;
            }

            // if could not sign in
            dialogs.ShowAlertMessage(Properties.Resources.Factory_could_not_validate_credentials, LoginStatusMessage, null);

            // not signing any more
            IsSigning = false;
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Twitter 連携に関するイベント設定を行います。
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private async Task _UsingPostTwitterAsync()
        {
            if (this.checkBoxPostTwitter.Checked)
            {
                var settings          = Properties.Settings.Default;
                var consumerKey       = (string)settings["ConsumerKey"] ?? null;
                var consumerSecret    = (string)settings["ConsumerSecret"] ?? null;
                var accessToken       = (string)settings["AccessToken"] ?? null;
                var accessTokenSecret = (string)settings["AccessTokenSecret"] ?? null;

                if (string.IsNullOrEmpty(consumerKey) || string.IsNullOrEmpty(consumerSecret) ||
                    string.IsNullOrEmpty(accessToken) || string.IsNullOrEmpty(accessTokenSecret))
                {
                    // Consumer Key / Secret をここで入力
                    var key = new KeyWindow(consumerKey, consumerSecret);
                    if (key.ShowDialog() == DialogResult.OK)
                    {
                        (this._ConsumerKey, this._ConsumerSecret) = key.CkPair;
                    }

                    // 入力された Consumer Key / Secret を元に インスタンス生成
                    this._Twitter = new Twitter(this._ConsumerKey, this._ConsumerSecret, this._HttpClient);

                    if (this._ConsumerKey != null && this._ConsumerSecret != null)
                    {
                        // 認証を実施します
                        await this._Twitter.AuthorizeAsync();

                        // Form が Close したと同時に ShowDialog も完了する。
                        var oauth = new OAuthWindow();
                        if (oauth.ShowDialog() == DialogResult.OK)
                        {
                            await this._Twitter.GetAccessTokenAsync(oauth.PinCode);
                        }

                        // 認証完了メッセージの投稿
                        await this.PostTwitterAsync($"Authentication completion for Kisaragi.\r\n{DateTimeOffset.Now}");

                        // 各種認証キーを設定ファイルに保存する
                        settings["ConsumerKey"]       = this._Twitter.ConsumerKey;
                        settings["ConsumerSecret"]    = this._Twitter.ConsumerSecret;
                        settings["AccessToken"]       = this._Twitter.AccessToken;
                        settings["AccessTokenSecret"] = this._Twitter.AccessTokenSecret;
                        settings["UserId"]            = this._Twitter.UserId;
                        settings["ScreenName"]        = this._Twitter.ScreenName;
                        settings.Save();
                    }
                    else
                    {
                        this.checkBoxPostTwitter.Checked = false;
                        MessageBox.Show("Twitter 連携をキャンセルします。\r\n" +
                                        "再度認証するには、チェックボックスをクリックしてください。", "認証未実施", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    }
                }
                else
                {
                    new KisaragiMessageBox("Twitter 連携用認証キーは既に存在しています。" +
                                           "\r\nTwitter 連携を行うにはチェックを入れたままにしてください。", "通知", 2000);
                }
            }
        }