/// <summary> /// /// </summary> /// <param name="authorizeInfo"></param> /// <param name="oauthVerifier"></param> /// <returns></returns> public AccessTokenInfo GetAccessToken(AuthorizeInfo authorizeInfo, String oauthVerifier) { var ai = authorizeInfo; var cm = new GetRequestTokenCommand(this.ConsumerKey, this.ConsumerSecret , ai.RequestToken, ai.RequestTokenSecret, HttpMethodName.Post); var si = OAuthClient.GenerateSignature(new Uri(this.AccessTokenUrl), cm, OAuthSignatureTypes.HMACSHA1); HttpRequestCommand command = new HttpRequestCommand(String.Format("{0}?{1}&oauth_verifier={2}&oauth_signature={3}" , this.AccessTokenUrl, si.NormalizedRequestParameters, oauthVerifier, si.Signature), HttpMethodName.Post); HttpClient cl = new HttpClient(); String s = cl.GetBodyText(command); return(AccessTokenInfo.Create(s, "oauth_token", "oauth_token_secret")); }
/// <summary> /// /// </summary> /// <returns></returns> public AuthorizeInfo GetAuthorizeInfo() { String url = this.RequestTokenUrl; var cm = new GetRequestTokenCommand(this.ConsumerKey, this.ConsumerSecret, "", "", HttpMethodName.Post); SignatureInfo si = OAuthClient.GenerateSignature(new Uri(url), cm, OAuthSignatureTypes.HMACSHA1); HttpClient cl = new HttpClient(); HttpRequestCommand command = new HttpRequestCommand(String.Format("{0}?{1}&oauth_signature={2}", url, si.NormalizedRequestParameters, si.Signature), HttpMethodName.Post); String result = cl.GetBodyText(command); //正規表現でoauth_token,oauth_token_secret取得 AuthorizeInfo ai = new AuthorizeInfo(); ai.AuthorizeUrl = String.Format("{0}?{1}", this.AuthorizeUrl, result); ai.RequestToken = this.GetMatchValue(RegexList.OAuthToken, result); ai.RequestTokenSecret = this.GetMatchValue(RegexList.OAuthTokenSecret, result); return(ai); }