mirror of
https://github.com/Ombi-app/Ombi.git
synced 2025-08-13 18:16:55 -07:00
More improvements to the Plex OAuth, Added the ability to turn it off if needed
This commit is contained in:
parent
f62e97bb32
commit
e12146c986
10 changed files with 40 additions and 14 deletions
|
@ -55,7 +55,10 @@ namespace Ombi.Core.Authentication
|
|||
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();
|
||||
if (settings.ApplicationUrl.IsNullOrEmpty())
|
||||
|
@ -63,7 +66,13 @@ namespace Ombi.Core.Authentication
|
|||
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;
|
||||
}
|
||||
|
||||
|
|
|
@ -9,7 +9,7 @@ namespace Ombi.Core.Authentication
|
|||
{
|
||||
Task<string> GetAccessTokenFromPin(int pinId);
|
||||
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);
|
||||
Task<PlexAccount> GetAccount(string accessToken);
|
||||
}
|
||||
|
|
|
@ -112,6 +112,7 @@ namespace Ombi.Helpers
|
|||
|
||||
return uriBuilder.Uri;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public class ApplicationSettingsException : Exception
|
||||
|
|
|
@ -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<PlexServers> Servers { get; set; }
|
||||
}
|
||||
|
||||
|
|
|
@ -43,6 +43,7 @@ export interface IEmbyServer extends IExternalSettings {
|
|||
|
||||
export interface IPlexSettings extends ISettings {
|
||||
enable: boolean;
|
||||
enableOAuth: boolean;
|
||||
servers: IPlexServer[];
|
||||
}
|
||||
|
||||
|
|
|
@ -17,7 +17,7 @@ include the remember me checkbox
|
|||
</div>
|
||||
<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)">
|
||||
|
||||
|
||||
|
@ -41,15 +41,16 @@ include the remember me checkbox
|
|||
<!-- /form -->
|
||||
</div>
|
||||
<!-- 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">
|
||||
Sign In With {{appName}}</button>
|
||||
</div>
|
||||
<div class="form-signin" *ngIf="plexEnabled && customizationSettings.applicationUrl && !loginWithOmbi">
|
||||
<div class="form-signin">
|
||||
<button class="btn btn-primary" type="button" (click)="oauth()">
|
||||
Sign In With Plex</button>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
</div>
|
||||
<!-- /card-container -->
|
||||
|
|
|
@ -125,7 +125,13 @@ export class LoginComponent implements OnDestroy, OnInit {
|
|||
|
||||
public oauth() {
|
||||
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;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
@ -17,6 +17,12 @@
|
|||
<label for="enable">Enable</label>
|
||||
</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">
|
||||
<button type="button" (click)="addTab()" class="btn btn-success-outline">Add Server</button>
|
||||
</div>
|
||||
|
|
|
@ -154,7 +154,7 @@ namespace Ombi.Controllers
|
|||
var s = await Get<PlexSettings>();
|
||||
|
||||
|
||||
return s.Enable;
|
||||
return s.Enable && s.EnableOAuth;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
|
|
@ -23,7 +23,7 @@ namespace Ombi.Controllers
|
|||
{
|
||||
[ApiV1]
|
||||
[Produces("application/json")]
|
||||
public class TokenController
|
||||
public class TokenController : Controller
|
||||
{
|
||||
public TokenController(OmbiUserManager um, IOptions<TokenAuthentication> 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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue