@@ -58,12 +58,14 @@ public TwitchAccountService(ITwitchClientProxy twitchClient, IConfiguration conf
58
58
59
59
/// <inheritdoc />
60
60
public async Task UpdateCredentials ( string bearer , string refresh , DateTime expires ) {
61
+ var oauth = new TwitchAccessToken {
62
+ AccessToken = bearer ,
63
+ RefreshToken = refresh ,
64
+ ExpiresUtc = expires
65
+ } ;
66
+
61
67
var twitchApi = new TwitchApiWrapper {
62
- OAuth = new TwitchAccessToken {
63
- AccessToken = bearer ,
64
- RefreshToken = refresh ,
65
- ExpiresUtc = expires
66
- }
68
+ OAuth = oauth
67
69
} ;
68
70
69
71
( string ? id , string ? username ) ? user = null ;
@@ -74,18 +76,14 @@ public async Task UpdateCredentials(string bearer, string refresh, DateTime expi
74
76
// Do nothing
75
77
}
76
78
77
- _configuration . OAuth = new TwitchAccessToken {
78
- AccessToken = bearer ,
79
- RefreshToken = refresh ,
80
- ExpiresUtc = expires
81
- } ;
79
+ _configuration . OAuth = oauth ;
82
80
83
81
_configuration . TwitchUsername = user ? . username ;
84
82
_configuration . WriteConfiguration ( ) ;
85
83
_twitchClient . TwitchOAuthToken = bearer ;
86
84
_twitchClient . TwitchUsername = user ? . username ;
87
85
88
- OnCredentialsChanged ? . Invoke ( null ) ;
86
+ OnCredentialsChanged ? . Invoke ( oauth ) ;
89
87
await OnCheckCredentials ( ) ;
90
88
}
91
89
@@ -108,10 +106,10 @@ public void DeleteCredentials() {
108
106
/// </summary>
109
107
private async Task OnCheckCredentials ( ) {
110
108
_timer . Stop ( ) ;
109
+ // Grab the value so we can check if the value changed
110
+ bool credsWereValid = CredentialsAreValid ;
111
+
111
112
try {
112
- // Grab the value so we can check if the value changed
113
- bool previousValue = CredentialsAreValid ;
114
-
115
113
// Refresh the token
116
114
await DoTokenRefreshIfNearExpiration ( ) ;
117
115
@@ -122,16 +120,18 @@ private async Task OnCheckCredentials() {
122
120
// Update the credentials
123
121
CredentialsAreValid = ! string . IsNullOrWhiteSpace ( username ) ;
124
122
TwitchUsername = username ;
125
-
126
- // Fire off the event if something changed
127
- if ( previousValue != CredentialsAreValid ) {
128
- OnCredentialsStatusChanged ? . Invoke ( CredentialsAreValid ) ;
129
- }
130
123
}
131
124
catch {
132
- // Do nothing
125
+ if ( credsWereValid ) {
126
+ DeleteCredentials ( ) ;
127
+ }
133
128
}
134
129
finally {
130
+ // Fire off the event if something changed
131
+ if ( credsWereValid != CredentialsAreValid ) {
132
+ OnCredentialsStatusChanged ? . Invoke ( CredentialsAreValid ) ;
133
+ }
134
+
135
135
_timer . Start ( ) ;
136
136
}
137
137
}
0 commit comments