2013-11-03 23:53:49 +13:00
|
|
|
|
#region License Information (GPL v3)
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
ShareX - A program that allows you to take screenshots and share any file type
|
2023-01-10 09:31:02 +13:00
|
|
|
|
Copyright (c) 2007-2023 ShareX Team
|
2013-11-03 23:53:49 +13:00
|
|
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or
|
|
|
|
|
modify it under the terms of the GNU General Public License
|
|
|
|
|
as published by the Free Software Foundation; either version 2
|
|
|
|
|
of the License, or (at your option) any later version.
|
|
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
|
along with this program; if not, write to the Free Software
|
|
|
|
|
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
|
|
|
|
|
|
Optionally you can also view the license at <http://www.gnu.org/licenses/>.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#endregion License Information (GPL v3)
|
|
|
|
|
|
2020-06-01 11:53:41 +12:00
|
|
|
|
using ShareX.HelpersLib;
|
2014-12-11 09:25:20 +13:00
|
|
|
|
using ShareX.UploadersLib.Properties;
|
2014-04-30 21:46:15 +12:00
|
|
|
|
using System;
|
2013-11-03 23:53:49 +13:00
|
|
|
|
using System.ComponentModel;
|
|
|
|
|
|
2016-03-24 08:05:31 +13:00
|
|
|
|
namespace ShareX.UploadersLib
|
2013-11-03 23:53:49 +13:00
|
|
|
|
{
|
2014-04-30 21:46:15 +12:00
|
|
|
|
public class OAuthInfo : ICloneable
|
2013-11-03 23:53:49 +13:00
|
|
|
|
{
|
|
|
|
|
public enum OAuthInfoSignatureMethod
|
|
|
|
|
{
|
|
|
|
|
HMAC_SHA1,
|
|
|
|
|
RSA_SHA1
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public string Description { get; set; }
|
|
|
|
|
|
|
|
|
|
[Browsable(false)]
|
|
|
|
|
public string OAuthVersion { get; set; }
|
|
|
|
|
|
|
|
|
|
[Browsable(false)]
|
|
|
|
|
public string ConsumerKey { get; set; }
|
|
|
|
|
|
|
|
|
|
// Used for HMAC_SHA1 signature
|
|
|
|
|
[Browsable(false)]
|
|
|
|
|
public string ConsumerSecret { get; set; }
|
|
|
|
|
|
|
|
|
|
// Used for RSA_SHA1 signature
|
|
|
|
|
[Browsable(false)]
|
|
|
|
|
public string ConsumerPrivateKey { get; set; }
|
|
|
|
|
|
|
|
|
|
[Browsable(false)]
|
|
|
|
|
public OAuthInfoSignatureMethod SignatureMethod { get; set; }
|
|
|
|
|
|
|
|
|
|
[Browsable(false)]
|
|
|
|
|
public string AuthToken { get; set; }
|
|
|
|
|
|
2020-06-01 11:53:41 +12:00
|
|
|
|
[Browsable(false), JsonEncrypt]
|
2013-11-03 23:53:49 +13:00
|
|
|
|
public string AuthSecret { get; set; }
|
|
|
|
|
|
2020-06-01 11:53:41 +12:00
|
|
|
|
[JsonEncrypt, Description("Verification Code from the Authorization Page")]
|
2013-11-03 23:53:49 +13:00
|
|
|
|
public string AuthVerifier { get; set; }
|
|
|
|
|
|
2014-05-30 23:38:23 +12:00
|
|
|
|
[Browsable(false)]
|
2013-11-03 23:53:49 +13:00
|
|
|
|
public string UserToken { get; set; }
|
|
|
|
|
|
2020-06-01 11:53:41 +12:00
|
|
|
|
[Browsable(false), JsonEncrypt]
|
2013-11-03 23:53:49 +13:00
|
|
|
|
public string UserSecret { get; set; }
|
|
|
|
|
|
|
|
|
|
public OAuthInfo()
|
|
|
|
|
{
|
2014-10-18 01:19:28 +13:00
|
|
|
|
Description = Resources.OAuthInfo_OAuthInfo_New_account;
|
2013-11-03 23:53:49 +13:00
|
|
|
|
OAuthVersion = "1.0";
|
|
|
|
|
}
|
|
|
|
|
|
2016-04-07 04:02:48 +12:00
|
|
|
|
public OAuthInfo(string consumerKey) : this()
|
2013-11-03 23:53:49 +13:00
|
|
|
|
{
|
|
|
|
|
ConsumerKey = consumerKey;
|
|
|
|
|
}
|
|
|
|
|
|
2016-04-07 04:02:48 +12:00
|
|
|
|
public OAuthInfo(string consumerKey, string consumerSecret) : this()
|
2013-11-03 23:53:49 +13:00
|
|
|
|
{
|
|
|
|
|
ConsumerKey = consumerKey;
|
|
|
|
|
ConsumerSecret = consumerSecret;
|
|
|
|
|
}
|
|
|
|
|
|
2016-04-07 04:02:48 +12:00
|
|
|
|
public OAuthInfo(string consumerKey, string consumerSecret, string userToken, string userSecret) : this(consumerKey, consumerSecret)
|
2013-11-03 23:53:49 +13:00
|
|
|
|
{
|
|
|
|
|
UserToken = userToken;
|
|
|
|
|
UserSecret = userSecret;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static bool CheckOAuth(OAuthInfo oauth)
|
|
|
|
|
{
|
|
|
|
|
return oauth != null && !string.IsNullOrEmpty(oauth.ConsumerKey) &&
|
2018-05-16 19:31:13 +12:00
|
|
|
|
((oauth.SignatureMethod == OAuthInfoSignatureMethod.HMAC_SHA1 && !string.IsNullOrEmpty(oauth.ConsumerSecret)) ||
|
|
|
|
|
(oauth.SignatureMethod == OAuthInfoSignatureMethod.RSA_SHA1 && !string.IsNullOrEmpty(oauth.ConsumerPrivateKey))) &&
|
|
|
|
|
!string.IsNullOrEmpty(oauth.UserToken) && !string.IsNullOrEmpty(oauth.UserSecret);
|
2013-11-03 23:53:49 +13:00
|
|
|
|
}
|
|
|
|
|
|
2014-04-30 21:46:15 +12:00
|
|
|
|
public OAuthInfo Clone()
|
|
|
|
|
{
|
|
|
|
|
return MemberwiseClone() as OAuthInfo;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
object ICloneable.Clone()
|
|
|
|
|
{
|
|
|
|
|
return Clone();
|
|
|
|
|
}
|
2015-09-03 03:41:02 +12:00
|
|
|
|
|
|
|
|
|
public override string ToString()
|
|
|
|
|
{
|
|
|
|
|
return Description;
|
|
|
|
|
}
|
2013-11-03 23:53:49 +13:00
|
|
|
|
}
|
|
|
|
|
}
|