Example #1
0
        public async Task Authenticate()
        {
            async Task RequestNewSession()
            {
                Terminal.WriteLine("Please authorise this application to use Spotify on your behalf");
                SpotifyUrlHelper.RunUrl(GetAuthorisationUrl(_codeVerifier));
                if (!await GetAuthToken())
                {
                    throw new NotAuthenticatedException();
                }
            }

            if (_appSettings.SpotifyTokens?.ExpiresAt != null)
            {
                if (_appSettings.SpotifyTokens?.ExpiresAt < DateTime.Now)
                {
                    if (!await RequestRefreshedAccessToken())
                    {
                        await RequestNewSession();
                    }
                }
                else if (await AreCachedCredentialsStillValid())
                {
                    IsAuthenticated = true;
                }
            }
            else
            {
                RequestNewSession();
            }
        }
Example #2
0
        public async Task Authenticate()
        {
            await GetAuthToken();

            Terminal.WriteLine("Please authorise this application to use Spotify on your behalf");
            SpotifyUrlHelper.RunUrl(GetAuthorisationUrl(_codeVerifier));
            Terminal.ReadLine();
        }