4、再回到url中开展业务潮管理

率先次发博客 ,有疑难如故有建议的请留言

  1. AuthHelper代码

     public abstract class AuthHelper
     {
         public static AuthToken GetToken(string code, string token_url, string cliend_id, string client_secret, string return_url)
         {
             var strResult = GetTokenStr(code, token_url, cliend_id, client_secret, return_url);
             try
             {
                 var res = JsonConvert.DeserializeObject<AuthToken>(strResult);
                 return res;
             }
             catch (Exception ex)
             {
                 Tool.Log.Write(ex.ToString());
             }
             return default(AuthToken);
         }
    
         /// <summary>
         /// 向第三方平台发送获取token请求
         /// </summary>
         /// <param name="code"></param>
         /// <param name="token_url"></param>
         /// <param name="cliend_id"></param>
         /// <param name="client_secret"></param>
         /// <param name="return_url"></param>
         /// <returns></returns>
         public static string GetTokenStr(string code, string token_url, string cliend_id, string client_secret, string return_url)
         {
             Dictionary<string, string> dicPara = new Dictionary<string, string>();
             dicPara.Add("grant_type", "authorization_code");
             dicPara.Add("code", code);
             dicPara.Add("redirect_uri", return_url);
             dicPara.Add("client_id", cliend_id);
             dicPara.Add("client_secret", client_secret);
    
             var token = WebApiHelper.PostResponseStr(token_url, dicPara);
             return token;
         }
    
         /// <summary>
         /// header中发送token
         /// </summary>
         /// <param name="accessToken"></param>
         /// <param name="profile_url"></param>
         /// <returns></returns>
         public static string GetProFileAuth(string accessToken, string profile_url)
         {
             Dictionary<string, string> dicAuth = new Dictionary<string, string>();
             dicAuth.Add("Authorization", "Bearer " + accessToken);
             var profile = WebApiHelper.GetResponseStr(profile_url, null, dicAuth);
             return profile;
         }
         /// <summary>
         /// get方式获取token
         /// </summary>
         /// <param name="accessToken"></param>
         /// <param name="profile_url"></param>
         /// <returns></returns>
         public static string GetProFileStr(string accessToken, string profile_url)
         {
             Dictionary<string, string> dicQuery = new Dictionary<string, string>();
             dicQuery.Add("access_token", accessToken);
             var profile = WebApiHelper.GetResponseStr(profile_url, dicQuery, null);
             return profile;
         }
     }
    

小心:申请的网站须求与实际访谈的url保持大器晚成致

2.授权采访流程

4、使用access_token(客商消息访问令牌卡塔尔获取有关音信

2、使用key/secret向服务方伏乞客商授权Token(code也正是authorization_code)

 

 

   public ActionResult ReturnLinkedin()
        {
            string description = string.Empty;

            string code = RequestString("code");
            string state = RequestString("state");
            string error = RequestString("error");
            string error_description = RequestString("error_description");
            if (code == "" || error != "")
            {
                if (code == "user_cancelled_authorize" || code == "user_cancelled_login ")
                {
                    description = code;
                }
                else
                    description = error != "" ? error_description : "no authentication !";
            }
            else
            {
                var res = Tools.Auth.LinkinHelper.GetToken(code, Tools.Auth.LinkinConfig.ReturnUrl);
                if (res.access_token != "")
                {
                    var entity = Tools.Auth.LinkinHelper.GetProFileStr(res.access_token, Tools.Auth.LinkinConfig.ProfileResourceUrl);
                    description = entity;
            /***具体业务处理
            **/
                }
                else
                {
                    description = "access token error";
                }
            }
            ViewBag.Description = description;
            return View();
        }

2、填写Oauth2.0本站重临链接

简述认证流程如下。 

近来协理Facebook ,LinkedIn
,基本一模二样,只是再次回到时的数目不一样,需依照现实重回类型举办对应管理

Github地址:

简述认证流程如下。要求:OAuth2兑现第三方网址授权并赢得其连带数据来促成登陆等成效

1.OAuth2表达流程

OAuth2验证公约提到3方(应用、客户和服务方卡塔 尔(阿拉伯语:قطر‎,加之流程相比较麻烦,完毕命名不尽相像,

简述认证流程如下。轻巧忘记和歪曲,简述认证流程如下

3、向第三方平台发送授权须求

1、向第三方平台报名访问权限获得(client_id和client_secret)

1、向利用OAuth2认证的服务方申请使用,获取使用的client_id(应用唯生机勃勃标志)和client_secret(应用私钥)

3、使用客户授权Token换取顾客消息访谈Token(access_token ),

4.回来工作管理

相关文章