public async Task <OauthToken> GetAccessToken(OauthToken token) { AuthorizationParameters = new Dictionary <string, string>() { { OauthParameter.OauthConsumerKey, _keys.Value.ConsumerKey }, { OauthParameter.OauthNonce, GetNonce() }, { OauthParameter.OauthSignatureMethod, OAuthSignatureMethod }, { OauthParameter.OauthTimestamp, GetTimeStamp() }, { OauthParameter.OauthToken, token.Token }, { OauthParameter.OauthVerifier, token.Verifier }, { OauthParameter.OauthVersion, OAuthVersion } }; Sign(AccessTokenUrl, _keys.Value.ConsumerSecret, token.Secret, "POST", ""); var response = await PostRequest(AccessTokenUrl); return(ParseReponse(response)); }
protected OauthToken ParseReponse(string response) { var token = new OauthToken(); if (string.IsNullOrEmpty(response)) { return(token); } // "oauth_token=qWnfRDBG47T57ud3peQeYtWHjoGSlbYtAwboQZuD&oauth_token_secret=iZJG3SKMA8BJexk4iEtQTwZmbstfR1TqoY1yKBo6&oauth_callback_confirmed=true" string var keyValPairs = response.Split('&'); foreach (var splits in keyValPairs.Select(t => t.Split('='))) { switch (splits[0]) { case "oauth_token": token.Token = splits[1]; break; case "oauth_token_secret": token.Secret = splits[1]; break; case "oauth_expires_in": int seconds; if (int.TryParse(splits[1], out seconds)) { token.Expires = DateTime.Now.AddSeconds(seconds); } break; case "oauth_session_handle": token.SessionHandle = splits[1]; break; } } return(token); }
/// <summary> /// A callback is needed to get back oauth_token and oauth_verifier /// </summary> /// <param name="token"></param> /// <returns></returns> public string GetAuthorizationUrl(OauthToken token) { return(AuthorizeUrl + "?oauth_token=" + token.Token); }