Also update authenticator if new refresh token was returned

This commit is contained in:
Jonas Dellinger 2021-09-28 22:30:52 +02:00
parent eb97a0af97
commit a340eaf43c
2 changed files with 9 additions and 2 deletions

View File

@ -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

View File

@ -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);
}