From e12146c98666d5de0471b106e918ff8ea7568468 Mon Sep 17 00:00:00 2001 From: Jamie Date: Tue, 24 Apr 2018 08:32:31 +0100 Subject: [PATCH] More improvements to the Plex OAuth, Added the ability to turn it off if needed --- .../Authentication/PlexOAuthManager.cs | 19 ++++++++++++++----- src/Ombi.Core/IPlexOAuthManager.cs | 2 +- src/Ombi.Helpers/UriHelper.cs | 1 + .../Settings/Models/External/PlexSettings.cs | 1 + .../ClientApp/app/interfaces/ISettings.ts | 1 + .../ClientApp/app/login/login.component.html | 9 +++++---- .../ClientApp/app/login/login.component.ts | 8 +++++++- .../app/settings/plex/plex.component.html | 6 ++++++ src/Ombi/Controllers/SettingsController.cs | 2 +- src/Ombi/Controllers/TokenController.cs | 5 +++-- 10 files changed, 40 insertions(+), 14 deletions(-) diff --git a/src/Ombi.Core/Authentication/PlexOAuthManager.cs b/src/Ombi.Core/Authentication/PlexOAuthManager.cs index d3bab0a05..f3a3e4d01 100644 --- a/src/Ombi.Core/Authentication/PlexOAuthManager.cs +++ b/src/Ombi.Core/Authentication/PlexOAuthManager.cs @@ -55,15 +55,24 @@ namespace Ombi.Core.Authentication return await _api.GetAccount(accessToken); } - public async Task GetOAuthUrl(int pinId, string code) + public async Task GetOAuthUrl(int pinId, string code, string websiteAddress = null) { - var settings = await _customizationSettingsService.GetSettingsAsync(); - if (settings.ApplicationUrl.IsNullOrEmpty()) + Uri url; + if (websiteAddress.IsNullOrEmpty()) { - return null; + var settings = await _customizationSettingsService.GetSettingsAsync(); + if (settings.ApplicationUrl.IsNullOrEmpty()) + { + return null; + } + + url = _api.GetOAuthUrl(pinId, code, settings.ApplicationUrl, false); + } + else + { + url = _api.GetOAuthUrl(pinId, code, websiteAddress, false); } - var url = _api.GetOAuthUrl(pinId, code, settings.ApplicationUrl, false); return url; } diff --git a/src/Ombi.Core/IPlexOAuthManager.cs b/src/Ombi.Core/IPlexOAuthManager.cs index 142d4162a..9c4f0582e 100644 --- a/src/Ombi.Core/IPlexOAuthManager.cs +++ b/src/Ombi.Core/IPlexOAuthManager.cs @@ -9,7 +9,7 @@ namespace Ombi.Core.Authentication { Task GetAccessTokenFromPin(int pinId); Task RequestPin(); - Task GetOAuthUrl(int pinId, string code); + Task GetOAuthUrl(int pinId, string code, string websiteAddress = null); Uri GetWizardOAuthUrl(int pinId, string code, string websiteAddress); Task GetAccount(string accessToken); } diff --git a/src/Ombi.Helpers/UriHelper.cs b/src/Ombi.Helpers/UriHelper.cs index 83cd27e9d..6ec8047ae 100644 --- a/src/Ombi.Helpers/UriHelper.cs +++ b/src/Ombi.Helpers/UriHelper.cs @@ -112,6 +112,7 @@ namespace Ombi.Helpers return uriBuilder.Uri; } + } public class ApplicationSettingsException : Exception diff --git a/src/Ombi.Settings/Settings/Models/External/PlexSettings.cs b/src/Ombi.Settings/Settings/Models/External/PlexSettings.cs index 3faba3e42..a77b54a87 100644 --- a/src/Ombi.Settings/Settings/Models/External/PlexSettings.cs +++ b/src/Ombi.Settings/Settings/Models/External/PlexSettings.cs @@ -6,6 +6,7 @@ namespace Ombi.Core.Settings.Models.External public sealed class PlexSettings : Ombi.Settings.Settings.Models.Settings { public bool Enable { get; set; } + public bool EnableOAuth { get; set; } public List Servers { get; set; } } diff --git a/src/Ombi/ClientApp/app/interfaces/ISettings.ts b/src/Ombi/ClientApp/app/interfaces/ISettings.ts index d67ebc698..234e0aa5b 100644 --- a/src/Ombi/ClientApp/app/interfaces/ISettings.ts +++ b/src/Ombi/ClientApp/app/interfaces/ISettings.ts @@ -43,6 +43,7 @@ export interface IEmbyServer extends IExternalSettings { export interface IPlexSettings extends ISettings { enable: boolean; + enableOAuth: boolean; servers: IPlexServer[]; } diff --git a/src/Ombi/ClientApp/app/login/login.component.html b/src/Ombi/ClientApp/app/login/login.component.html index a50040fab..40a5ef5a0 100644 --- a/src/Ombi/ClientApp/app/login/login.component.html +++ b/src/Ombi/ClientApp/app/login/login.component.html @@ -17,7 +17,7 @@ include the remember me checkbox

-
+
-
+
+
+ + +
+
diff --git a/src/Ombi/Controllers/SettingsController.cs b/src/Ombi/Controllers/SettingsController.cs index 0a515d9cb..1bbb5af49 100644 --- a/src/Ombi/Controllers/SettingsController.cs +++ b/src/Ombi/Controllers/SettingsController.cs @@ -154,7 +154,7 @@ namespace Ombi.Controllers var s = await Get(); - return s.Enable; + return s.Enable && s.EnableOAuth; } /// diff --git a/src/Ombi/Controllers/TokenController.cs b/src/Ombi/Controllers/TokenController.cs index b337b3f51..a488ba172 100644 --- a/src/Ombi/Controllers/TokenController.cs +++ b/src/Ombi/Controllers/TokenController.cs @@ -23,7 +23,7 @@ namespace Ombi.Controllers { [ApiV1] [Produces("application/json")] - public class TokenController + public class TokenController : Controller { public TokenController(OmbiUserManager um, IOptions ta, IAuditRepository audit, ITokenRepository token, IPlexOAuthManager oAuthManager) @@ -83,8 +83,9 @@ namespace Ombi.Controllers // We need a PIN first var pin = await _plexOAuthManager.RequestPin(); + var websiteAddress = $"{this.Request.Scheme}://{this.Request.Host}{this.Request.PathBase}"; //https://app.plex.tv/auth#?forwardUrl=http://google.com/&clientID=Ombi-Test&context%5Bdevice%5D%5Bproduct%5D=Ombi%20SSO&pinID=798798&code=4lgfd - var url = await _plexOAuthManager.GetOAuthUrl(pin.id, pin.code); + var url = await _plexOAuthManager.GetOAuthUrl(pin.id, pin.code, websiteAddress); if (url == null) { return new JsonResult(new