// Makes an OAuth signature out of the HTTP method, the base URI and the headers static string MakeSignature(string method, string base_uri, Dictionary <string, string> headers) { var items = from k in headers.Keys orderby k select k + "%3D" + OAuth.PercentEncode(headers [k]); return(method + "&" + OAuth.PercentEncode(base_uri) + "&" + string.Join("%26", items.ToArray())); }
public void EditList(string originalName, ListDefinition list) { var editor = new DialogViewController(null, true); var name = new EntryElement(Locale.GetText("Name"), null, list.Name); name.Changed += delegate { editor.NavigationItem.RightBarButtonItem.Enabled = !String.IsNullOrEmpty(name.Value); }; var description = new EntryElement(Locale.GetText("Description"), Locale.GetText("optional"), list.Description); var privacy = new RootElement(Locale.GetText("Privacy"), new RadioGroup("key", (int)list.Privacy)) { new Section() { new RadioElement(Locale.GetText("Public")), new RadioElement(Locale.GetText("Private")) } }; editor.NavigationItem.SetLeftBarButtonItem(new UIBarButtonItem(UIBarButtonSystemItem.Cancel, delegate { DeactivateController(true); }), false); editor.NavigationItem.SetRightBarButtonItem(new UIBarButtonItem(UIBarButtonSystemItem.Save, delegate { string url = String.Format("http://api.twitter.com/1/{0}/lists{1}.json?name={2}&mode={3}{4}", TwitterAccount.CurrentAccount.Username, originalName == null ? "" : "/" + originalName, OAuth.PercentEncode(name.Value), privacy.RadioSelected == 0 ? "public" : "private", description.Value == null ? "" : "&description=" + OAuth.PercentEncode(description.Value)); TwitterAccount.CurrentAccount.Post(url, ""); }), false); editor.NavigationItem.RightBarButtonItem.Enabled = !String.IsNullOrEmpty(name.Value); editor.Root = new RootElement(Locale.GetText("New List")) { new Section() { name, description, privacy } }; ActivateController(editor); }
// // Assign the result to the Authorization header, like this: // request.Headers [HttpRequestHeader.Authorization] = AuthorizeRequest (...) // public static string AuthorizeRequest(OAuthConfig config, string oauthToken, string oauthTokenSecret, string method, Uri uri, string data) { var headers = new Dictionary <string, string>() { { "oauth_consumer_key", config.ConsumerKey }, { "oauth_nonce", MakeNonce() }, { "oauth_signature_method", "HMAC-SHA1" }, { "oauth_timestamp", MakeTimestamp() }, { "oauth_token", oauthToken }, { "oauth_version", "1.0" } }; var signatureHeaders = new Dictionary <string, string> (headers); // Add the data and URL query string to the copy of the headers for computing the signature if (data != null && data != "") { var parsed = HttpUtility.ParseQueryString(data); foreach (string k in parsed.Keys) { signatureHeaders.Add(k, OAuth.PercentEncode(parsed [k])); } } var nvc = HttpUtility.ParseQueryString(uri.Query); foreach (string key in nvc) { if (key != null) { signatureHeaders.Add(key, OAuth.PercentEncode(nvc [key])); } } string signature = MakeSignature(method, uri.GetLeftPart(UriPartial.Path), signatureHeaders); string compositeSigningKey = MakeSigningKey(config.ConsumerSecret, oauthTokenSecret); string oauth_signature = MakeOAuthSignature(compositeSigningKey, signature); headers.Add("oauth_signature", OAuth.PercentEncode(oauth_signature)); return(HeadersToOAuth(headers)); }
void Post() { var content = new StringBuilder(); var account = TwitterAccount.CurrentAccount; if (directRecipient == null) { content.AppendFormat("status={0}", OAuth.PercentEncode(composerView.Text)); AppendLocation(content); if (InReplyTo != 0) { content.AppendFormat("&in_reply_to_status_id={0}", InReplyTo); } account.Post("http://twitter.com/statuses/update.json", content.ToString()); } else { content.AppendFormat("text={0}&user={1}", OAuth.PercentEncode(composerView.Text), OAuth.PercentEncode(directRecipient)); AppendLocation(content); account.Post("http://twitter.com/direct_messages/new.json", content.ToString()); } CloseComposer(this, EventArgs.Empty); }
public bool AcquireRequestToken() { var headers = new Dictionary <string, string> () { { "oauth_callback", OAuth.PercentEncode(config.Callback) }, { "oauth_consumer_key", config.ConsumerKey }, { "oauth_nonce", MakeNonce() }, { "oauth_signature_method", "HMAC-SHA1" }, { "oauth_timestamp", MakeTimestamp() }, { "oauth_version", "1.0" } }; string signature = MakeSignature("POST", config.RequestTokenUrl, headers); string compositeSigningKey = MakeSigningKey(config.ConsumerSecret, null); string oauth_signature = MakeOAuthSignature(compositeSigningKey, signature); var wc = new WebClient(); headers.Add("oauth_signature", OAuth.PercentEncode(oauth_signature)); wc.Headers [HttpRequestHeader.Authorization] = HeadersToOAuth(headers); try { var result = HttpUtility.ParseQueryString(wc.UploadString(new Uri(config.RequestTokenUrl), "")); if (result ["oauth_callback_confirmed"] != null) { RequestToken = result ["oauth_token"]; RequestTokenSecret = result ["oauth_token_secret"]; return(true); } } catch (Exception e) { Console.WriteLine(e); // fallthrough for errors } return(false); }
// // Used to authorize an HTTP request going to TwitPic // public static void AuthorizeTwitPic(OAuthConfig config, HttpWebRequest wc, string oauthToken, string oauthTokenSecret) { var headers = new Dictionary <string, string>() { { "oauth_consumer_key", config.ConsumerKey }, { "oauth_nonce", MakeNonce() }, { "oauth_signature_method", "HMAC-SHA1" }, { "oauth_timestamp", MakeTimestamp() }, { "oauth_token", oauthToken }, { "oauth_version", "1.0" }, //{ "realm", "http://api.twitter.com" } }; string signurl = "http://api.twitter.com/1/account/verify_credentials.xml"; // The signature is not done against the *actual* url, it is done against the verify_credentials.json one string signature = MakeSignature("GET", signurl, headers); string compositeSigningKey = MakeSigningKey(config.ConsumerSecret, oauthTokenSecret); string oauth_signature = MakeOAuthSignature(compositeSigningKey, signature); headers.Add("oauth_signature", OAuth.PercentEncode(oauth_signature)); Util.Log("Headers: " + HeadersToOAuth(headers)); wc.Headers.Add("X-Verify-Credentials-Authorization", HeadersToOAuth(headers)); wc.Headers.Add("X-Auth-Service-Provider", signurl); }
// Invoked after the user has authorized us // // TODO: this should return the stream error for invalid passwords instead of // just true/false. public bool AcquireAccessToken() { var headers = new Dictionary <string, string> () { { "oauth_consumer_key", config.ConsumerKey }, { "oauth_nonce", MakeNonce() }, { "oauth_signature_method", "HMAC-SHA1" }, { "oauth_timestamp", MakeTimestamp() }, { "oauth_version", "1.0" } }; var content = ""; if (xAuthUsername == null) { headers.Add("oauth_token", AuthorizationToken); headers.Add("oauth_verifier", AuthorizationVerifier); } else { headers.Add("x_auth_username", OAuth.PercentEncode(xAuthUsername)); headers.Add("x_auth_password", OAuth.PercentEncode(xAuthPassword)); headers.Add("x_auth_mode", "client_auth"); content = String.Format("x_auth_mode=client_auth&x_auth_password={0}&x_auth_username={1}", OAuth.PercentEncode(xAuthPassword), OAuth.PercentEncode(xAuthUsername)); } string signature = MakeSignature("POST", config.AccessTokenUrl, headers); string compositeSigningKey = MakeSigningKey(config.ConsumerSecret, RequestTokenSecret); string oauth_signature = MakeOAuthSignature(compositeSigningKey, signature); var wc = new WebClient(); headers.Add("oauth_signature", OAuth.PercentEncode(oauth_signature)); if (xAuthUsername != null) { headers.Remove("x_auth_username"); headers.Remove("x_auth_password"); headers.Remove("x_auth_mode"); } wc.Headers [HttpRequestHeader.Authorization] = HeadersToOAuth(headers); try { var result = HttpUtility.ParseQueryString(wc.UploadString(new Uri(config.AccessTokenUrl), content)); if (result ["oauth_token"] != null) { AccessToken = result ["oauth_token"]; AccessTokenSecret = result ["oauth_token_secret"]; AccessScreenname = result ["screen_name"]; AccessId = Int64.Parse(result ["user_id"]); return(true); } } catch (WebException e) { var x = e.Response.GetResponseStream(); var j = new System.IO.StreamReader(x); Console.WriteLine(j.ReadToEnd()); Console.WriteLine(e); // fallthrough for errors } return(false); }
static string MakeSigningKey(string consumerSecret, string oauthTokenSecret) { return(OAuth.PercentEncode(consumerSecret) + "&" + (oauthTokenSecret != null ? OAuth.PercentEncode(oauthTokenSecret) : "")); }
void CreateUI() { System.Threading.Thread.Sleep(2000); if (spinner != null) { spinner.RemoveFromSuperview(); spinner = null; } var profileRect = new RectangleF(PadX, 0, View.Bounds.Width - PadX, 100); var shortProfileView = new ShortProfileView(profileRect, user.Id, false); shortProfileView.PictureTapped += delegate { PictureViewer.Load(this, user.Id); }; shortProfileView.UrlTapped += delegate { WebViewController.OpenUrl(this, user.Url); }; var main = new Section(shortProfileView); if (!String.IsNullOrEmpty(user.Description)) { main.Add(new StyledMultilineElement(user.Description) { Lines = 0, LineBreakMode = UILineBreakMode.WordWrap, Font = UIFont.SystemFontOfSize(14), }); } ; var tweetsUrl = String.Format("http://api.twitter.com/1/statuses/user_timeline.json?skip_user=true&id={0}", user.Id); var favoritesUrl = String.Format("http://api.twitter.com/1/favorites.json?id={0}", user.Id); var followersUrl = String.Format("http://api.twitter.com/1/statuses/followers.json?id={0}", user.Id); var friendsUrl = String.Format("http://api.twitter.com/1/statuses/friends.json?id={0}", user.Id); #if false followButton = new StyledStringElement(FollowText, ToggleFollow) { Alignment = UITextAlignment.Center, TextColor = UIColor.FromRGB(0x32, 0x4f, 0x85) }; #endif var sfollow = new Section() { new ActivityElement() }; Root = new RootElement(user.Screenname) { main, new Section() { TimelineRootElement.MakeTimeline(user.Screenname, Locale.Format("{0:#,#} tweets", user.StatusesCount), tweetsUrl, user), TimelineRootElement.MakeFavorites(user.Screenname, Locale.Format("{0:#,#} favorites", user.FavCount), favoritesUrl, null), new UserRootElement(user, Locale.Format("{0:#,#} friends", user.FriendsCount), friendsUrl), new UserRootElement(user, Locale.Format("{0:#,#} followers", user.FollowersCount), followersUrl), }, sfollow, }; var created = user.CreatedAt; if (created.HasValue) { Root.Add(new Section(null, Locale.Format("Joined on {0}", created.Value.ToLongDateString()))); } string url = String.Format("http://api.twitter.com/1/friendships/show.json?target_id={0}&source_screen_name={1}", user.Id, OAuth.PercentEncode(TwitterAccount.CurrentAccount.Username)); TwitterAccount.CurrentAccount.Download(url, res => { TableView.BeginUpdates(); Root.Remove(sfollow); if (res != null) { ParseFollow(res); } TableView.EndUpdates(); }); }
public SearchViewController(string search) : base(search, "http://search.twitter.com/search.json?q=" + OAuth.PercentEncode(search), "rpp=", 50, "since_id=", "page=", null) { //View.AddSubview (bottomBar); }