Exemplo n.º 1
0
        /// <summary>
        /// 获取code,重定向到第三方
        /// 返回地址加上code
        /// </summary>
        public void GetRequestToken()
        {
            var oauth        = new OAuthData();
            var appKey       = Request.QueryString["appKey"];
            var redirect_uri = Request.QueryString["redirect_uri"];
            var sign         = Request.QueryString["sign"];

            var entity = OAuthDb.Db.FirstOrDefault(i => i.oauth_consumer_key == appKey);

            if (entity == null)
            {
                Response.Write("oauth_consumer_key不是有效的!");
                Response.StatusCode = 401;
                Response.End();
                return;
            }
            oauth.SetValue("appKey", appKey);
            oauth.SetValue("redirect_uri", redirect_uri);

            if (Utils.Encryptor.MD5Encryptor.MD5((oauth.ToUrl() + "&key=" + entity.oauth_consumer_secret)).ToUpper() != sign)
            {
                Response.Write("签名不合并,可以传输过程中已经被篡改!");
                Response.StatusCode = 401;
                Response.End();
                return;
            }

            entity.oauth_requestToken = Utils.Encryptor.MD5Encryptor.MD5(entity.oauth_consumer_key + entity.oauth_consumer_secret);
            entity.oauth_timestamp    = (DateTime.Now.ToUniversalTime() - DateTime.MinValue).TotalSeconds;
            Response.Redirect(redirect_uri + "?requestToken=" + entity.oauth_requestToken);
        }
Exemplo n.º 2
0
 /// <summary>
 /// 获取accessToken
 /// </summary>
 public string GetAccessToken()
 {
     if (string.IsNullOrWhiteSpace(System.Web.HttpContext.Current.Request.QueryString["accessToken"]))
     {
         string requestToken = System.Web.HttpContext.Current.Request.QueryString["requestToken"];
         var    data         = new OAuthData();
         data.SetValue("requestToken", requestToken);
         data.SetValue("redirect_uri", System.Web.HttpContext.Current.Request.Url.AbsoluteUri);
         System.Web.HttpContext.Current.Response.Redirect("http://localhost:5766/OAuth/GetAccessToken?" + data.ToUrl() + "&sign=" + data.MakeSign());
         return(null);
     }
     else
     {
         return(System.Web.HttpContext.Current.Request.QueryString["accessToken"]);
     }
 }
Exemplo n.º 3
0
 /// <summary>
 /// 获取requestToken
 /// </summary>
 public string GetRequestToken(string appKey)
 {
     if (string.IsNullOrWhiteSpace(System.Web.HttpContext.Current.Request.QueryString["requestToken"]))
     {
         var data = new OAuthData();
         data.SetValue("appKey", appKey);
         data.SetValue("redirect_uri", System.Web.HttpContext.Current.Request.Url.AbsoluteUri);
         data.SetValue("sign", data.MakeSign()); //所有参数加key,生成md5
         if (!data.CheckSign())
         {
             System.Web.HttpContext.Current.Response.Write("sign签名格式不正确,请参考说明文档!");
             System.Web.HttpContext.Current.Response.StatusCode = 401;
             System.Web.HttpContext.Current.Response.End();
         }
         System.Web.HttpContext.Current.Response.Redirect("http://localhost:5766/OAuth/GetRequestToken?" + data.ToUrl() + "&sign=" + data.MakeSign());
         return(null);
     }
     else
     {
         return(System.Web.HttpContext.Current.Request.QueryString["requestToken"]);
     }
 }