Esempio n. 1
0
        public async Task <RedirectResult> IssueToken(string code, string state)
        {
            // Oauth認証時に格納したユーザデータを取得
            NameValueCollection data = _userData;

            // ===========================
            // GitHubアクセストークン発行
            // ===========================
            var request = new OauthTokenRequest(ConfigurationManager.AppSettings["client_id"], ConfigurationManager.AppSettings["client_secret"], code);

            var token = await _githubClient.Oauth.CreateAccessToken(request);

            // ============================================
            // slackユーザとGitHubアクセストークンの紐付け
            // ============================================
            var entityOperationUser = new EntityOperation <UserEntity>();

            //作成or更新を行うユーザエンティティ作成
            var entity = new UserEntity(data["user_id"], data["user_name"], token.AccessToken);

            //エンティティを操作変数を用いて作成or更新
            entityOperationUser.InsertOrUpdateEntityResult(entity, "user");

            return(Redirect("https://" + data["team_domain"] + ".slack.com/messages"));
        }
Esempio n. 2
0
        // GET api/<controller>
        public async Task <RedirectResult> Get(string code, string state)
        {
            //stateに相違がある場合はセキュリティエラー
            if (state != LoginDialog.csrf)
            {
                throw new InvalidOperationException("SECURITY FAIL!");
            }

            //tokenのリクエストを作成
            var request = new OauthTokenRequest(ConfigurationManager.AppSettings["client_id"], ConfigurationManager.AppSettings["client_secret"], code);

            //リクエストを送信
            var token = await GitHubDialog.github.Oauth.CreateAccessToken(request);

            //ユーザエンティティの操作変数作成
            EntityOperation <UserEntity> entityOperation_Template = new EntityOperation <UserEntity>();

            //作成or更新を行うユーザエンティティ作成
            UserEntity entity = new UserEntity(GitHubDialog.activity.From.Id, GitHubDialog.activity.From.Name, token.AccessToken);

            //エンティティを操作変数を用いて作成or更新
            TableResult result = entityOperation_Template.InsertOrUpdateEntityResult(entity, "user");

            #region 未使用API送信
            ////API送信用ウェブクライアント
            //using (WebClient wc = new WebClient())
            //{
            //    //必要なクエリ情報を作成し、格納
            //    NameValueCollection nvc = new NameValueCollection();
            //    nvc.Add("client_id", ConfigurationManager.AppSettings["client_id"]);
            //    nvc.Add("client_secret", ConfigurationManager.AppSettings["client_secret"]);
            //    nvc.Add("code", code);
            //    nvc.Add("state", state);
            //    wc.QueryString = nvc;

            //    //データを送信し、また受信する
            //    byte[] response =  wc.UploadValues("https://github.com/login/oauth/access_token", nvc);

            //    //文字列化した受信バイトデータをNameValueCollectionに換装
            //    nvc = HttpUtility.ParseQueryString(wc.Encoding.GetString(response));

            //    GitHubDialog.accessToken = nvc.Get("access_token");

            //    return Redirect("https://slack.com");
            //}
            #endregion

            return(Redirect("https://" + GitHubDialog.channelName + ".slack.com"));
        }