本博主要介绍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();
/// <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; }
/// <summary> ///general a post http request /// </summary> /// <author>Johnny</author> /// <date>2013/11/20, 09:21:33</date> public