Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/Nullinside.TwitchStreamingTools/Configuration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

using Newtonsoft.Json;

using Nullinside.Api.Common.Auth;
using Nullinside.Api.Common.Twitch;
using Nullinside.TwitchStreamingTools.Controls.ViewModels;
using Nullinside.TwitchStreamingTools.Models;
Expand Down Expand Up @@ -55,7 +56,7 @@ public static Configuration Instance {
/// <summary>
/// The twitch OAuth token.
/// </summary>
public TwitchAccessToken? OAuth { get; set; }
public OAuthToken? OAuth { get; set; }

/// <summary>
/// The twitch application configuration for getting OAuth tokens.
Expand Down
3 changes: 2 additions & 1 deletion src/Nullinside.TwitchStreamingTools/IConfiguration.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System.Collections.Generic;

using Nullinside.Api.Common.Auth;
using Nullinside.Api.Common.Twitch;
using Nullinside.TwitchStreamingTools.Controls.ViewModels;
using Nullinside.TwitchStreamingTools.Models;
Expand All @@ -18,7 +19,7 @@ public interface IConfiguration {
/// <summary>
/// The twitch OAuth token.
/// </summary>
TwitchAccessToken? OAuth { get; set; }
OAuthToken? OAuth { get; set; }

/// <summary>
/// The twitch application configuration for getting OAuth tokens.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using System.Threading.Tasks;

using Nullinside.Api.Common.Auth;
using Nullinside.Api.Common.Twitch;

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

/// <summary>
/// Updates the credentials.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

using Avalonia.Threading;

using Nullinside.Api.Common.Auth;
using Nullinside.Api.Common.Twitch;
using Nullinside.TwitchStreamingTools.Utilities;

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

/// <inheritdoc />
public Action<TwitchAccessToken?>? OnCredentialsChanged { get; set; }
public Action<OAuthToken?>? OnCredentialsChanged { get; set; }

/// <inheritdoc />
public async Task UpdateCredentials(string bearer, string refresh, DateTime expires) {
var oauth = new TwitchAccessToken {
var oauth = new OAuthToken {
AccessToken = bearer,
RefreshToken = refresh,
ExpiresUtc = expires
Expand Down Expand Up @@ -159,7 +160,7 @@ private async Task DoTokenRefreshIfNearExpiration() {
await twitchApi.RefreshAccessToken().ConfigureAwait(false);

// Update the configuration
_configuration.OAuth = new TwitchAccessToken {
_configuration.OAuth = new OAuthToken {
AccessToken = twitchApi.OAuth.AccessToken,
RefreshToken = twitchApi.OAuth.RefreshToken,
ExpiresUtc = twitchApi.OAuth.ExpiresUtc ?? DateTime.MinValue
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

using Newtonsoft.Json;

using Nullinside.Api.Common.Auth;
using Nullinside.Api.Common.Twitch;

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

return new TwitchAccessToken {
return new OAuthToken {
AccessToken = oauthResp.AccessToken,
ExpiresUtc = oauthResp.ExpiresUtc,
RefreshToken = oauthResp.RefreshToken
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
using Newtonsoft.Json;

using Nullinside.Api.Common;
using Nullinside.Api.Common.Auth;
using Nullinside.Api.Common.Extensions;
using Nullinside.Api.Common.Twitch;
using Nullinside.TwitchStreamingTools.Services;
Expand Down Expand Up @@ -145,7 +146,7 @@ private async Task LoadProfileImage() {
/// Called when the credentials are changed to load the new profile image.
/// </summary>
/// <param name="token"></param>
private async void OnCredentialsChanged(TwitchAccessToken? token) {
private async void OnCredentialsChanged(OAuthToken? token) {
try {
if (string.IsNullOrWhiteSpace(token?.AccessToken)) {
ProfileImage = null;
Expand Down Expand Up @@ -213,7 +214,7 @@ private async Task PerformLogin() {
await webSocket.CloseAsync(WebSocketCloseStatus.NormalClosure, "Completed Successfully!", token).ConfigureAwait(false);

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