mirror of
https://github.com/jellyfin/jellyfin.git
synced 2025-04-24 14:08:44 -04:00
Wait for the async authentication to finish when the JTW token expires
This commit is contained in:
parent
d5fe82314e
commit
c2ab0ad641
1 changed files with 9 additions and 5 deletions
|
@ -24,24 +24,28 @@ namespace MediaBrowser.Providers.TV.TheTVDB
|
||||||
{
|
{
|
||||||
_cache = memoryCache;
|
_cache = memoryCache;
|
||||||
_tvDbClient = new TvDbClient();
|
_tvDbClient = new TvDbClient();
|
||||||
_tvDbClient.Authentication.AuthenticateAsync(TvdbUtils.TvdbApiKey);
|
|
||||||
_tokenCreatedAt = DateTime.Now;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public TvDbClient TvDbClient
|
private TvDbClient TvDbClient
|
||||||
{
|
{
|
||||||
get
|
get
|
||||||
{
|
{
|
||||||
|
if (string.IsNullOrEmpty(_tvDbClient.Authentication.Token))
|
||||||
|
{
|
||||||
|
_tvDbClient.Authentication.AuthenticateAsync(TvdbUtils.TvdbApiKey).GetAwaiter().GetResult();
|
||||||
|
_tokenCreatedAt = DateTime.Now;
|
||||||
|
}
|
||||||
|
|
||||||
// Refresh if necessary
|
// Refresh if necessary
|
||||||
if (_tokenCreatedAt < DateTime.Now.Subtract(TimeSpan.FromHours(20)))
|
if (_tokenCreatedAt < DateTime.Now.Subtract(TimeSpan.FromHours(20)))
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
_tvDbClient.Authentication.RefreshTokenAsync();
|
_tvDbClient.Authentication.RefreshTokenAsync().GetAwaiter().GetResult();
|
||||||
}
|
}
|
||||||
catch
|
catch
|
||||||
{
|
{
|
||||||
_tvDbClient.Authentication.AuthenticateAsync(TvdbUtils.TvdbApiKey);
|
_tvDbClient.Authentication.AuthenticateAsync(TvdbUtils.TvdbApiKey).GetAwaiter().GetResult();
|
||||||
}
|
}
|
||||||
|
|
||||||
_tokenCreatedAt = DateTime.Now;
|
_tokenCreatedAt = DateTime.Now;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue