More improvements to the Plex OAuth, Added the ability to turn it off if needed

This commit is contained in:
Jamie 2018-04-24 08:32:31 +01:00
commit e12146c986
10 changed files with 40 additions and 14 deletions

View file

@ -55,7 +55,10 @@ namespace Ombi.Core.Authentication
return await _api.GetAccount(accessToken); return await _api.GetAccount(accessToken);
} }
public async Task<Uri> GetOAuthUrl(int pinId, string code) public async Task<Uri> GetOAuthUrl(int pinId, string code, string websiteAddress = null)
{
Uri url;
if (websiteAddress.IsNullOrEmpty())
{ {
var settings = await _customizationSettingsService.GetSettingsAsync(); var settings = await _customizationSettingsService.GetSettingsAsync();
if (settings.ApplicationUrl.IsNullOrEmpty()) if (settings.ApplicationUrl.IsNullOrEmpty())
@ -63,7 +66,13 @@ namespace Ombi.Core.Authentication
return null; return null;
} }
var url = _api.GetOAuthUrl(pinId, code, settings.ApplicationUrl, false); url = _api.GetOAuthUrl(pinId, code, settings.ApplicationUrl, false);
}
else
{
url = _api.GetOAuthUrl(pinId, code, websiteAddress, false);
}
return url; return url;
} }

View file

@ -9,7 +9,7 @@ namespace Ombi.Core.Authentication
{ {
Task<string> GetAccessTokenFromPin(int pinId); Task<string> GetAccessTokenFromPin(int pinId);
Task<OAuthPin> RequestPin(); Task<OAuthPin> RequestPin();
Task<Uri> GetOAuthUrl(int pinId, string code); Task<Uri> GetOAuthUrl(int pinId, string code, string websiteAddress = null);
Uri GetWizardOAuthUrl(int pinId, string code, string websiteAddress); Uri GetWizardOAuthUrl(int pinId, string code, string websiteAddress);
Task<PlexAccount> GetAccount(string accessToken); Task<PlexAccount> GetAccount(string accessToken);
} }

View file

@ -112,6 +112,7 @@ namespace Ombi.Helpers
return uriBuilder.Uri; return uriBuilder.Uri;
} }
} }
public class ApplicationSettingsException : Exception public class ApplicationSettingsException : Exception

View file

@ -6,6 +6,7 @@ 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 bool EnableOAuth { get; set; }
public List<PlexServers> Servers { get; set; } public List<PlexServers> Servers { get; set; }
} }

View file

@ -43,6 +43,7 @@ export interface IEmbyServer extends IExternalSettings {
export interface IPlexSettings extends ISettings { export interface IPlexSettings extends ISettings {
enable: boolean; enable: boolean;
enableOAuth: boolean;
servers: IPlexServer[]; servers: IPlexServer[];
} }

View file

@ -17,7 +17,7 @@ include the remember me checkbox
</div> </div>
<p id="profile-name" class="profile-name-card"></p> <p id="profile-name" class="profile-name-card"></p>
<div *ngIf="!plexEnabled || !customizationSettings.applicationUrl || loginWithOmbi"> <div *ngIf="!plexEnabled || loginWithOmbi">
<form *ngIf="authenticationSettings" class="form-signin" novalidate [formGroup]="form" (ngSubmit)="onSubmit(form)"> <form *ngIf="authenticationSettings" class="form-signin" novalidate [formGroup]="form" (ngSubmit)="onSubmit(form)">
@ -41,15 +41,16 @@ include the remember me checkbox
<!-- /form --> <!-- /form -->
</div> </div>
<!-- Main OAuth Flow --> <!-- Main OAuth Flow -->
<div class="form-signin" *ngIf="plexEnabled && customizationSettings.applicationUrl && !loginWithOmbi"> <div *ngIf="plexEnabled && !loginWithOmbi">
<div class="form-signin">
<button class="btn btn-success" type="button" (click)="loginWithOmbi = true"> <button class="btn btn-success" type="button" (click)="loginWithOmbi = true">
Sign In With {{appName}}</button> Sign In With {{appName}}</button>
</div> </div>
<div class="form-signin" *ngIf="plexEnabled && customizationSettings.applicationUrl && !loginWithOmbi"> <div class="form-signin">
<button class="btn btn-primary" type="button" (click)="oauth()"> <button class="btn btn-primary" type="button" (click)="oauth()">
Sign In With Plex</button> Sign In With Plex</button>
</div> </div>
</div>
</div> </div>
<!-- /card-container --> <!-- /card-container -->

View file

@ -125,7 +125,13 @@ export class LoginComponent implements OnDestroy, OnInit {
public oauth() { public oauth() {
this.authService.login({usePlexOAuth: true, password:"",rememberMe:true,username:""}).subscribe(x => { this.authService.login({usePlexOAuth: true, password:"",rememberMe:true,username:""}).subscribe(x => {
if (window.frameElement) {
// in frame
window.open(x.url, "_blank");
} else {
// not in frame
window.location.href = x.url; window.location.href = x.url;
}
}); });
} }

View file

@ -17,6 +17,12 @@
<label for="enable">Enable</label> <label for="enable">Enable</label>
</div> </div>
</div> </div>
<div class="form-group col-md-3">
<div class="checkbox">
<input type="checkbox" id="enableOAuth" [(ngModel)]="settings.enableOAuth" [checked]="settings.enableOAuth">
<label for="enableOAuth">Enable OAuth</label>
</div>
</div>
<div class="col-md-2 col-md-push-7"> <div class="col-md-2 col-md-push-7">
<button type="button" (click)="addTab()" class="btn btn-success-outline">Add Server</button> <button type="button" (click)="addTab()" class="btn btn-success-outline">Add Server</button>
</div> </div>

View file

@ -154,7 +154,7 @@ namespace Ombi.Controllers
var s = await Get<PlexSettings>(); var s = await Get<PlexSettings>();
return s.Enable; return s.Enable && s.EnableOAuth;
} }
/// <summary> /// <summary>

View file

@ -23,7 +23,7 @@ namespace Ombi.Controllers
{ {
[ApiV1] [ApiV1]
[Produces("application/json")] [Produces("application/json")]
public class TokenController public class TokenController : Controller
{ {
public TokenController(OmbiUserManager um, IOptions<TokenAuthentication> ta, IAuditRepository audit, ITokenRepository token, public TokenController(OmbiUserManager um, IOptions<TokenAuthentication> ta, IAuditRepository audit, ITokenRepository token,
IPlexOAuthManager oAuthManager) IPlexOAuthManager oAuthManager)
@ -83,8 +83,9 @@ namespace Ombi.Controllers
// We need a PIN first // We need a PIN first
var pin = await _plexOAuthManager.RequestPin(); 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 //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) if (url == null)
{ {
return new JsonResult(new return new JsonResult(new