c#实现microsoft账号登入授权(OAuth 2.0)并获取个人信息

本博主要介绍microsoft 账号授权(OAuth 2.0)登入并获取用户信息的过程,因为写过google账号授权登入的过程,所以这里就简单介绍一下,google授权登入参考地址:http://www.cnblogs.com/JohnnyYin/p/3447217.html

1.去microsoft官网注册账号,注册完了账号再注册一个app,地址:https://account.live.com/developers/applications/index

 2.其他都不详细介绍了,直接上code

 

/// <summary>
        /// the access token
        /// </summary>
        private static string accessToken;

        /// <summary>
        /// the application id
        /// </summary>
        private static string clientID = ConfigurationSettings.AppSettings["WL_ClientID"].ToString();

        /// <summary>
        /// the application secret
        /// </summary>
        private static string clientSecret = ConfigurationSettings.AppSettings["WL_ClientSecret"].ToString();

        /// <summary>
        /// the application redirect uri path
        /// </summary>
        private static string redirectUri = ConfigurationSettings.AppSettings["WL_RedirectUri"].ToString();
View Code

 

/// <summary>
        ///Get the login with microsoft url
        /// </summary>
        /// <returns></returns>
        /// <author>Johnny</author>
        /// <date>2013/11/15, 16:37:08</date>
        /// <returns>return a twitter login url</returns>
        public string GetLoginUrl()
        {
            string loginUrl = null;
            try
            {
                loginUrl = string.Format("https://login.live.com/oauth20_authorize.srf?" +
                        "client_id={0}&scope={1}&response_type=code&redirect_uri={2}",
                        HttpUtility.UrlEncode(clientID),
                        HttpUtility.UrlEncode("wl.basic,wl.emails"),
                        HttpUtility.UrlEncode(redirectUri)
                        );
            }
            catch (Exception)
            {

                throw;
            }
            return loginUrl;
        }
View Code
/// <summary>
        ///general a post http request
        /// </summary>
        /// <author>Johnny</author>
        /// <date>2013/11/20, 09:21:33</date>
        public string
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值