Пример #1
0
 public void Init()
 {
     oauthAPI             = OAuthAPIFactory.CreateOAuthAPI();
     oauthAPI.AppKey      = "ebf7336b13e244c888e67ef33c6a07be";
     oauthAPI.AppSecret   = "7b27dd3e8e85af7558961c5bc9a297b4";
     oauthAPI.Token       = "f71f4c3c13be441ea658171649cdb68a";
     oauthAPI.TokenSecret = "e5f386111aff1908f67df4c763c9efbc";
 }
Пример #2
0
 public void Init()
 {
     oauthAPI             = OAuthAPIFactory.CreateOAuthAPI();
     oauthAPI.AppKey      = "R59IF17nNl6PEt3EBbfM";
     oauthAPI.AppSecret   = "Eb3)5g1PAqYD6UhrO1-O52CZ2tvkdioGxxf^7SCt";
     oauthAPI.Token       = "380fa793579a7c3e27df2e3a425330ab";
     oauthAPI.TokenSecret = "5e664a38c22086564a3076dfa77f83cb";
 }
Пример #3
0
 public void Init()
 {
     oauthAPI             = OAuthAPIFactory.CreateOAuthAPI();
     oauthAPI.AppKey      = "TeHso9yKTtSG5dVa";
     oauthAPI.AppSecret   = "6sKtvqiZ6hD4zymed7uAiMLovx99nt9x";
     oauthAPI.Token       = "a1c7f3f8741a7311cae7919f4aac1304";
     oauthAPI.TokenSecret = "8afb019d14ddf76dc12a031497f5916e";
 }
Пример #4
0
 public void Init()
 {
     oauthAPI             = OAuthAPIFactory.CreateOAuthAPI();
     oauthAPI.AppKey      = "1992241176";
     oauthAPI.AppSecret   = "f6b0007ab6757928d70c4961d04e2606";
     oauthAPI.Token       = "ad8b1dc2cd84a2bdb70783f6b369f199";
     oauthAPI.TokenSecret = "637ecb48f715b3a9f1f8f9c516062e0c";
 }
Пример #5
0
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                if (Session["oauthAPIObj"] != null)
                {
                    OAuthAPIEntity oauthAPI = Session["oauthAPIObj"] as OAuthAPIEntity;

                    drpSite.SelectedIndex = oauthAPI.Site;

                    txtAppKey.Text    = oauthAPI.AppKey;
                    txtAppSecret.Text = oauthAPI.AppSecret;
                    txtUserName.Text  = oauthAPI.UserName;
                }

                if (Request["oauth_verifier"] != null || drpSite.SelectedIndex == 2)
                {
                    if (!string.IsNullOrEmpty(txtToken.Text))
                    {
                        return;
                    }

                    var verifier = Request["oauth_verifier"];

                    IOAuthAPI oauthAPI = Session["oauthAPI"] as IOAuthAPI;

                    if (oauthAPI.GetAccessToken(verifier))
                    {
                        txtToken.Text         = oauthAPI.Token;
                        txtTokenSecret.Text   = oauthAPI.TokenSecret;
                        this.lblErrorMsg.Text = "授权成功";

                        Session["oauthAPI"] = oauthAPI;

                        OAuthAPIEntity oauthAPIEntity = Session["oauthAPIObj"] as OAuthAPIEntity;

                        oauthAPIEntity.Token       = oauthAPI.Token;
                        oauthAPIEntity.TokenSecret = oauthAPI.TokenSecret;

                        Session["oauthAPIObj"] = oauthAPIEntity;
                    }
                }
            }
        }
Пример #6
0
        protected void btnGo_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrEmpty(txtAppKey.Text) || string.IsNullOrEmpty(txtAppSecret.Text))
            {
                lblErrorMsg.Text = "请输入appkey和appsecret";
                return;
            }

            Session.Clear();

            var site = int.Parse(drpSite.SelectedValue);

            if (site == 5)
            {
                site = 0;
            }

            OAuthAPIEntity entity = OAuthAPIDAL.Load(txtAppKey.Text, txtUserName.Text, site);

            if (entity != null)
            {
                lblErrorMsg.Text    = "已经存在";
                txtToken.Text       = entity.Token;
                txtTokenSecret.Text = entity.TokenSecret;

                IOAuthAPI oauthAPI2 = OAuthAPIFactory.CreateOAuthAPI();
                oauthAPI2.RequestTokenUrl = entity.RequestTokenUrl;
                oauthAPI2.AuthorizeUrl    = entity.AuthorizeUrl;
                oauthAPI2.AccessTokenUrl  = entity.AccessTokenUrl;
                oauthAPI2.AppKey          = entity.AppKey;
                oauthAPI2.AppSecret       = entity.AppSecret;
                oauthAPI2.Token           = entity.Token;
                oauthAPI2.TokenSecret     = entity.TokenSecret;

                Session["oauthAPI"] = oauthAPI2;
                return;
            }

            OAuthAPIEntity oauthAPIEntity = GetOAuthAPI(site);

            oauthAPIEntity.AppKey    = txtAppKey.Text;
            oauthAPIEntity.AppSecret = txtAppSecret.Text;
            oauthAPIEntity.UserName  = txtUserName.Text;
            oauthAPIEntity.Password  = txtPassword.Text;
            oauthAPIEntity.Site      = site;

            Session["oauthAPIObj"] = oauthAPIEntity;

            if (int.Parse(drpSite.SelectedValue) >= 5)
            {
                IHttpForm http = HttpFormFactory.DefaultHttpForm();

                string authorizeFormat = "https://api.weibo.com/oauth2/authorize?client_id={0}&redirect_uri={1}&response_type=code";

                string authorize = string.Format(authorizeFormat, oauthAPIEntity.AppKey, "http://barefoot.3322.org/queryservice.svc/query");

                HttpFormGetRequest getRequest = new HttpFormGetRequest();

                getRequest.Cookies = Login(oauthAPIEntity.UserName, oauthAPIEntity.Password);
                getRequest.Url     = authorize;

                HttpFormResponse response = http.Get(getRequest);

                Match m = null;

                if (!response.Response.StartsWith("\"code="))
                {
                    m = Regex.Match(response.Response, "<input\\stype=\"hidden\"\\sname=\"regCallback\"\\svalue=\"(?<regCallback>[^\"]+)\"/>", RegexOptions.IgnoreCase | RegexOptions.Multiline);

                    string regCallback = m.Groups["regCallback"].Value;

                    string regPostData = "action=submit&response_type=code&regCallback=" + regCallback + "&redirect_uri=http://barefoot.3322.org/queryservice.svc/query&client_id=" + oauthAPIEntity.AppKey + "&state=&from=";

                    HttpFormPostRawRequest regRequest = new HttpFormPostRawRequest();

                    regRequest.Data    = regPostData;
                    regRequest.Url     = "https://api.weibo.com/oauth2/authorize";
                    regRequest.Cookies = response.Cookies;

                    response = http.Post(regRequest);
                }

                string code = response.Response.Trim('\"').Substring(5);

                HttpFormPostRawRequest request = new HttpFormPostRawRequest();

                request.Url = "https://api.weibo.com/oauth2/access_token";

                string postDataFormat = "client_id={0}&client_secret={1}&grant_type=authorization_code&code={2}&redirect_uri=http://barefoot.3322.org/queryservice.svc/query";

                string postData = string.Format(postDataFormat, oauthAPIEntity.AppKey, oauthAPIEntity.AppSecret, code);

                request.Data = postData;

                response = http.Post(request);

                m = Regex.Match(response.Response, "{\"access_token\":\"(?<token>[^\"]+)\",");

                string token = m.Groups["token"].Value;

                txtToken.Text         = token;
                txtTokenSecret.Text   = code;
                this.lblErrorMsg.Text = "授权成功";

                oauthAPIEntity.Token       = token;
                oauthAPIEntity.TokenSecret = code;
                oauthAPIEntity.Version     = 2;

                Session["oauthAPIObj"] = oauthAPIEntity;
            }
            else
            {
                IOAuthAPI oauthAPI = OAuthAPIFactory.CreateOAuthAPI();
                oauthAPI.RequestTokenUrl = oauthAPIEntity.RequestTokenUrl;
                oauthAPI.AuthorizeUrl    = oauthAPIEntity.AuthorizeUrl;
                oauthAPI.AccessTokenUrl  = oauthAPIEntity.AccessTokenUrl;

                if (oauthAPI.GetRequestToken(oauthAPIEntity.AppKey, oauthAPIEntity.AppSecret, Config.CallbackUrl))
                {
                    var authorizationUrl = oauthAPI.GetAuthorize(Config.CallbackUrl);

                    Session["oauthAPI"] = oauthAPI;

                    if (!string.IsNullOrEmpty(authorizationUrl))
                    {
                        Response.Redirect(authorizationUrl);
                    }
                }
            }
        }