From a340eaf43c755833cdc54a474a8765e667fbcd4f Mon Sep 17 00:00:00 2001 From: Jonas Dellinger Date: Tue, 28 Sep 2021 22:30:52 +0200 Subject: [PATCH] Also update authenticator if new refresh token was returned --- .editorconfig | 3 +++ .../Authenticators/AuthorizationCodeAuthenticator.cs | 8 ++++++-- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/.editorconfig b/.editorconfig index b7f043d6..f4a3530f 100644 --- a/.editorconfig +++ b/.editorconfig @@ -17,6 +17,9 @@ dotnet_diagnostic.CA1308.severity = none dotnet_diagnostic.CA1002.severity = none # TODO: Enable for next major version, EventArgs breaking change: dotnet_diagnostic.CA1003.severity = none + +dotnet_diagnostic.IDE0130.severity = none + # # Sort using and Import directives with System.* appearing first dotnet_sort_system_directives_first = true diff --git a/SpotifyAPI.Web/Authenticators/AuthorizationCodeAuthenticator.cs b/SpotifyAPI.Web/Authenticators/AuthorizationCodeAuthenticator.cs index c116900a..77111843 100644 --- a/SpotifyAPI.Web/Authenticators/AuthorizationCodeAuthenticator.cs +++ b/SpotifyAPI.Web/Authenticators/AuthorizationCodeAuthenticator.cs @@ -53,14 +53,18 @@ namespace SpotifyAPI.Web if (InitialToken.IsExpired) { - var tokenRequest = new AuthorizationCodeRefreshRequest(ClientId, ClientSecret, InitialToken.RefreshToken); - var refreshedToken = await OAuthClient.RequestToken(tokenRequest, apiConnector).ConfigureAwait(false); + AuthorizationCodeRefreshRequest? tokenRequest = new(ClientId, ClientSecret, InitialToken.RefreshToken); + AuthorizationCodeRefreshResponse? refreshedToken = await OAuthClient.RequestToken(tokenRequest, apiConnector).ConfigureAwait(false); InitialToken.AccessToken = refreshedToken.AccessToken; InitialToken.CreatedAt = refreshedToken.CreatedAt; InitialToken.ExpiresIn = refreshedToken.ExpiresIn; InitialToken.Scope = refreshedToken.Scope; InitialToken.TokenType = refreshedToken.TokenType; + if (refreshedToken.RefreshToken != null) + { + InitialToken.RefreshToken = refreshedToken.RefreshToken; + } TokenRefreshed?.Invoke(this, InitialToken); }