/// <summary> /// /// </summary> /// <param name="accessToken"></param> public void SetProperty(OAuth1AccessToken accessToken) { this.Token = accessToken.Token; this.TokenSecret = accessToken.TokenSecret; foreach (var key in accessToken.Values.Keys) { this.Values[key] = accessToken.Values[key]; } }
/// <summary> /// /// </summary> /// <param name="authorizeInfo"></param> /// <param name="oauthVerifier"></param> /// <returns></returns> public OAuth1AccessToken GetAccessToken(OAuth1AuthorizeInfo authorizeInfo, String oauthVerifier) { var ai = authorizeInfo; var cm = new GetRequestTokenCommand(this.ConsumerKey, this.ConsumerSecret , ai.RequestToken, ai.RequestTokenSecret, HttpMethodName.Post); var si = OAuth1Client.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); var res = this.GetResponse(command); return(OAuth1AccessToken.Create(res.BodyText)); }
/// <summary> /// /// </summary> /// <param name="requestToken"></param> /// <param name="requestTokenSecret"></param> /// <returns></returns> public OAuth1AccessToken GetAccessToken(String requestToken, String requestTokenSecret) { String url = this.AccessTokenUrl; GetRequestTokenCommand cm = new GetRequestTokenCommand(this.ConsumerKey, this.ConsumerSecret , requestToken, requestTokenSecret, HttpMethodName.Post); SignatureInfo si = OAuth1Client.GenerateSignature(new Uri(url), cm, OAuthSignatureTypes.HMACSHA1); HttpRequestCommand command = new HttpRequestCommand(String.Format("{0}?{1}&oauth_signature={2}", url, si.NormalizedRequestParameters, si.Signature), HttpMethodName.Post); var res = this.GetResponse(command); return(OAuth1AccessToken.Create(res.BodyText)); }
/// <summary> /// /// </summary> /// <param name="value"></param> /// <param name="tokenKey"></param> /// <param name="tokenSecretKey"></param> /// <returns></returns> public static OAuth1AccessToken Create(String value) { OAuth1AccessToken t = new OAuth1AccessToken(); t.RawValue = value; var tokenKey = "oauth_token"; var tokenSecretKey = "oauth_token_secret"; String[] ss = value.Split('&'); String[] sss = null; Dictionary <String, String> d = new Dictionary <string, string>(); for (int i = 0; i < ss.Length; i++) { if (ss[i].Contains("=") == false) { continue; } sss = ss[i].Split('='); if (sss.Length == 2) { d[sss[0].ToLower()] = sss[1]; } } t.Values = d; if (d.ContainsKey(tokenKey) == true) { t.Token = d[tokenKey]; } if (d.ContainsKey(tokenSecretKey) == true) { t.TokenSecret = d[tokenSecretKey]; } if (String.IsNullOrEmpty(t.Token) == false && String.IsNullOrEmpty(t.TokenSecret) == false) { t.State = OAuthAccessTokenState.Success; } else { t.State = OAuthAccessTokenState.Error; } return(t); }
/// <summary> /// /// </summary> /// <param name="value"></param> /// <param name="tokenKey"></param> /// <param name="tokenSecretKey"></param> /// <returns></returns> public static OAuth1AccessToken Create(String value) { OAuth1AccessToken t = new OAuth1AccessToken(); t.RawValue = value; var tokenKey = "oauth_token"; var tokenSecretKey = "oauth_token_secret"; String[] ss = value.Split('&'); String[] sss = null; Dictionary<String, String> d = new Dictionary<string, string>(); for (int i = 0; i < ss.Length; i++) { if (ss[i].Contains("=") == false) { continue; } sss = ss[i].Split('='); if (sss.Length == 2) { d[sss[0].ToLower()] = sss[1]; } } t.Values = d; if (d.ContainsKey(tokenKey) == true) { t.Token = d[tokenKey]; } if (d.ContainsKey(tokenSecretKey) == true) { t.TokenSecret = d[tokenSecretKey]; } if (String.IsNullOrEmpty(t.Token) == false && String.IsNullOrEmpty(t.TokenSecret) == false) { t.State = OAuthAccessTokenState.Success; } else { t.State = OAuthAccessTokenState.Error; } return t; }
/// <summary> /// /// </summary> /// <param name="accessToken"></param> public void SetProperty(OAuth1AccessToken accessToken) { this.Token = accessToken.Token; this.TokenSecret = accessToken.TokenSecret; foreach (var key in accessToken.Values.Keys) { this.Values[key] = accessToken.Values[key]; } }