Esempio n. 1
0
        protected void btnAuthon_Click(object sender, EventArgs e)
        {
            if (String.IsNullOrEmpty(txtAppKey.Text.Trim()))
            {
                Utility.MessageBox("App Key 不能为空!");
                return;
            }

            if (String.IsNullOrEmpty(txtAppSecret.Text.Trim()))
            {
                Utility.MessageBox("App Secret 不能为空!");
                return;
            }

            if (String.IsNullOrEmpty(txtCallbackUrl.Text.Trim()))
            {
                Utility.MessageBox("Callback Url 不能为空!");
                return;
            }
            try
            {
                Uri uri = new Uri(txtCallbackUrl.Text.Trim(), UriKind.Absolute);
                if (!String.Equals(uri.Host, Request.Url.Host))
                {
                    Utility.MessageBox("回调地址与当前主域不匹配!");
                    return;
                }
            }
            catch (UriFormatException ex)
            {
                Utility.MessageBox(ex.Message);
                return;
            }

            OAuth oauth = new OAuth(txtAppKey.Text.Trim(), txtAppSecret.Text.Trim(), txtCallbackUrl.Text.Trim());
            Application.Set("OAuthAppKey",txtAppKey.Text.Trim());
            Application.Set("OAuthAppSecret", txtAppSecret.Text.Trim());
            Application.Set("OAuthCallbackUrl", txtCallbackUrl.Text.Trim());
            Response.Redirect(oauth.GetAuthorizationUrl());
        }
Esempio n. 2
0
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Utility.IsAccessTokenValid(AppContext.AccessToken))
            {
                //有效 做你想做的事
                lbMessage.Text = AppContext.AccessToken.Token;
            }
            else
            {
                if (String.IsNullOrEmpty(AppContext.AppKey)
                    || String.IsNullOrEmpty(AppContext.AppSecret)
                    || String.IsNullOrEmpty(AppContext.CallbackUrl))
                {
                    Response.Redirect("~/setting.aspx");
                }

                //失效了再获取或者用refreshToken刷新
                //refreshToken没有测试过
                OAuth oauth = new OAuth(AppContext.AppKey, AppContext.AppSecret, AppContext.CallbackUrl);
                Response.Redirect(oauth.GetAuthorizationUrl());

            }
        }
Esempio n. 3
0
        private void btnLink_Click(object sender, EventArgs e)
        {
            if (String.IsNullOrEmpty(txtAppKey.Text.Trim()))
            {
                Utility.ShowError("App Key 不能为空!");
                return;
            }

            if (String.IsNullOrEmpty(txtAppSecret.Text.Trim()))
            {
                Utility.ShowError("App Secret 不能为空!");
                return;
            }

            this.AppKey = txtAppKey.Text.Trim();
            this.AppSecret = txtAppSecret.Text.Trim();
            String callBackUrl = "urn:ietf:wg:oauth:2.0:oob";
            oauth = new OAuth(this.AppKey, this.AppSecret, callBackUrl);
            oauth.AuthorizeUrl = AppContext.AuthorizeUrl;
            oauth.AccessTokenUrl = AppContext.AccessTokenUrl;
            Utility.Run(oauth.GetAuthorizationUrl(), null);
            Console.WriteLine("打开授权网页!");
        }