コード例 #1
0
        public void Token_expiration_should_be_correct()
        {
            // Arrange
            var sut = new PKCETokenResponse();

            sut.CreatedAt = DateTime.UtcNow.AddDays(-14);
            sut.ExpiresIn = 1;

            // Act
            var result = sut.HasExpired();

            // Assert
            result.Should().BeTrue();
        }
コード例 #2
0
ファイル: AuthService.cs プロジェクト: Drawserqzez/SpotifyCLI
        public async Task <ISpotifyClient> CreateSpotifyClientAsync()
        {
            PKCETokenResponse tokenResponse = _config.Tokens;

            if (String.IsNullOrEmpty(tokenResponse.AccessToken) || String.IsNullOrEmpty(tokenResponse.RefreshToken))
            {
                tokenResponse = await UseNewTokens();
            }
            else if (tokenResponse.HasExpired())
            {
                tokenResponse = await RefreshTokens();
            }

            var config = SpotifyClientConfig.CreateDefault().WithAuthenticator(new PKCEAuthenticator(_config.ClientId, tokenResponse));

            return(new SpotifyClient(config));
        }