Updates to finally secure the Twitch codes so i don't have to keep adding them for compile and removing them for Source Distribution. fixed a Bug in the notification system that ment dismiss did not work.

This commit is contained in:
Martin Barker
2023-01-28 15:17:50 +00:00
parent 77cae0c9c8
commit e9f291f6f7
5 changed files with 31 additions and 20 deletions

1
.gitignore vendored
View File

@@ -6,3 +6,4 @@
/TwitchDesktopNotifications/obj /TwitchDesktopNotifications/obj
/.vs /.vs
/TwitchDesktopNotifications/App.config /TwitchDesktopNotifications/App.config
/TwitchDesktopNotifications/TwitchDetails.cs

View File

@@ -11,10 +11,17 @@ Want to contribute? Great!
Project is built using Visual Studios 2022, Project is built using Visual Studios 2022,
You need to create Application to obtain a ID and Secret on [Twitch Developer Console](https://dev.twitch.tv/console) replace lines 15 and 16 in TwitchFetcher.cs You need to create Application to obtain a ID and Secret on [Twitch Developer Console](https://dev.twitch.tv/console)
```pwsh Add a new C# Class to the project named `TwitchDetails.cs` add the following code with your ID and Secret
TwitchClientID = ""; ```cs
TwitchClientSecret = ""; namespace TwitchDesktopNotifications
{
static public class TwitchDetails
{
public static string TwitchClientID = "";
public static string TwitchClientSecret = "";
}
}
``` ```
### CommunityToolkit 8.0.0 Pre-release ### CommunityToolkit 8.0.0 Pre-release

View File

@@ -22,10 +22,18 @@ namespace TwitchDesktopNotifications.Core
try try
{ {
Process myProcess = new Process(); if (
myProcess.StartInfo.UseShellExecute = true; // action is defined and set to watch
myProcess.StartInfo.FileName = args["streamerUrl"]; ( args.Contains("action") && args["action"] == "watch" )
myProcess.Start(); ||
// action is not defined so the user just generally clicked on the notification
!args.Contains("action")
){
Process myProcess = new Process();
myProcess.StartInfo.UseShellExecute = true;
myProcess.StartInfo.FileName = args["streamerUrl"];
myProcess.Start();
}
}catch(Exception ex) { } }catch(Exception ex) { }
}; };
} }

View File

@@ -12,15 +12,10 @@ namespace TwitchDesktopNotifications.Core
internal class TwitchFetcher internal class TwitchFetcher
{ {
private TwitchFetcher() { private TwitchFetcher() {
TwitchClientID = "";
TwitchClientSecret = "";
} }
public static TwitchFetcher instance { get; private set; } public static TwitchFetcher instance { get; private set; }
string TwitchClientID = "";
string TwitchClientSecret = "";
List <StreamsData> currentlyLive = null; List <StreamsData> currentlyLive = null;
public string guid { get; private set; } public string guid { get; private set; }
@@ -60,7 +55,7 @@ namespace TwitchDesktopNotifications.Core
WebRequest request = WebRequest.Create("https://api.twitch.tv/" + endpoint); WebRequest request = WebRequest.Create("https://api.twitch.tv/" + endpoint);
request.Method = "GET"; request.Method = "GET";
request.Headers[HttpRequestHeader.Authorization] = String.Format("Bearer {0}", DataStore.GetInstance().Store.Authentication.AccessToken); request.Headers[HttpRequestHeader.Authorization] = String.Format("Bearer {0}", DataStore.GetInstance().Store.Authentication.AccessToken);
request.Headers["Client-ID"] = TwitchClientID; request.Headers["Client-ID"] = TwitchDetails.TwitchClientID;
WebResponse response = request.GetResponse(); WebResponse response = request.GetResponse();
Stream dataStream = response.GetResponseStream(); Stream dataStream = response.GetResponseStream();
StreamReader reader = new StreamReader(dataStream); StreamReader reader = new StreamReader(dataStream);
@@ -139,8 +134,8 @@ namespace TwitchDesktopNotifications.Core
{ {
Dictionary<string, string> postData = new Dictionary<string, string>(); Dictionary<string, string> postData = new Dictionary<string, string>();
postData["client_id"] = TwitchClientID; postData["client_id"] = TwitchDetails.TwitchClientID;
postData["client_secret"] = TwitchClientSecret; postData["client_secret"] = TwitchDetails.TwitchClientSecret;
postData["grant_type"] = "refresh_token"; postData["grant_type"] = "refresh_token";
postData["refresh_token"] = DataStore.GetInstance().Store.Authentication.RefreshToken; postData["refresh_token"] = DataStore.GetInstance().Store.Authentication.RefreshToken;
@@ -173,7 +168,7 @@ namespace TwitchDesktopNotifications.Core
WebServer.GetInstance().TwitchState = guid; WebServer.GetInstance().TwitchState = guid;
Process myProcess = new Process(); Process myProcess = new Process();
myProcess.StartInfo.UseShellExecute = true; myProcess.StartInfo.UseShellExecute = true;
myProcess.StartInfo.FileName = String.Format("https://id.twitch.tv/oauth2/authorize?&redirect_uri=http://localhost:32584/twitchRedirect&scope=user:read:subscriptions%20user:read:follows%20user:read:email%20openid&response_type=code&state={0}&nonce={1}&client_id={2}", guid, guid, TwitchClientID); myProcess.StartInfo.FileName = String.Format("https://id.twitch.tv/oauth2/authorize?&redirect_uri=http://localhost:32584/twitchRedirect&scope=user:read:subscriptions%20user:read:follows%20user:read:email%20openid&response_type=code&state={0}&nonce={1}&client_id={2}", guid, guid, TwitchDetails.TwitchClientID);
myProcess.Start(); myProcess.Start();
} }
@@ -181,8 +176,8 @@ namespace TwitchDesktopNotifications.Core
{ {
Dictionary<string, string> postData = new Dictionary<string, string>(); Dictionary<string, string> postData = new Dictionary<string, string>();
postData["client_id"] = TwitchClientID; postData["client_id"] = TwitchDetails.TwitchClientID;
postData["client_secret"] = TwitchClientSecret; postData["client_secret"] = TwitchDetails.TwitchClientSecret;
postData["grant_type"] = "authorization_code"; postData["grant_type"] = "authorization_code";
postData["redirect_uri"] = "http://localhost:32584/twitchRedirect"; postData["redirect_uri"] = "http://localhost:32584/twitchRedirect";
postData["code"] = code; postData["code"] = code;

View File

@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk"> <Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup> <PropertyGroup>
<OutputType>Exe</OutputType> <OutputType>WinExe</OutputType>
<TargetFramework>net6.0-windows10.0.17763.0</TargetFramework> <TargetFramework>net6.0-windows10.0.17763.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings> <ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable> <Nullable>enable</Nullable>