Exemplo n.º 1
0
        public async Task <string> GetPlexApiTokenAsync(PlexAccount plexAccount)
        {
            if (plexAccount == null)
            {
                Log.Warning("The plexAccount was null");
                return(string.Empty);
            }

            if (plexAccount.AuthenticationToken != string.Empty)
            {
                // TODO Make the token refresh limit configurable
                if ((plexAccount.ValidatedAt - DateTime.Now).TotalDays < 30)
                {
                    Log.Information("Plex AuthToken was still valid, using from local DB.");
                    return(plexAccount.AuthenticationToken);
                }

                Log.Information("Plex AuthToken has expired, refreshing Plex AuthToken now.");

                return(await _plexApiService.RefreshPlexAuthTokenAsync(plexAccount));
            }

            Log.Error($"PlexAccount with Id: {plexAccount.Id} contained an empty AuthToken!");
            return(string.Empty);
        }