コード例 #1
0
        protected void Button2_Click(object sender, EventArgs e)
        {
            SocialLogincs socialLogincs           = new SocialLogincs();
            Dictionary <string, string> keyValues = socialLogincs.SocialLoginBtnPush(2);

            Session["sns"]   = 2;
            Session["state"] = keyValues["state"];
            Response.Redirect(keyValues["authorizationUri"]);
        }
コード例 #2
0
        //自宅
        //http://192.168.3.4:8080/Default

        //職場
        //https://localhost:44383/Default

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                //セッション変数代入用
                int    snsCode = 0;
                string state   = string.Empty;

                if (Session["sns"] != null && Session["state"] != null)
                {
                    snsCode = (int)Session["sns"];
                    state   = (string)Session["state"];

                    if (state.Equals(Request.QueryString["state"]))
                    {
                        try
                        {
                            //アクセストークンを取得
                            SocialLogincs socialLogincs = new SocialLogincs();
                            Dictionary <string, string> responsePair = socialLogincs.GetAccessToken(snsCode, Request.QueryString["code"]);

                            if (responsePair.ContainsKey("access_token") && responsePair.ContainsKey("token_type"))
                            {
                                //SNS別のユーザーIDを取得
                                Dictionary <string, string> responseUserProfile = socialLogincs.GetUserProfile(snsCode, responsePair["access_token"], responsePair["token_type"]);

                                //会員IDの検証
                                string csfUserId = string.Empty;      //SNSユーザーIDからCSF会員IDを抽出

                                //SNSがLINEモバイルの場合、アクセストークンを無効化する
                                if (snsCode == 1)
                                {
                                    socialLogincs.InvalidationAccessToken(responsePair["access_token"]);
                                }

                                //会員IDが紐づいていればログイン(トップページへリダイレクト)
                                if (!string.IsNullOrWhiteSpace(csfUserId))
                                {
                                    Session["KaiinId"] = csfUserId;
                                    //Response.Redirect("http://192.168.3.4:8080/LoginSuccessful");
                                    Response.Redirect("https://localhost:44383/LoginSuccessful");
                                }
                            }
                        }
                        catch
                        {
                            //SNSログインエラーの例外処理
                        }
                    }
                    //Session["sns"] = null;
                    Session["state"] = null;
                }
            }
        }
コード例 #3
0
        protected void Button1_Click(object sender, EventArgs e)
        {
            SocialLogincs socialLogincs = new SocialLogincs();

            socialLogincs.SendLineMessage(userId);      //userID = LINEのユーザーID
        }