Skip to content

Commit

Permalink
- Adding scope list validation check for user OAuth Tokens
Browse files Browse the repository at this point in the history
  • Loading branch information
SaviorXTanren committed Aug 1, 2023
1 parent 0b9033e commit 1c0a66b
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 18 deletions.
19 changes: 13 additions & 6 deletions MixItUp.Base/Services/Trovo/TrovoSessionService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -108,11 +108,19 @@ public async Task<Result> Connect(SettingsV3Model settings)
{
Result userResult = null;

Result<TrovoPlatformService> trovoResult = await TrovoPlatformService.Connect(settings.StreamingPlatformAuthentications[StreamingPlatformTypeEnum.Trovo].UserOAuthToken);
if (trovoResult.Success)
// If scopes don't match, re-auth the token
if (string.Equals(string.Join(",", TrovoPlatformService.StreamerScopes), settings.StreamingPlatformAuthentications[StreamingPlatformTypeEnum.Trovo].UserOAuthToken.ScopeList, StringComparison.OrdinalIgnoreCase))
{
this.UserConnection = trovoResult.Value;
userResult = trovoResult;
Result<TrovoPlatformService> trovoResult = await TrovoPlatformService.Connect(settings.StreamingPlatformAuthentications[StreamingPlatformTypeEnum.Trovo].UserOAuthToken);
if (trovoResult.Success)
{
this.UserConnection = trovoResult.Value;
userResult = trovoResult;
}
else
{
userResult = await this.ConnectUser();
}
}
else
{
Expand All @@ -129,7 +137,7 @@ public async Task<Result> Connect(SettingsV3Model settings)

if (settings.StreamingPlatformAuthentications[StreamingPlatformTypeEnum.Trovo].BotOAuthToken != null)
{
trovoResult = await TrovoPlatformService.Connect(settings.StreamingPlatformAuthentications[StreamingPlatformTypeEnum.Trovo].BotOAuthToken);
Result<TrovoPlatformService> trovoResult = await TrovoPlatformService.Connect(settings.StreamingPlatformAuthentications[StreamingPlatformTypeEnum.Trovo].BotOAuthToken);
if (trovoResult.Success)
{
this.BotConnection = trovoResult.Value;
Expand All @@ -141,7 +149,6 @@ public async Task<Result> Connect(SettingsV3Model settings)
}
else
{

return new Result(success: true, message: MixItUp.Base.Resources.TrovoFailedToConnectBotAccount);
}
}
Expand Down
19 changes: 13 additions & 6 deletions MixItUp.Base/Services/Twitch/TwitchSessionService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -108,11 +108,19 @@ public async Task<Result> Connect(SettingsV3Model settings)
{
Result userResult = null;

Result<TwitchPlatformService> twitchResult = await TwitchPlatformService.Connect(settings.StreamingPlatformAuthentications[StreamingPlatformTypeEnum.Twitch].UserOAuthToken);
if (twitchResult.Success)
// If scopes don't match, re-auth the token
if (string.Equals(string.Join(",", TwitchPlatformService.StreamerScopes), settings.StreamingPlatformAuthentications[StreamingPlatformTypeEnum.Twitch].UserOAuthToken.ScopeList, StringComparison.OrdinalIgnoreCase))
{
this.UserConnection = twitchResult.Value;
userResult = twitchResult;
Result<TwitchPlatformService> twitchResult = await TwitchPlatformService.Connect(settings.StreamingPlatformAuthentications[StreamingPlatformTypeEnum.Twitch].UserOAuthToken);
if (twitchResult.Success)
{
this.UserConnection = twitchResult.Value;
userResult = twitchResult;
}
else
{
userResult = await this.ConnectUser();
}
}
else
{
Expand All @@ -129,7 +137,7 @@ public async Task<Result> Connect(SettingsV3Model settings)

if (settings.StreamingPlatformAuthentications[StreamingPlatformTypeEnum.Twitch].BotOAuthToken != null)
{
twitchResult = await TwitchPlatformService.Connect(settings.StreamingPlatformAuthentications[StreamingPlatformTypeEnum.Twitch].BotOAuthToken);
Result<TwitchPlatformService> twitchResult = await TwitchPlatformService.Connect(settings.StreamingPlatformAuthentications[StreamingPlatformTypeEnum.Twitch].BotOAuthToken);
if (twitchResult.Success)
{
this.BotConnection = twitchResult.Value;
Expand All @@ -141,7 +149,6 @@ public async Task<Result> Connect(SettingsV3Model settings)
}
else
{

return new Result(success: true, message: MixItUp.Base.Resources.TwitchFailedToConnectBotAccount);
}
}
Expand Down
19 changes: 13 additions & 6 deletions MixItUp.Base/Services/YouTube/YouTubeSessionService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -91,11 +91,19 @@ public async Task<Result> Connect(SettingsV3Model settings)
{
Result userResult = null;

Result<YouTubePlatformService> youtubeResult = await YouTubePlatformService.Connect(settings.StreamingPlatformAuthentications[StreamingPlatformTypeEnum.YouTube].UserOAuthToken);
if (youtubeResult.Success)
// If scopes don't match, re-auth the token
if (string.Equals(string.Join(",", YouTubePlatformService.StreamerScopes), settings.StreamingPlatformAuthentications[StreamingPlatformTypeEnum.YouTube].UserOAuthToken.ScopeList, StringComparison.OrdinalIgnoreCase))
{
this.UserConnection = youtubeResult.Value;
userResult = youtubeResult;
Result<YouTubePlatformService> youtubeResult = await YouTubePlatformService.Connect(settings.StreamingPlatformAuthentications[StreamingPlatformTypeEnum.YouTube].UserOAuthToken);
if (youtubeResult.Success)
{
this.UserConnection = youtubeResult.Value;
userResult = youtubeResult;
}
else
{
userResult = await this.ConnectUser();
}
}
else
{
Expand All @@ -112,7 +120,7 @@ public async Task<Result> Connect(SettingsV3Model settings)

if (settings.StreamingPlatformAuthentications[StreamingPlatformTypeEnum.YouTube].BotOAuthToken != null)
{
youtubeResult = await YouTubePlatformService.Connect(settings.StreamingPlatformAuthentications[StreamingPlatformTypeEnum.YouTube].BotOAuthToken);
Result<YouTubePlatformService> youtubeResult = await YouTubePlatformService.Connect(settings.StreamingPlatformAuthentications[StreamingPlatformTypeEnum.YouTube].BotOAuthToken);
if (youtubeResult.Success)
{
this.BotConnection = youtubeResult.Value;
Expand All @@ -124,7 +132,6 @@ public async Task<Result> Connect(SettingsV3Model settings)
}
else
{

return new Result(success: true, message: MixItUp.Base.Resources.YouTubeFailedToConnectBotAccount);
}
}
Expand Down

0 comments on commit 1c0a66b

Please sign in to comment.