Some oAuth fixes for Imgur & Photobucket. Still having problems with Photobucket...

git-svn-id: http://svn.code.sf.net/p/greenshot/code/trunk@2026 7dccd23d-a4a3-4e1f-8c07-b4c1b4018ab4
This commit is contained in:
RKrom 2012-09-12 12:43:02 +00:00
parent daf24cdca0
commit f447fb8b72
11 changed files with 165 additions and 118 deletions

View file

@ -157,11 +157,13 @@ namespace GreenshotImgurPlugin {
imgurInfo.Image = ImageHelper.CreateThumbnail(image, 90, 90); imgurInfo.Image = ImageHelper.CreateThumbnail(image, 90, 90);
IniConfig.Save(); IniConfig.Save();
uploadURL = imgurInfo.Page; uploadURL = null;
try { try {
if (config.UsePageLink) { if (config.UsePageLink) {
uploadURL = imgurInfo.Page;
Clipboard.SetText(imgurInfo.Page); Clipboard.SetText(imgurInfo.Page);
} else { } else {
uploadURL = imgurInfo.Original;
Clipboard.SetText(imgurInfo.Original); Clipboard.SetText(imgurInfo.Original);
} }
} catch (Exception ex) { } catch (Exception ex) {

View file

@ -134,9 +134,7 @@ namespace GreenshotImgurPlugin {
uploadRequest.Append(EscapeText(System.Convert.ToBase64String(imageData, 0, dataLength))); uploadRequest.Append(EscapeText(System.Convert.ToBase64String(imageData, 0, dataLength)));
// add type // add type
uploadRequest.Append("&type=base64"); uploadRequest.Append("&type=base64");
// add key
uploadRequest.Append("&key=");
uploadRequest.Append(IMGUR_ANONYMOUS_API_KEY);
// add title // add title
if (title != null) { if (title != null) {
uploadRequest.Append("&title="); uploadRequest.Append("&title=");
@ -151,6 +149,9 @@ namespace GreenshotImgurPlugin {
string responseString; string responseString;
if (config.AnonymousAccess) { if (config.AnonymousAccess) {
// add key
uploadRequest.Append("&key=");
uploadRequest.Append(IMGUR_ANONYMOUS_API_KEY);
url = config.ImgurApiUrl + "/upload"; url = config.ImgurApiUrl + "/upload";
HttpWebRequest webRequest = (HttpWebRequest)NetworkHelper.CreateWebRequest(url); HttpWebRequest webRequest = (HttpWebRequest)NetworkHelper.CreateWebRequest(url);
@ -171,10 +172,12 @@ namespace GreenshotImgurPlugin {
} else { } else {
url = config.ImgurApiUrl + "/account/images"; url = config.ImgurApiUrl + "/account/images";
OAuthHelper oAuth = new OAuthHelper(); OAuthHelper oAuth = new OAuthHelper();
oAuth.BrowserWidth = 650;
oAuth.BrowserHeight = 500;
oAuth.CallbackUrl = "http://getgreenshot.org"; oAuth.CallbackUrl = "http://getgreenshot.org";
oAuth.AccessTokenUrl = "https://api.imgur.com/oauth/access_token"; oAuth.AccessTokenUrl = "http://api.imgur.com/oauth/access_token";
oAuth.AuthorizeUrl = "https://api.imgur.com/oauth/authorize"; oAuth.AuthorizeUrl = "http://api.imgur.com/oauth/authorize";
oAuth.RequestTokenUrl = "https://api.imgur.com/oauth/request_token"; oAuth.RequestTokenUrl = "http://api.imgur.com/oauth/request_token";
oAuth.ConsumerKey = "fill-in"; oAuth.ConsumerKey = "fill-in";
oAuth.ConsumerSecret = "fill-in"; oAuth.ConsumerSecret = "fill-in";
oAuth.UserAgent = "Greenshot"; oAuth.UserAgent = "Greenshot";
@ -291,31 +294,5 @@ namespace GreenshotImgurPlugin {
} catch {} } catch {}
} }
public static void ImgurOAuthExample() {
OAuthHelper oAuth = new OAuthHelper();
oAuth.CallbackUrl = "http://getgreenshot.org";
oAuth.AccessTokenUrl = "https://api.imgur.com/oauth/access_token";
oAuth.AuthorizeUrl = "https://api.imgur.com/oauth/authorize";
oAuth.RequestTokenUrl = "https://api.imgur.com/oauth/request_token";
oAuth.ConsumerKey = "907d4455b8c38144d68c4f72190af4c40504a0ac7";
oAuth.ConsumerSecret = "d33902ef409fea163ab755454c15b3d0";
oAuth.UserAgent = "Greenshot";
if (string.IsNullOrEmpty(config.ImgurToken)) {
LOG.Debug("Creating Imgur Token");
oAuth.getRequestToken();
if (string.IsNullOrEmpty(oAuth.authorizeToken("Imgur authorization"))) {
return;
}
string accessToken = oAuth.getAccessToken();
config.ImgurToken = oAuth.Token;
config.ImgurTokenSecret = oAuth.TokenSecret;
} else {
LOG.Debug("Using stored Imgur Token");
oAuth.Token = config.ImgurToken;
oAuth.TokenSecret = config.ImgurTokenSecret;
}
System.Windows.Forms.MessageBox.Show(oAuth.oAuthWebRequest(OAuthHelper.Method.GET, "http://api.imgur.com/2/account", null));
}
} }
} }

View file

@ -32,9 +32,6 @@ namespace GreenshotPhotobucketPlugin {
/// </summary> /// </summary>
[IniSection("Photobucket", Description="Greenshot Photobucket Plugin configuration")] [IniSection("Photobucket", Description="Greenshot Photobucket Plugin configuration")]
public class PhotobucketConfiguration : IniSection { public class PhotobucketConfiguration : IniSection {
[IniProperty("PhotobucketApiUrl", Description = "Url to Photobucket system.", DefaultValue = "http://api.photobucket.com")]
public string PhotobucketApiUrl;
[IniProperty("UploadFormat", Description="What file type to use for uploading", DefaultValue="png")] [IniProperty("UploadFormat", Description="What file type to use for uploading", DefaultValue="png")]
public OutputFormat UploadFormat; public OutputFormat UploadFormat;
[IniProperty("UploadJpegQuality", Description="JPEG file save quality in %.", DefaultValue="80")] [IniProperty("UploadJpegQuality", Description="JPEG file save quality in %.", DefaultValue="80")]

View file

@ -117,22 +117,24 @@ namespace GreenshotPhotobucketPlugin {
host.SaveToStream(image, stream, outputSettings); host.SaveToStream(image, stream, outputSettings);
try { try {
string filename = Path.GetFileName(host.GetFilename(config.UploadFormat, captureDetails)); string filename = Path.GetFileName(host.GetFilename(config.UploadFormat, captureDetails));
PhotobucketInfo PhotobucketInfo = null; PhotobucketInfo photobucketInfo = null;
// Run upload in the background // Run upload in the background
new PleaseWaitForm().ShowAndWait(Attributes.Name, Language.GetString("photobucket", LangKey.communication_wait), new PleaseWaitForm().ShowAndWait(Attributes.Name, Language.GetString("photobucket", LangKey.communication_wait),
delegate() { delegate() {
PhotobucketInfo = PhotobucketUtils.UploadToPhotobucket(stream.GetBuffer(), (int)stream.Length, captureDetails.Title, filename); photobucketInfo = PhotobucketUtils.UploadToPhotobucket(stream.GetBuffer(), (int)stream.Length, captureDetails.Title, filename);
} }
); );
// This causes an exeption if the upload failed :)
LOG.DebugFormat("Uploaded to Photobucket page: " + photobucketInfo.Page);
uploadURL = null; uploadURL = null;
try { try {
if (config.UsePageLink) { if (config.UsePageLink) {
uploadURL = PhotobucketInfo.Page; uploadURL = photobucketInfo.Page;
Clipboard.SetText(PhotobucketInfo.Page); Clipboard.SetText(photobucketInfo.Page);
} else { } else {
uploadURL = PhotobucketInfo.Original; uploadURL = photobucketInfo.Original;
Clipboard.SetText(PhotobucketInfo.Original); Clipboard.SetText(photobucketInfo.Original);
} }
} catch (Exception ex) { } catch (Exception ex) {
LOG.Error("Can't write to clipboard: ", ex); LOG.Error("Can't write to clipboard: ", ex);

View file

@ -93,20 +93,30 @@ namespace GreenshotPhotobucketPlugin {
uploadRequest.Append("&filename="); uploadRequest.Append("&filename=");
uploadRequest.Append(EscapeText(filename)); uploadRequest.Append(EscapeText(filename));
} }
string url = config.PhotobucketApiUrl + "/album/greenshot/upload"; string url = "http://api.photobucket.com/album/greenshot/upload";
string responseString; string responseString;
OAuthHelper oAuth = new OAuthHelper(); OAuthHelper oAuth = new OAuthHelper();
// This url is configured in the Photobucket API settings in the Photobucket site!!
oAuth.CallbackUrl = "http://getgreenshot.org"; oAuth.CallbackUrl = "http://getgreenshot.org";
oAuth.AccessTokenUrl = "http://api.photobucket.com/login/access"; oAuth.AccessTokenUrl = "http://api.photobucket.com/login/access";
oAuth.AuthorizeUrl = " http://photobucket.com/apilogin/login"; oAuth.AuthorizeUrl = "http://photobucket.com/apilogin/login";
oAuth.RequestTokenUrl = "http://api.photobucket.com/login/request"; oAuth.RequestTokenUrl = "http://api.photobucket.com/login/request";
oAuth.ConsumerKey = "fill-in"; oAuth.ConsumerKey = "fill-in";
oAuth.ConsumerSecret = "fill-in"; oAuth.ConsumerSecret = "fill-in";
oAuth.UserAgent = "Greenshot"; oAuth.UserAgent = "Greenshot";
oAuth.BrowserWidth = 1010;
oAuth.BrowserHeight = 400;
oAuth.CheckVerifier = false;
if (string.IsNullOrEmpty(config.PhotobucketToken)) { if (string.IsNullOrEmpty(config.PhotobucketToken)) {
LOG.Debug("Creating Photobucket Token"); LOG.Debug("Creating Photobucket Token");
oAuth.getRequestToken(); try {
oAuth.getRequestToken();
} catch (Exception ex) {
LOG.Error(ex);
throw new NotSupportedException("Photobucket is not available: " + ex.Message);
}
LOG.Debug("Authorizing Photobucket");
if (string.IsNullOrEmpty(oAuth.authorizeToken("Photobucket authorization"))) { if (string.IsNullOrEmpty(oAuth.authorizeToken("Photobucket authorization"))) {
return null; return null;
} }

View file

@ -44,52 +44,49 @@ namespace GreenshotPlugin.Controls {
/// the contents of this method with the code editor. /// the contents of this method with the code editor.
/// </summary> /// </summary>
private void InitializeComponent() { private void InitializeComponent() {
this.browser = new System.Windows.Forms.WebBrowser(); this.addressTextBox = new System.Windows.Forms.TextBox();
this.addressTextBox = new System.Windows.Forms.TextBox(); this.browser = new System.Windows.Forms.WebBrowser();
this.SuspendLayout(); this.SuspendLayout();
// //
// browser // addressTextBox
// //
this.browser.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) this.addressTextBox.Cursor = System.Windows.Forms.Cursors.Arrow;
| System.Windows.Forms.AnchorStyles.Left) this.addressTextBox.Dock = System.Windows.Forms.DockStyle.Top;
| System.Windows.Forms.AnchorStyles.Right))); this.addressTextBox.Enabled = false;
this.browser.Location = new System.Drawing.Point(0, 26); this.addressTextBox.Location = new System.Drawing.Point(0, 0);
this.browser.MinimumSize = new System.Drawing.Size(20, 20); this.addressTextBox.Name = "addressTextBox";
this.browser.Name = "browser"; this.addressTextBox.Size = new System.Drawing.Size(595, 20);
this.browser.Size = new System.Drawing.Size(864, 561); this.addressTextBox.TabIndex = 3;
this.browser.TabIndex = 0; this.addressTextBox.TabStop = false;
this.browser.Navigating += new System.Windows.Forms.WebBrowserNavigatingEventHandler(this.webBrowser1_Navigating); //
this.browser.Navigated += new System.Windows.Forms.WebBrowserNavigatedEventHandler(this.browser_Navigated); // browser
// //
// addressTextBox this.browser.Dock = System.Windows.Forms.DockStyle.Fill;
// this.browser.Location = new System.Drawing.Point(0, 20);
this.addressTextBox.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) this.browser.MinimumSize = new System.Drawing.Size(100, 100);
| System.Windows.Forms.AnchorStyles.Right))); this.browser.Name = "browser";
this.addressTextBox.Location = new System.Drawing.Point(7, 2); this.browser.Size = new System.Drawing.Size(595, 295);
this.addressTextBox.Name = "addressTextBox"; this.browser.TabIndex = 4;
this.addressTextBox.Size = new System.Drawing.Size(840, 20); //
this.addressTextBox.TabIndex = 1; // OAuthLoginForm
this.addressTextBox.TabStop = false; //
this.addressTextBox.KeyPress += new System.Windows.Forms.KeyPressEventHandler(this.addressTextBox_KeyPress); this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
// this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
// LoginForm this.ClientSize = new System.Drawing.Size(595, 315);
// this.Controls.Add(this.browser);
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); this.Controls.Add(this.addressTextBox);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.MaximizeBox = false;
this.ClientSize = new System.Drawing.Size(864, 587); this.MinimizeBox = false;
this.Controls.Add(this.addressTextBox); this.Name = "OAuthLoginForm";
this.Controls.Add(this.browser); this.ResumeLayout(false);
this.MaximizeBox = false; this.PerformLayout();
this.MinimizeBox = false;
this.Name = "LoginForm";
this.ShowInTaskbar = false;
this.ResumeLayout(false);
this.PerformLayout();
} }
#endregion #endregion
private System.Windows.Forms.WebBrowser browser; private System.Windows.Forms.TextBox addressTextBox;
private System.Windows.Forms.TextBox addressTextBox; private System.Windows.Forms.WebBrowser browser;
} }
} }

View file

@ -33,6 +33,7 @@ namespace GreenshotPlugin.Controls {
/// The OAuthLoginForm is used to allow the user to authorize Greenshot with an "Oauth" application /// The OAuthLoginForm is used to allow the user to authorize Greenshot with an "Oauth" application
/// </summary> /// </summary>
public partial class OAuthLoginForm : Form { public partial class OAuthLoginForm : Form {
private static readonly log4net.ILog LOG = log4net.LogManager.GetLogger(typeof(OAuthLoginForm));
private OAuthHelper _oauth; private OAuthHelper _oauth;
private String _token; private String _token;
private String _verifier; private String _verifier;
@ -56,25 +57,39 @@ namespace GreenshotPlugin.Controls {
} }
} }
public OAuthLoginForm(OAuthHelper o, string browserTitle) { public OAuthLoginForm(OAuthHelper o, string browserTitle, int width, int height) {
_oauth = o; _oauth = o;
_token = null; _token = null;
InitializeComponent(); InitializeComponent();
this.ClientSize = new System.Drawing.Size(width, height);
this.Icon = GreenshotPlugin.Core.GreenshotResources.getGreenshotIcon(); this.Icon = GreenshotPlugin.Core.GreenshotResources.getGreenshotIcon();
this.Text = browserTitle; this.Text = browserTitle;
this.addressTextBox.Text = o.AuthorizationLink; this.addressTextBox.Text = o.AuthorizationLink;
_token = _oauth.Token; _token = _oauth.Token;
_tokenSecret = _oauth.TokenSecret; _tokenSecret = _oauth.TokenSecret;
browser.DocumentCompleted += new WebBrowserDocumentCompletedEventHandler(browser_DocumentCompleted);
browser.Navigate(new Uri(_oauth.AuthorizationLink)); browser.Navigate(new Uri(_oauth.AuthorizationLink));
WindowDetails.ToForeground(this.Handle);
} }
private void browser_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e) {
LOG.DebugFormat("document completed with url: {0}", browser.Url);
checkUrl();
}
private void webBrowser1_Navigating(object sender, WebBrowserNavigatingEventArgs e) { private void webBrowser1_Navigating(object sender, WebBrowserNavigatingEventArgs e) {
LOG.DebugFormat("Navigating to url: {0}", browser.Url);
this.addressTextBox.Text = e.Url.ToString(); this.addressTextBox.Text = e.Url.ToString();
} }
private void browser_Navigated(object sender, WebBrowserNavigatedEventArgs e) { private void browser_Navigated(object sender, WebBrowserNavigatedEventArgs e) {
if (browser.Url.ToString().Contains(_oauth.CallbackUrl)) { LOG.DebugFormat("Navigated to url: {0}", browser.Url);
string queryParams = e.Url.Query; checkUrl();
}
private void checkUrl() {
if (browser.Url.ToString().Contains(_oauth.CallbackUrl)) {
string queryParams = browser.Url.Query;
if (queryParams.Length > 0) { if (queryParams.Length > 0) {
//Store the Token and Token Secret //Store the Token and Token Secret
NameValueCollection qs = NetworkHelper.ParseQueryString(queryParams); NameValueCollection qs = NetworkHelper.ParseQueryString(queryParams);

View file

@ -91,7 +91,6 @@ namespace GreenshotPlugin.Controls {
this.SizeGripStyle = System.Windows.Forms.SizeGripStyle.Hide; this.SizeGripStyle = System.Windows.Forms.SizeGripStyle.Hide;
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent; this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent;
this.Text = "Greenshot"; this.Text = "Greenshot";
this.TopMost = true;
this.UseWaitCursor = true; this.UseWaitCursor = true;
this.ResumeLayout(false); this.ResumeLayout(false);
this.PerformLayout(); this.PerformLayout();

View file

@ -26,6 +26,8 @@ using System.Text;
using System.Collections.Specialized; using System.Collections.Specialized;
using System.Text.RegularExpressions; using System.Text.RegularExpressions;
using Greenshot.IniFile; using Greenshot.IniFile;
using System.Security.Cryptography.X509Certificates;
using System.Net.Security;
namespace GreenshotPlugin.Core { namespace GreenshotPlugin.Core {
/// <summary> /// <summary>
@ -35,6 +37,14 @@ namespace GreenshotPlugin.Core {
private static readonly log4net.ILog LOG = log4net.LogManager.GetLogger(typeof(NetworkHelper)); private static readonly log4net.ILog LOG = log4net.LogManager.GetLogger(typeof(NetworkHelper));
private static CoreConfiguration config = IniConfig.GetIniSection<CoreConfiguration>(); private static CoreConfiguration config = IniConfig.GetIniSection<CoreConfiguration>();
static NetworkHelper() {
// Disable certificate checking
System.Net.ServicePointManager.ServerCertificateValidationCallback +=
delegate(object sender, X509Certificate cert, X509Chain chain, SslPolicyErrors sslError) {
bool validationResult = true;
return validationResult;
};
}
/// <summary> /// <summary>
/// Download a file as string /// Download a file as string
/// </summary> /// </summary>

View file

@ -30,7 +30,7 @@ using GreenshotPlugin.Controls;
namespace GreenshotPlugin.Core { namespace GreenshotPlugin.Core {
public class OAuthHelper { public class OAuthHelper {
private static readonly log4net.ILog LOG = log4net.LogManager.GetLogger(typeof(OAuthHelper));
/// <summary> /// <summary>
/// Provides a predefined set of algorithms that are supported officially by the protocol /// Provides a predefined set of algorithms that are supported officially by the protocol
/// </summary> /// </summary>
@ -106,6 +106,10 @@ namespace GreenshotPlugin.Core {
public enum Method { GET, POST, PUT, DELETE }; public enum Method { GET, POST, PUT, DELETE };
private string _userAgent = "Greenshot"; private string _userAgent = "Greenshot";
private string _callbackUrl = "http://getgreenshot.org"; private string _callbackUrl = "http://getgreenshot.org";
private bool checkVerifier = true;
// default browser size
private int _browserWidth = 864;
private int _browserHeight = 587;
#region PublicPropertiies #region PublicPropertiies
public string ConsumerKey { get; set; } public string ConsumerKey { get; set; }
@ -115,7 +119,35 @@ namespace GreenshotPlugin.Core {
public string AuthorizeUrl { get; set; } public string AuthorizeUrl { get; set; }
public string AccessTokenUrl { get; set; } public string AccessTokenUrl { get; set; }
public string CallbackUrl { get { return _callbackUrl;} set { _callbackUrl = value; } } public string CallbackUrl { get { return _callbackUrl;} set { _callbackUrl = value; } }
public string Token { get; set; } public bool CheckVerifier {
get {
return checkVerifier;
}
set {
checkVerifier = value;
}
}
public int BrowserWidth {
get {
return _browserWidth;
}
set {
_browserWidth = value;
}
}
public int BrowserHeight {
get {
return _browserHeight;
}
set {
_browserHeight = value;
}
}
public string Token {
get;
set;
}
public string TokenSecret { get; set; } public string TokenSecret { get; set; }
#endregion #endregion
@ -183,7 +215,7 @@ namespace GreenshotPlugin.Core {
/// </summary> /// </summary>
/// <param name="value">The value to Url encode</param> /// <param name="value">The value to Url encode</param>
/// <returns>Returns a Url encoded string</returns> /// <returns>Returns a Url encoded string</returns>
public static string UrlEncodeSpecial(string value) { public static string UrlEncode3986(string value) {
StringBuilder result = new StringBuilder(); StringBuilder result = new StringBuilder();
foreach (char symbol in value) { foreach (char symbol in value) {
@ -260,7 +292,7 @@ namespace GreenshotPlugin.Core {
//TODO: Make this less of a hack //TODO: Make this less of a hack
if (!string.IsNullOrEmpty(callback)) { if (!string.IsNullOrEmpty(callback)) {
parameters.Add(new QueryParameter(OAuthCallbackKey, UrlEncodeSpecial(callback))); parameters.Add(new QueryParameter(OAuthCallbackKey, UrlEncode3986(callback)));
} }
if (!string.IsNullOrEmpty(token)) { if (!string.IsNullOrEmpty(token)) {
@ -284,8 +316,8 @@ namespace GreenshotPlugin.Core {
StringBuilder signatureBase = new StringBuilder(); StringBuilder signatureBase = new StringBuilder();
signatureBase.AppendFormat("{0}&", httpMethod.ToUpper()); signatureBase.AppendFormat("{0}&", httpMethod.ToUpper());
signatureBase.AppendFormat("{0}&", UrlEncodeSpecial(normalizedUrl)); signatureBase.AppendFormat("{0}&", UrlEncode3986(normalizedUrl));
signatureBase.AppendFormat("{0}", UrlEncodeSpecial(normalizedRequestParameters)); signatureBase.AppendFormat("{0}", UrlEncode3986(normalizedRequestParameters));
return signatureBase.ToString(); return signatureBase.ToString();
} }
@ -335,7 +367,7 @@ namespace GreenshotPlugin.Core {
case SignatureTypes.HMACSHA1: case SignatureTypes.HMACSHA1:
string signatureBase = GenerateSignatureBase(url, consumerKey, token, tokenSecret, httpMethod, timeStamp, nonce, callback, HMACSHA1SignatureType, out normalizedUrl, out normalizedRequestParameters); string signatureBase = GenerateSignatureBase(url, consumerKey, token, tokenSecret, httpMethod, timeStamp, nonce, callback, HMACSHA1SignatureType, out normalizedUrl, out normalizedRequestParameters);
HMACSHA1 hmacsha1 = new HMACSHA1(); HMACSHA1 hmacsha1 = new HMACSHA1();
hmacsha1.Key = Encoding.ASCII.GetBytes(string.Format("{0}&{1}", UrlEncodeSpecial(consumerSecret), string.IsNullOrEmpty(tokenSecret) ? "" : UrlEncodeSpecial(tokenSecret))); hmacsha1.Key = Encoding.ASCII.GetBytes(string.Format("{0}&{1}", UrlEncode3986(consumerSecret), string.IsNullOrEmpty(tokenSecret) ? "" : UrlEncode3986(tokenSecret)));
return GenerateSignatureUsingHash(signatureBase, hmacsha1); return GenerateSignatureUsingHash(signatureBase, hmacsha1);
case SignatureTypes.RSASHA1: case SignatureTypes.RSASHA1:
@ -356,15 +388,6 @@ namespace GreenshotPlugin.Core {
return Convert.ToInt64(ts.TotalSeconds).ToString(); return Convert.ToInt64(ts.TotalSeconds).ToString();
} }
/*
public virtual string GenerateTimeStamp() {
// Default implementation of UNIX time of the current UTC time
TimeSpan ts = DateTime.UtcNow - new DateTime(1970, 1, 1, 0, 0, 0, 0);
string timeStamp = ts.TotalSeconds.ToString();
timeStamp = timeStamp.Substring(0, timeStamp.IndexOf(","));
return Convert.ToInt64(timeStamp).ToString();
}*/
/// <summary> /// <summary>
/// Generate a nonce /// Generate a nonce
/// </summary> /// </summary>
@ -401,15 +424,19 @@ namespace GreenshotPlugin.Core {
Exception e = new Exception("The request token is not set"); Exception e = new Exception("The request token is not set");
throw e; throw e;
} }
LOG.DebugFormat("Opening browser for URL: {0}", AuthorizationLink);
OAuthLoginForm oAuthLoginForm = new OAuthLoginForm(this, browserTitle); OAuthLoginForm oAuthLoginForm = new OAuthLoginForm(this, browserTitle, BrowserWidth, BrowserHeight);
oAuthLoginForm.ShowDialog(); oAuthLoginForm.ShowDialog();
Token = oAuthLoginForm.Token; Token = oAuthLoginForm.Token;
Verifier = oAuthLoginForm.Verifier; if (CheckVerifier) {
if (!string.IsNullOrEmpty(Verifier)) { Verifier = oAuthLoginForm.Verifier;
return Token; if (!string.IsNullOrEmpty(Verifier)) {
return Token;
} else {
return null;
}
} else { } else {
return null; return Token;
} }
} }
@ -418,7 +445,7 @@ namespace GreenshotPlugin.Core {
/// </summary> /// </summary>
/// <returns>The access token.</returns> /// <returns>The access token.</returns>
public String getAccessToken() { public String getAccessToken() {
if (string.IsNullOrEmpty(Token) || string.IsNullOrEmpty(Verifier)) { if (string.IsNullOrEmpty(Token) || (CheckVerifier && string.IsNullOrEmpty(Verifier))) {
Exception e = new Exception("The request token and verifier were not set"); Exception e = new Exception("The request token and verifier were not set");
throw e; throw e;
} }
@ -472,7 +499,7 @@ namespace GreenshotPlugin.Core {
postData += "&"; postData += "&";
} }
qs[key] = NetworkHelper.UrlDecode(qs[key]); qs[key] = NetworkHelper.UrlDecode(qs[key]);
qs[key] = UrlEncodeSpecial(qs[key]); qs[key] = UrlEncode3986(qs[key]);
postData += key + "=" + qs[key]; postData += key + "=" + qs[key];
} }
@ -492,7 +519,7 @@ namespace GreenshotPlugin.Core {
string callback = ""; string callback = "";
if (url.ToString().Contains(RequestTokenUrl)) { if (url.ToString().Contains(RequestTokenUrl)) {
callback = _callbackUrl; callback = CallbackUrl;
} }
//Generate Signature //Generate Signature

View file

@ -333,7 +333,18 @@ namespace GreenshotPlugin.Core {
} }
return null; return null;
} }
/// <summary>
/// Retrieve the children with mathing classname
/// </summary>
public IEnumerable<WindowDetails> GetChilden(string childClassname) {
foreach (WindowDetails child in Children) {
if (childClassname.Equals(child.ClassName)) {
yield return child;
}
}
}
public IntPtr ParentHandle { public IntPtr ParentHandle {
get { get {
if (parentHandle == IntPtr.Zero) { if (parentHandle == IntPtr.Zero) {