Example #1
0
        /// <summary>
        /// Refreshes an expired access token and updates the database.
        /// </summary>
        /// <param name="state">A user's app state.</param>
        /// <param name="clientId">The client ID.</param>
        /// <param name="oldAccessToken">The expired access token.</param>
        /// <returns>The refreshed access token.</returns>
        public async Task <string> RefreshAccessToken(Guid state, string clientId, string oldAccessToken)
        {
            string refreshToken, clientSecret;

            // First, we have to get the refresh token
            refreshToken = await authenticator.GetRefreshTokenByStateAsync(state);

            // Next, we have to get the client secret
            clientSecret = await authenticator.GetClientSecretByValidStateAsync(state);

            // Okay, now let's make our POST request to Twitch
            var refreshResponse = await twitchApi.Auth.v5.RefreshAuthTokenAsync(refreshToken, clientSecret, clientId);

            await authenticator.UpdateAccessAndRefreshTokens(state, refreshResponse.AccessToken, refreshResponse.RefreshToken);

            return(refreshResponse.AccessToken);
        }