金沙澳门官网第三方登录开发

作者: 网络编程  发布:2019-10-19

2.授权访谈流程

 

   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();
        }

 

Github地址:

 

 

1.OAuth2表明流程

轻便忘记和混淆,简述认证流程如下

率先次发博客 ,有问号照旧有提出的请留言

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

  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;
         }
     }
    

4、使用access_token(客户音信访问令牌)获取有关音讯

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

4、再回来url中进行作业潮管理

2、填写Oauth2.0本站再次来到链接

OAuth2表达左券提到3方(应用、客商和服务方),加之流程相比麻烦,达成命名不尽同样,

暂且协理推特(TWTR.US)(Instagram) ,LinkedIn ,基本完全同样,只是再次来到时的数量分裂,需依附实际再次回到类型进行对应管理

3、使用顾客授权Token换取客商新闻访谈Token(access_token ),

1、向第三方平台申请访谈权限获得(client_id和client_secret)

4.回到职业管理

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

须求:OAuth2实现第三方网址授权并获得其有关数据来完结登入等功效

注意:申请的网址必要与事实上访谈的url保持一致

本文由金沙澳门官网发布于网络编程,转载请注明出处:金沙澳门官网第三方登录开发

关键词: 金沙澳门官网

上一篇:金沙澳门官网php环境配置
下一篇:没有了