Skip to content

Commit cdc7b1c

Browse files
Merge pull request #135 from nullinside-development-group/chore/update
chore: update
2 parents 5a63729 + e7583ae commit cdc7b1c

File tree

7 files changed

+18
-12
lines changed

7 files changed

+18
-12
lines changed

src/Nullinside.TwitchStreamingTools/Configuration.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
using Newtonsoft.Json;
99

10+
using Nullinside.Api.Common.Auth;
1011
using Nullinside.Api.Common.Twitch;
1112
using Nullinside.TwitchStreamingTools.Controls.ViewModels;
1213
using Nullinside.TwitchStreamingTools.Models;
@@ -55,7 +56,7 @@ public static Configuration Instance {
5556
/// <summary>
5657
/// The twitch OAuth token.
5758
/// </summary>
58-
public TwitchAccessToken? OAuth { get; set; }
59+
public OAuthToken? OAuth { get; set; }
5960

6061
/// <summary>
6162
/// The twitch application configuration for getting OAuth tokens.

src/Nullinside.TwitchStreamingTools/IConfiguration.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using System.Collections.Generic;
22

3+
using Nullinside.Api.Common.Auth;
34
using Nullinside.Api.Common.Twitch;
45
using Nullinside.TwitchStreamingTools.Controls.ViewModels;
56
using Nullinside.TwitchStreamingTools.Models;
@@ -18,7 +19,7 @@ public interface IConfiguration {
1819
/// <summary>
1920
/// The twitch OAuth token.
2021
/// </summary>
21-
TwitchAccessToken? OAuth { get; set; }
22+
OAuthToken? OAuth { get; set; }
2223

2324
/// <summary>
2425
/// The twitch application configuration for getting OAuth tokens.

src/Nullinside.TwitchStreamingTools/Services/ITwitchAccountService.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using System;
22
using System.Threading.Tasks;
33

4+
using Nullinside.Api.Common.Auth;
45
using Nullinside.Api.Common.Twitch;
56

67
namespace Nullinside.TwitchStreamingTools.Services;
@@ -27,7 +28,7 @@ public interface ITwitchAccountService {
2728
/// <summary>
2829
/// An event indicating that the credentials have changed.
2930
/// </summary>
30-
Action<TwitchAccessToken?>? OnCredentialsChanged { get; set; }
31+
Action<OAuthToken?>? OnCredentialsChanged { get; set; }
3132

3233
/// <summary>
3334
/// Updates the credentials.

src/Nullinside.TwitchStreamingTools/Services/TwitchAccountService.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
using Avalonia.Threading;
55

6+
using Nullinside.Api.Common.Auth;
67
using Nullinside.Api.Common.Twitch;
78
using Nullinside.TwitchStreamingTools.Utilities;
89

@@ -55,11 +56,11 @@ public TwitchAccountService(ITwitchClientProxy twitchClient, IConfiguration conf
5556
public Action<bool>? OnCredentialsStatusChanged { get; set; }
5657

5758
/// <inheritdoc />
58-
public Action<TwitchAccessToken?>? OnCredentialsChanged { get; set; }
59+
public Action<OAuthToken?>? OnCredentialsChanged { get; set; }
5960

6061
/// <inheritdoc />
6162
public async Task UpdateCredentials(string bearer, string refresh, DateTime expires) {
62-
var oauth = new TwitchAccessToken {
63+
var oauth = new OAuthToken {
6364
AccessToken = bearer,
6465
RefreshToken = refresh,
6566
ExpiresUtc = expires
@@ -159,7 +160,7 @@ private async Task DoTokenRefreshIfNearExpiration() {
159160
await twitchApi.RefreshAccessToken().ConfigureAwait(false);
160161

161162
// Update the configuration
162-
_configuration.OAuth = new TwitchAccessToken {
163+
_configuration.OAuth = new OAuthToken {
163164
AccessToken = twitchApi.OAuth.AccessToken,
164165
RefreshToken = twitchApi.OAuth.RefreshToken,
165166
ExpiresUtc = twitchApi.OAuth.ExpiresUtc ?? DateTime.MinValue

src/Nullinside.TwitchStreamingTools/Utilities/TwitchApiWrapper.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
using Newtonsoft.Json;
1010

11+
using Nullinside.Api.Common.Auth;
1112
using Nullinside.Api.Common.Twitch;
1213

1314
namespace Nullinside.TwitchStreamingTools.Utilities;
@@ -38,7 +39,7 @@ public TwitchApiWrapper() : base(
3839
/// </summary>
3940
/// <param name="token">The refresh token.</param>
4041
/// <returns>The new OAuth token information if successful, null otherwise.</returns>
41-
public override async Task<TwitchAccessToken?> RefreshAccessToken(CancellationToken token = new()) {
42+
public override async Task<OAuthToken?> RefreshAccessToken(CancellationToken token = new()) {
4243
try {
4344
// If the secret is specified, then this isn't using our API to authenticate, it's using the twitch api directly.
4445
if (!string.IsNullOrWhiteSpace(TwitchAppConfig?.ClientSecret)) {
@@ -53,12 +54,12 @@ public TwitchApiWrapper() : base(
5354
using HttpResponseMessage response = await client.PostAsync(request.RequestUri, content, token).ConfigureAwait(false);
5455
response.EnsureSuccessStatusCode();
5556
string responseBody = await response.Content.ReadAsStringAsync(token).ConfigureAwait(false);
56-
var oauthResp = JsonConvert.DeserializeObject<TwitchAccessToken>(responseBody);
57+
var oauthResp = JsonConvert.DeserializeObject<OAuthToken>(responseBody);
5758
if (null == oauthResp) {
5859
return null;
5960
}
6061

61-
return new TwitchAccessToken {
62+
return new OAuthToken {
6263
AccessToken = oauthResp.AccessToken,
6364
ExpiresUtc = oauthResp.ExpiresUtc,
6465
RefreshToken = oauthResp.RefreshToken

src/Nullinside.TwitchStreamingTools/ViewModels/Pages/AccountViewModel.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
using Newtonsoft.Json;
1717

1818
using Nullinside.Api.Common;
19+
using Nullinside.Api.Common.Auth;
1920
using Nullinside.Api.Common.Extensions;
2021
using Nullinside.Api.Common.Twitch;
2122
using Nullinside.TwitchStreamingTools.Services;
@@ -145,7 +146,7 @@ private async Task LoadProfileImage() {
145146
/// Called when the credentials are changed to load the new profile image.
146147
/// </summary>
147148
/// <param name="token"></param>
148-
private async void OnCredentialsChanged(TwitchAccessToken? token) {
149+
private async void OnCredentialsChanged(OAuthToken? token) {
149150
try {
150151
if (string.IsNullOrWhiteSpace(token?.AccessToken)) {
151152
ProfileImage = null;
@@ -213,7 +214,7 @@ private async Task PerformLogin() {
213214
await webSocket.CloseAsync(WebSocketCloseStatus.NormalClosure, "Completed Successfully!", token).ConfigureAwait(false);
214215

215216
// Update the oauth token in the twitch account service.
216-
var oauthResp = JsonConvert.DeserializeObject<TwitchAccessToken>(json);
217+
var oauthResp = JsonConvert.DeserializeObject<OAuthToken>(json);
217218
if (null == oauthResp || null == oauthResp.AccessToken || null == oauthResp.RefreshToken || null == oauthResp.ExpiresUtc) {
218219
_logger.Error($"Failed to get a valid oauth token, got: {json}");
219220
return;

0 commit comments

Comments
 (0)