Made the app name customizable for the OAUth !wip

This commit is contained in:
Jamie Rees 2018-04-19 22:18:25 +01:00
commit 5531af462c
2 changed files with 19 additions and 16 deletions

View file

@ -10,38 +10,42 @@ using Ombi.Api.Plex.Models.Status;
using Ombi.Core.Settings; using Ombi.Core.Settings;
using Ombi.Core.Settings.Models.External; using Ombi.Core.Settings.Models.External;
using Ombi.Helpers; using Ombi.Helpers;
using Ombi.Settings.Settings.Models;
namespace Ombi.Api.Plex namespace Ombi.Api.Plex
{ {
public class PlexApi : IPlexApi public class PlexApi : IPlexApi
{ {
public PlexApi(IApi api, ISettingsService<PlexSettings> settings) public PlexApi(IApi api, ISettingsService<CustomizationSettings> settings)
{ {
Api = api; Api = api;
_plex = settings; _custom = settings;
} }
private IApi Api { get; } private IApi Api { get; }
private readonly ISettingsService<PlexSettings> _plex; private readonly ISettingsService<CustomizationSettings> _custom;
private string _clientId; private string _app;
private string ClientIdSecret private string ApplicationName
{ {
get get
{ {
if (string.IsNullOrEmpty(_clientId)) if (string.IsNullOrEmpty(_app))
{ {
var settings = _plex.GetSettings(); var settings = _custom.GetSettings();
if (settings.UniqueInstallCode.IsNullOrEmpty()) if (settings.ApplicationName.IsNullOrEmpty())
{ {
settings.UniqueInstallCode = Guid.NewGuid().ToString("N"); _app = "Ombi";
_plex.SaveSettings(settings); }
else
{
_app = settings.ApplicationName;
} }
_clientId = settings.UniqueInstallCode; return _app;
} }
return _clientId; return _app;
} }
} }
@ -215,7 +219,7 @@ namespace Ombi.Api.Plex
request.AddQueryString("code", code); request.AddQueryString("code", code);
request.AddQueryString("context[device][product]", "Ombi"); request.AddQueryString("context[device][product]", "Ombi");
request.AddQueryString("context[device][environment]", "bundled"); request.AddQueryString("context[device][environment]", "bundled");
request.AddQueryString("clientID", $"OmbiV3{ClientIdSecret}"); request.AddQueryString("clientID", $"OmbiV3");
if (request.FullUri.Fragment.Equals("#")) if (request.FullUri.Fragment.Equals("#"))
{ {
@ -246,8 +250,8 @@ namespace Ombi.Api.Plex
/// <param name="request"></param> /// <param name="request"></param>
private void AddHeaders(Request request) private void AddHeaders(Request request)
{ {
request.AddHeader("X-Plex-Client-Identifier", $"OmbiV3{ClientIdSecret}"); request.AddHeader("X-Plex-Client-Identifier", $"OmbiV3");
request.AddHeader("X-Plex-Product", "Ombi"); request.AddHeader("X-Plex-Product", ApplicationName);
request.AddHeader("X-Plex-Version", "3"); request.AddHeader("X-Plex-Version", "3");
request.AddContentHeader("Content-Type", request.ContentType == ContentType.Json ? "application/json" : "application/xml"); request.AddContentHeader("Content-Type", request.ContentType == ContentType.Json ? "application/json" : "application/xml");
request.AddHeader("Accept", "application/json"); request.AddHeader("Accept", "application/json");

View file

@ -6,7 +6,6 @@ namespace Ombi.Core.Settings.Models.External
public sealed class PlexSettings : Ombi.Settings.Settings.Models.Settings public sealed class PlexSettings : Ombi.Settings.Settings.Models.Settings
{ {
public bool Enable { get; set; } public bool Enable { get; set; }
public string UniqueInstallCode { get; set; }
public List<PlexServers> Servers { get; set; } public List<PlexServers> Servers { get; set; }
} }