/// <summary> /// Creates a new access token. This corresponds to the Hyves auth.accesstoken method. /// </summary> /// <param name="requestToken">The request token to use to create the access token.</param> /// <param name="requestTokenSecret">The request token secret to use to sign the request.</param> /// <param name="tokenSecret"></param> /// <param name="userId">The user Id associated with the session.</param> /// <param name="expireDate">Date when the created access token expireDate.</param> /// <returns>A access token.</returns> public string CreateAccessToken(string requestToken, string requestTokenSecret, out string tokenSecret, out string userId, out DateTime expireDate) { tokenSecret = string.Empty; userId = string.Empty; expireDate = DateTime.Now; if (string.IsNullOrEmpty(requestToken)) { throw new ArgumentException("requestToken"); } if (string.IsNullOrEmpty(requestTokenSecret)) { throw new ArgumentException("requestTokenSecret"); } string token = null; HttpWebRequest webRequest = CreateRequest(requestToken, requestTokenSecret, HyvesExpirationType.Default, session); HttpWebResponse webResponse = null; try { webResponse = (HttpWebResponse)webRequest.GetResponse(); } catch (WebException we) { webResponse = (HttpWebResponse)we.Response; } if (webResponse.StatusCode == HttpStatusCode.OK) { HyvesResponse sessionResponse = new HyvesResponse(webResponse.GetResponseStream(), HyvesMethod.Unknown); if (sessionResponse.IsError == false) { Hashtable result = sessionResponse.Result as Hashtable; if (result != null) { token = (string)result["oauth_token"]; tokenSecret = (string)result["oauth_token_secret"]; userId = (string)result["userid"]; expireDate = HyvesResponse.CoerceDateTime(result["expiredate"]); } } } return(token); }
/// <summary> /// Completes an asynchronous call to create an new access token. /// </summary> /// <param name="asyncResult">The async result from the corresponding BeginCreateAccessToken call.</param> /// <param name="tokenSecret"></param> /// <param name="userId">The user Id associated with the access token.</param> /// <param name="expireDate">Date when the created access token expireDate.</param> /// <returns>A new access token.</returns> public string EndCreateAccessToken(IAsyncResult asyncResult, out string tokenSecret, out string userId, out DateTime expireDate) { tokenSecret = string.Empty; userId = string.Empty; expireDate = DateTime.Now; if (asyncResult == null) { throw new ArgumentNullException("asyncResult"); } if (asyncRequest == null) { throw new InvalidOperationException("No method is currently being invoked using this request."); } string token = null; try { HttpWebResponse webResponse = (HttpWebResponse)asyncRequest.EndGetResponse(asyncResult); if (webResponse.StatusCode == HttpStatusCode.OK) { HyvesResponse accessResponse = new HyvesResponse(webResponse.GetResponseStream(), HyvesMethod.Unknown); if (accessResponse.IsError == false) { Hashtable result = accessResponse.Result as Hashtable; if (result != null) { token = (string)result["oauth_token"]; tokenSecret = (string)result["oauth_token_secret"]; userId = (string)result["userid"]; expireDate = HyvesResponse.CoerceDateTime(result["expiredate"]); } } } } finally { asyncRequest = null; } return(token); }