API key improvements

Fixed: Special characters in API key
New: Add heathcheck for API Key

(cherry picked from commit 9325140b90f8ac625ae5b26075748c22f6f06158)

Closes #3636
pull/3633/head
Bogdan 1 year ago
parent 7f3ccf659c
commit 8b512caa67

@ -33,7 +33,7 @@ function getUrls(state) {
icalUrl += `tags=${tags.toString()}&`;
}
icalUrl += `pastDays=${pastDays}&futureDays=${futureDays}&apikey=${window.Lidarr.apiKey}`;
icalUrl += `pastDays=${pastDays}&futureDays=${futureDays}&apikey=${encodeURIComponent(window.Lidarr.apiKey)}`;
const iCalHttpUrl = `${window.location.protocol}//${icalUrl}`;
const iCalWebCalUrl = `webcal://${icalUrl}`;

@ -60,7 +60,7 @@ function Logger(minimumLogLevel) {
}
Logger.prototype.cleanse = function(message) {
const apikey = new RegExp(`access_token=${window.Lidarr.apiKey}`, 'g');
const apikey = new RegExp(`access_token=${encodeURIComponent(window.Lidarr.apiKey)}`, 'g');
return message.replace(apikey, 'access_token=(removed)');
};
@ -104,7 +104,7 @@ class SignalRConnector extends Component {
this.connection = new signalR.HubConnectionBuilder()
.configureLogging(new Logger(signalR.LogLevel.Information))
.withUrl(`${url}?access_token=${window.Lidarr.apiKey}`)
.withUrl(`${url}?access_token=${encodeURIComponent(window.Lidarr.apiKey)}`)
.withAutomaticReconnect({
nextRetryDelayInMilliseconds: (retryContext) => {
if (retryContext.elapsedMilliseconds > 180000) {

@ -0,0 +1,35 @@
using NLog;
using NzbDrone.Core.Configuration;
using NzbDrone.Core.Configuration.Events;
using NzbDrone.Core.Lifecycle;
using NzbDrone.Core.Localization;
namespace NzbDrone.Core.HealthCheck.Checks
{
[CheckOn(typeof(ApplicationStartedEvent))]
[CheckOn(typeof(ConfigSavedEvent))]
public class ApiKeyValidationCheck : HealthCheckBase
{
private readonly IConfigFileProvider _configFileProvider;
private readonly Logger _logger;
public ApiKeyValidationCheck(IConfigFileProvider configFileProvider, ILocalizationService localizationService, Logger logger)
: base(localizationService)
{
_configFileProvider = configFileProvider;
_logger = logger;
}
public override HealthCheck Check()
{
if (_configFileProvider.ApiKey.Length < 20)
{
_logger.Warn("Please update your API key to be at least 20 characters long. You can do this via settings or the config file");
return new HealthCheck(GetType(), HealthCheckResult.Warning, _localizationService.GetLocalizedString("ApiKeyValidationHealthCheckMessage"), "#invalid-api-key");
}
return new HealthCheck(GetType());
}
}
}

@ -68,6 +68,7 @@
"AnchorTooltip": "This file is already in your library for a release you are currently importing",
"AnyReleaseOkHelpText": "Lidarr will automatically switch to the release best matching downloaded tracks",
"ApiKeyHelpTextWarning": "Requires restart to take effect",
"ApiKeyValidationHealthCheckMessage": "Please update your API key to be at least 20 characters long. You can do this via settings or the config file",
"AppDataDirectory": "AppData directory",
"AppDataLocationHealthCheckMessage": "Updating will not be possible to prevent deleting AppData on Update",
"ApplicationURL": "Application URL",

Loading…
Cancel
Save