mirror of
https://github.com/Radarr/Radarr.git
synced 2024-09-11 20:12:41 +02:00
Fixed: Migration 170 setting incorrect trakt auth values
This commit is contained in:
parent
7f1761bec5
commit
d41eed2e79
@ -57,27 +57,6 @@ private void RenameRadarrListType(IDbConnection conn, IDbTransaction tran)
|
|||||||
|
|
||||||
private void FixTraktConfig(IDbConnection conn, IDbTransaction tran)
|
private void FixTraktConfig(IDbConnection conn, IDbTransaction tran)
|
||||||
{
|
{
|
||||||
var config = new Dictionary<string, string>();
|
|
||||||
|
|
||||||
using (IDbCommand configCmd = conn.CreateCommand())
|
|
||||||
{
|
|
||||||
configCmd.Transaction = tran;
|
|
||||||
configCmd.CommandText = @"SELECT * FROM Config";
|
|
||||||
using (IDataReader configReader = configCmd.ExecuteReader())
|
|
||||||
{
|
|
||||||
var keyIndex = configReader.GetOrdinal("Key");
|
|
||||||
var valueIndex = configReader.GetOrdinal("Value");
|
|
||||||
|
|
||||||
while (configReader.Read())
|
|
||||||
{
|
|
||||||
var key = configReader.GetString(keyIndex);
|
|
||||||
var value = configReader.GetString(valueIndex);
|
|
||||||
|
|
||||||
config.Add(key.ToLowerInvariant(), value);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
var rows = conn.Query<ProviderDefinition169>($"SELECT Id, Implementation, ConfigContract, Settings FROM NetImport WHERE Implementation = 'TraktImport'");
|
var rows = conn.Query<ProviderDefinition169>($"SELECT Id, Implementation, ConfigContract, Settings FROM NetImport WHERE Implementation = 'TraktImport'");
|
||||||
|
|
||||||
var corrected = new List<ProviderDefinition169>();
|
var corrected = new List<ProviderDefinition169>();
|
||||||
@ -94,12 +73,9 @@ private void FixTraktConfig(IDbConnection conn, IDbTransaction tran)
|
|||||||
Username = settings.Username,
|
Username = settings.Username,
|
||||||
AuthUser = settings.Username,
|
AuthUser = settings.Username,
|
||||||
|
|
||||||
OAuthUrl = "http://radarr.aeonlucid.com/v1/trakt/redirect",
|
|
||||||
RenewUri = "http://radarr.aeonlucid.com/v1/trakt/refresh",
|
|
||||||
ClientId = "964f67b126ade0112c4ae1f0aea3a8fb03190f71117bd83af6a0560a99bc52e6",
|
|
||||||
Scope = settings.Scope,
|
Scope = settings.Scope,
|
||||||
AccessToken = settings.AccessToken.IsNotNullOrWhiteSpace() ? settings.AccessToken : GetConfigValue(config, "TraktAuthToken", "localhost") ?? "",
|
AccessToken = settings.AccessToken.IsNotNullOrWhiteSpace() ? settings.AccessToken : "",
|
||||||
RefreshToken = settings.RefreshToken.IsNotNullOrWhiteSpace() ? settings.RefreshToken : GetConfigValue(config, "TraktRefreshToken", "localhost") ?? "",
|
RefreshToken = settings.RefreshToken.IsNotNullOrWhiteSpace() ? settings.RefreshToken : "",
|
||||||
Expires = settings.Expires > DateTime.UtcNow ? settings.Expires : DateTime.UtcNow,
|
Expires = settings.Expires > DateTime.UtcNow ? settings.Expires : DateTime.UtcNow,
|
||||||
Link = settings.Link,
|
Link = settings.Link,
|
||||||
Rating = settings.Rating,
|
Rating = settings.Rating,
|
||||||
@ -126,12 +102,9 @@ private void FixTraktConfig(IDbConnection conn, IDbTransaction tran)
|
|||||||
TraktListType = settings.TraktListType,
|
TraktListType = settings.TraktListType,
|
||||||
AuthUser = settings.Username,
|
AuthUser = settings.Username,
|
||||||
|
|
||||||
OAuthUrl = "http://radarr.aeonlucid.com/v1/trakt/redirect",
|
|
||||||
RenewUri = "http://radarr.aeonlucid.com/v1/trakt/refresh",
|
|
||||||
ClientId = "964f67b126ade0112c4ae1f0aea3a8fb03190f71117bd83af6a0560a99bc52e6",
|
|
||||||
Scope = settings.Scope,
|
Scope = settings.Scope,
|
||||||
AccessToken = settings.AccessToken.IsNotNullOrWhiteSpace() ? settings.AccessToken : GetConfigValue(config, "TraktAuthToken", "localhost") ?? "",
|
AccessToken = settings.AccessToken.IsNotNullOrWhiteSpace() ? settings.AccessToken : "",
|
||||||
RefreshToken = settings.RefreshToken.IsNotNullOrWhiteSpace() ? settings.RefreshToken : GetConfigValue(config, "TraktRefreshToken", "localhost") ?? "",
|
RefreshToken = settings.RefreshToken.IsNotNullOrWhiteSpace() ? settings.RefreshToken : "",
|
||||||
Expires = settings.Expires > DateTime.UtcNow ? settings.Expires : DateTime.UtcNow,
|
Expires = settings.Expires > DateTime.UtcNow ? settings.Expires : DateTime.UtcNow,
|
||||||
Link = settings.Link,
|
Link = settings.Link,
|
||||||
Rating = settings.Rating,
|
Rating = settings.Rating,
|
||||||
@ -158,12 +131,9 @@ private void FixTraktConfig(IDbConnection conn, IDbTransaction tran)
|
|||||||
TraktListType = (int)Enum.Parse(typeof(TraktPopularListType170), Enum.GetName(typeof(TraktListType169), settings.TraktListType)),
|
TraktListType = (int)Enum.Parse(typeof(TraktPopularListType170), Enum.GetName(typeof(TraktListType169), settings.TraktListType)),
|
||||||
AuthUser = settings.Username,
|
AuthUser = settings.Username,
|
||||||
|
|
||||||
OAuthUrl = "http://radarr.aeonlucid.com/v1/trakt/redirect",
|
|
||||||
RenewUri = "http://radarr.aeonlucid.com/v1/trakt/refresh",
|
|
||||||
ClientId = "964f67b126ade0112c4ae1f0aea3a8fb03190f71117bd83af6a0560a99bc52e6",
|
|
||||||
Scope = settings.Scope,
|
Scope = settings.Scope,
|
||||||
AccessToken = settings.AccessToken.IsNotNullOrWhiteSpace() ? settings.AccessToken : GetConfigValue(config, "TraktAuthToken", "localhost") ?? "",
|
AccessToken = settings.AccessToken.IsNotNullOrWhiteSpace() ? settings.AccessToken : "",
|
||||||
RefreshToken = settings.RefreshToken.IsNotNullOrWhiteSpace() ? settings.RefreshToken : GetConfigValue(config, "TraktRefreshToken", "localhost") ?? "",
|
RefreshToken = settings.RefreshToken.IsNotNullOrWhiteSpace() ? settings.RefreshToken : "",
|
||||||
Expires = settings.Expires > DateTime.UtcNow ? settings.Expires : DateTime.UtcNow,
|
Expires = settings.Expires > DateTime.UtcNow ? settings.Expires : DateTime.UtcNow,
|
||||||
Link = settings.Link,
|
Link = settings.Link,
|
||||||
Rating = settings.Rating,
|
Rating = settings.Rating,
|
||||||
@ -190,18 +160,6 @@ private void FixTraktConfig(IDbConnection conn, IDbTransaction tran)
|
|||||||
var updateSql = "UPDATE NetImport SET Implementation = @Implementation, ConfigContract = @ConfigContract, Settings = @Settings WHERE Id = @Id";
|
var updateSql = "UPDATE NetImport SET Implementation = @Implementation, ConfigContract = @ConfigContract, Settings = @Settings WHERE Id = @Id";
|
||||||
conn.Execute(updateSql, corrected, transaction: tran);
|
conn.Execute(updateSql, corrected, transaction: tran);
|
||||||
}
|
}
|
||||||
|
|
||||||
private T GetConfigValue<T>(Dictionary<string, string> config, string key, T defaultValue)
|
|
||||||
{
|
|
||||||
key = key.ToLowerInvariant();
|
|
||||||
|
|
||||||
if (config.ContainsKey(key))
|
|
||||||
{
|
|
||||||
return (T)Convert.ChangeType(config[key], typeof(T));
|
|
||||||
}
|
|
||||||
|
|
||||||
return defaultValue;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public class ProviderDefinition169 : ModelBase
|
public class ProviderDefinition169 : ModelBase
|
||||||
@ -213,9 +171,6 @@ public class ProviderDefinition169 : ModelBase
|
|||||||
|
|
||||||
public class TraktBaseSettings170
|
public class TraktBaseSettings170
|
||||||
{
|
{
|
||||||
public string OAuthUrl { get; set; }
|
|
||||||
public string RenewUri { get; set; }
|
|
||||||
public string ClientId { get; set; }
|
|
||||||
public string Scope { get; set; }
|
public string Scope { get; set; }
|
||||||
public string AuthUser { get; set; }
|
public string AuthUser { get; set; }
|
||||||
public string AccessToken { get; set; }
|
public string AccessToken { get; set; }
|
||||||
|
@ -25,7 +25,8 @@ public override INetImportRequestGenerator GetRequestGenerator()
|
|||||||
{
|
{
|
||||||
return new TraktListRequestGenerator()
|
return new TraktListRequestGenerator()
|
||||||
{
|
{
|
||||||
Settings = Settings
|
Settings = Settings,
|
||||||
|
ClientId = ClientId
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -7,6 +7,7 @@ namespace NzbDrone.Core.NetImport.Trakt.List
|
|||||||
public class TraktListRequestGenerator : INetImportRequestGenerator
|
public class TraktListRequestGenerator : INetImportRequestGenerator
|
||||||
{
|
{
|
||||||
public TraktListSettings Settings { get; set; }
|
public TraktListSettings Settings { get; set; }
|
||||||
|
public string ClientId { get; set; }
|
||||||
|
|
||||||
public TraktListRequestGenerator()
|
public TraktListRequestGenerator()
|
||||||
{
|
{
|
||||||
@ -31,7 +32,7 @@ private IEnumerable<NetImportRequest> GetMoviesRequest()
|
|||||||
var request = new NetImportRequest($"{link}", HttpAccept.Json);
|
var request = new NetImportRequest($"{link}", HttpAccept.Json);
|
||||||
|
|
||||||
request.HttpRequest.Headers.Add("trakt-api-version", "2");
|
request.HttpRequest.Headers.Add("trakt-api-version", "2");
|
||||||
request.HttpRequest.Headers.Add("trakt-api-key", Settings.ClientId); //aeon
|
request.HttpRequest.Headers.Add("trakt-api-key", ClientId); //aeon
|
||||||
|
|
||||||
if (Settings.AccessToken.IsNotNullOrWhiteSpace())
|
if (Settings.AccessToken.IsNotNullOrWhiteSpace())
|
||||||
{
|
{
|
||||||
|
@ -30,7 +30,8 @@ public override INetImportRequestGenerator GetRequestGenerator()
|
|||||||
{
|
{
|
||||||
return new TraktPopularRequestGenerator()
|
return new TraktPopularRequestGenerator()
|
||||||
{
|
{
|
||||||
Settings = Settings
|
Settings = Settings,
|
||||||
|
ClientId = ClientId
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -8,6 +8,8 @@ public class TraktPopularRequestGenerator : INetImportRequestGenerator
|
|||||||
{
|
{
|
||||||
public TraktPopularSettings Settings { get; set; }
|
public TraktPopularSettings Settings { get; set; }
|
||||||
|
|
||||||
|
public string ClientId { get; set; }
|
||||||
|
|
||||||
public TraktPopularRequestGenerator()
|
public TraktPopularRequestGenerator()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
@ -58,7 +60,7 @@ private IEnumerable<NetImportRequest> GetMoviesRequest()
|
|||||||
var request = new NetImportRequest($"{link}", HttpAccept.Json);
|
var request = new NetImportRequest($"{link}", HttpAccept.Json);
|
||||||
|
|
||||||
request.HttpRequest.Headers.Add("trakt-api-version", "2");
|
request.HttpRequest.Headers.Add("trakt-api-version", "2");
|
||||||
request.HttpRequest.Headers.Add("trakt-api-key", Settings.ClientId); //aeon
|
request.HttpRequest.Headers.Add("trakt-api-key", ClientId); //aeon
|
||||||
|
|
||||||
if (Settings.AccessToken.IsNotNullOrWhiteSpace())
|
if (Settings.AccessToken.IsNotNullOrWhiteSpace())
|
||||||
{
|
{
|
||||||
|
@ -14,6 +14,11 @@ public abstract class TraktImportBase<TSettings> : HttpNetImportBase<TSettings>
|
|||||||
{
|
{
|
||||||
public override NetImportType ListType => NetImportType.Trakt;
|
public override NetImportType ListType => NetImportType.Trakt;
|
||||||
|
|
||||||
|
public const string OAuthUrl = "https://api.trakt.tv/oauth/authorize";
|
||||||
|
public const string RedirectUri = "https://auth.servarr.com/v1/trakt/auth";
|
||||||
|
public const string RenewUri = "https://auth.servarr.com/v1/trakt/renew";
|
||||||
|
public const string ClientId = "64508a8bf370cee550dde4806469922fd7cd70afb2d5690e3ee7f75ae784b70e";
|
||||||
|
|
||||||
private INetImportRepository _netImportRepository;
|
private INetImportRepository _netImportRepository;
|
||||||
|
|
||||||
protected TraktImportBase(INetImportRepository netImportRepository,
|
protected TraktImportBase(INetImportRepository netImportRepository,
|
||||||
@ -50,10 +55,10 @@ public override object RequestAction(string action, IDictionary<string, string>
|
|||||||
{
|
{
|
||||||
if (action == "startOAuth")
|
if (action == "startOAuth")
|
||||||
{
|
{
|
||||||
var request = new HttpRequestBuilder(Settings.OAuthUrl)
|
var request = new HttpRequestBuilder(OAuthUrl)
|
||||||
.AddQueryParam("client_id", Settings.ClientId)
|
.AddQueryParam("client_id", ClientId)
|
||||||
.AddQueryParam("response_type", "code")
|
.AddQueryParam("response_type", "code")
|
||||||
.AddQueryParam("redirect_uri", Settings.RedirectUri)
|
.AddQueryParam("redirect_uri", RedirectUri)
|
||||||
.AddQueryParam("state", query["callbackUrl"])
|
.AddQueryParam("state", query["callbackUrl"])
|
||||||
.Build();
|
.Build();
|
||||||
|
|
||||||
@ -82,7 +87,7 @@ private string GetUserName(string accessToken)
|
|||||||
.Build();
|
.Build();
|
||||||
|
|
||||||
request.Headers.Add("trakt-api-version", "2");
|
request.Headers.Add("trakt-api-version", "2");
|
||||||
request.Headers.Add("trakt-api-key", Settings.ClientId); //aeon
|
request.Headers.Add("trakt-api-key", ClientId);
|
||||||
|
|
||||||
if (accessToken.IsNotNullOrWhiteSpace())
|
if (accessToken.IsNotNullOrWhiteSpace())
|
||||||
{
|
{
|
||||||
@ -112,7 +117,7 @@ private void RefreshToken()
|
|||||||
|
|
||||||
Settings.Validate().Filter("RefreshToken").ThrowOnError();
|
Settings.Validate().Filter("RefreshToken").ThrowOnError();
|
||||||
|
|
||||||
var request = new HttpRequestBuilder(Settings.RenewUri)
|
var request = new HttpRequestBuilder(RenewUri)
|
||||||
.AddQueryParam("refresh_token", Settings.RefreshToken)
|
.AddQueryParam("refresh_token", Settings.RefreshToken)
|
||||||
.Build();
|
.Build();
|
||||||
|
|
||||||
|
@ -59,10 +59,6 @@ public TraktSettingsBase()
|
|||||||
}
|
}
|
||||||
|
|
||||||
public string Link => "https://api.trakt.tv";
|
public string Link => "https://api.trakt.tv";
|
||||||
public string OAuthUrl => "https://api.trakt.tv/oauth/authorize";
|
|
||||||
public string RedirectUri => "https://auth.servarr.com/v1/trakt/auth";
|
|
||||||
public string RenewUri => "https://auth.servarr.com/v1/trakt/renew";
|
|
||||||
public string ClientId => "64508a8bf370cee550dde4806469922fd7cd70afb2d5690e3ee7f75ae784b70e";
|
|
||||||
public virtual string Scope => "";
|
public virtual string Scope => "";
|
||||||
|
|
||||||
[FieldDefinition(0, Label = "Access Token", Type = FieldType.Textbox, Hidden = HiddenType.Hidden)]
|
[FieldDefinition(0, Label = "Access Token", Type = FieldType.Textbox, Hidden = HiddenType.Hidden)]
|
||||||
|
@ -25,7 +25,8 @@ public override INetImportRequestGenerator GetRequestGenerator()
|
|||||||
{
|
{
|
||||||
return new TraktUserRequestGenerator()
|
return new TraktUserRequestGenerator()
|
||||||
{
|
{
|
||||||
Settings = Settings
|
Settings = Settings,
|
||||||
|
ClientId = ClientId
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -8,6 +8,8 @@ public class TraktUserRequestGenerator : INetImportRequestGenerator
|
|||||||
{
|
{
|
||||||
public TraktUserSettings Settings { get; set; }
|
public TraktUserSettings Settings { get; set; }
|
||||||
|
|
||||||
|
public string ClientId { get; set; }
|
||||||
|
|
||||||
public TraktUserRequestGenerator()
|
public TraktUserRequestGenerator()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
@ -41,7 +43,7 @@ private IEnumerable<NetImportRequest> GetMoviesRequest()
|
|||||||
var request = new NetImportRequest($"{link}", HttpAccept.Json);
|
var request = new NetImportRequest($"{link}", HttpAccept.Json);
|
||||||
|
|
||||||
request.HttpRequest.Headers.Add("trakt-api-version", "2");
|
request.HttpRequest.Headers.Add("trakt-api-version", "2");
|
||||||
request.HttpRequest.Headers.Add("trakt-api-key", Settings.ClientId);
|
request.HttpRequest.Headers.Add("trakt-api-key", ClientId);
|
||||||
|
|
||||||
if (Settings.AccessToken.IsNotNullOrWhiteSpace())
|
if (Settings.AccessToken.IsNotNullOrWhiteSpace())
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user