public static async Task <string> ReRefreshToken() { var _httpClient = new OAuth2Client(new Uri(m_Uri), m_ClientId, m_ClientSecret); _httpClient.BaseAddress = new Uri(m_Uri); oAuth2Token = await _httpClient.RefreshToken(oAuth2Token.RefreshToken); httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", oAuth2Token.AccessToken); return(oAuth2Token.AccessToken); }
/// <summary> /// 获取Access Token字符串 /// </summary> /// <param name="uriStr">"http://localhost:13800/"</param> /// <param name="clientId">ClientId字符串</param> /// <param name="clientSecret">密钥</param> /// <param name="username">用户名</param> /// <param name="password">密码</param> /// <returns></returns> public static async Task <string> GetAccessToken(string uriStr, string clientId, string clientSecret, string username, string password) { var _httpClient = new OAuth2Client(new Uri(uriStr), clientId, clientSecret); m_Uri = uriStr; m_ClientId = clientId; m_ClientSecret = clientSecret; m_UserName = username; m_Password = password; _httpClient.BaseAddress = new Uri(uriStr); try { oAuth2Token = await _httpClient.RequestToken(m_UserName, m_Password); } catch (Exception ex) { string sss = ex.ToString(); } httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", oAuth2Token.AccessToken); return(oAuth2Token.AccessToken); }