2022-12-08 21:32:58 +13:00
|
|
|
|
#region License Information (GPL v3)
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
ShareX - A program that allows you to take screenshots and share any file type
|
2024-01-03 12:57:14 +13:00
|
|
|
|
Copyright (c) 2007-2024 ShareX Team
|
2022-12-08 21:32:58 +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)
|
|
|
|
|
|
|
|
|
|
using ShareX.HelpersLib;
|
|
|
|
|
using System;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
using System.Windows.Forms;
|
|
|
|
|
|
|
|
|
|
namespace ShareX.UploadersLib
|
|
|
|
|
{
|
|
|
|
|
public partial class OAuthListenerForm : Form
|
|
|
|
|
{
|
|
|
|
|
public IOAuth2Loopback OAuth { get; private set; }
|
|
|
|
|
public OAuth2Info OAuth2Info { get; private set; }
|
2022-12-09 00:48:35 +13:00
|
|
|
|
public OAuthUserInfo UserInfo { get; private set; }
|
2022-12-08 21:32:58 +13:00
|
|
|
|
|
|
|
|
|
private OAuthListener listener;
|
|
|
|
|
|
|
|
|
|
public OAuthListenerForm(IOAuth2Loopback oauth)
|
|
|
|
|
{
|
|
|
|
|
InitializeComponent();
|
2024-01-17 20:12:48 +13:00
|
|
|
|
ShareXResources.ApplyTheme(this, true);
|
2022-12-08 21:32:58 +13:00
|
|
|
|
|
|
|
|
|
OAuth = oauth;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private async void OAuthListenerForm_Load(object sender, EventArgs e)
|
|
|
|
|
{
|
2022-12-09 00:48:35 +13:00
|
|
|
|
await ConnectAsync(OAuth);
|
2022-12-08 21:32:58 +13:00
|
|
|
|
|
|
|
|
|
Close();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void OAuthListenerForm_FormClosed(object sender, FormClosedEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
listener?.Dispose();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void btnCancel_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
Close();
|
|
|
|
|
}
|
|
|
|
|
|
2022-12-09 00:48:35 +13:00
|
|
|
|
private async Task<bool> ConnectAsync(IOAuth2Loopback oauth)
|
2022-12-08 21:32:58 +13:00
|
|
|
|
{
|
2022-12-09 00:48:35 +13:00
|
|
|
|
OAuth2Info = null;
|
|
|
|
|
UserInfo = null;
|
|
|
|
|
|
2022-12-08 21:32:58 +13:00
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
using (listener = new OAuthListener(oauth))
|
|
|
|
|
{
|
|
|
|
|
bool result = await listener.ConnectAsync();
|
|
|
|
|
|
|
|
|
|
if (result)
|
|
|
|
|
{
|
2022-12-09 00:48:35 +13:00
|
|
|
|
OAuth2Info = listener.OAuth.AuthInfo;
|
|
|
|
|
UserInfo = await Task.Run(() => oauth.GetUserInfo());
|
2022-12-09 01:15:52 +13:00
|
|
|
|
|
2022-12-09 00:48:35 +13:00
|
|
|
|
return true;
|
2022-12-08 21:32:58 +13:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
catch (Exception e)
|
|
|
|
|
{
|
|
|
|
|
DebugHelper.WriteException(e);
|
|
|
|
|
e.ShowError();
|
|
|
|
|
}
|
|
|
|
|
|
2022-12-09 00:48:35 +13:00
|
|
|
|
return false;
|
2022-12-08 21:32:58 +13:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|