Merge branch 'develop' of https://github.com/tidusjar/ombi into develop

pull/2450/head
TidusJar 6 years ago
commit a613e2cec6

@ -24,7 +24,7 @@ namespace Ombi.Api.Plex
Task<PlexAccount> GetAccount(string authToken); Task<PlexAccount> GetAccount(string authToken);
Task<PlexMetadata> GetRecentlyAdded(string authToken, string uri, string sectionId); Task<PlexMetadata> GetRecentlyAdded(string authToken, string uri, string sectionId);
Task<OAuthPin> GetPin(int pinId); Task<OAuthPin> GetPin(int pinId);
Task<Uri> GetOAuthUrl(int pinId, string code, string applicationUrl, bool wizard); Task<Uri> GetOAuthUrl(int pinId, string code, string applicationUrl);
Task<PlexAddWrapper> AddUser(string emailAddress, string serverId, string authToken, int[] libs); Task<PlexAddWrapper> AddUser(string emailAddress, string serverId, string authToken, int[] libs);
} }
} }

@ -217,15 +217,11 @@ namespace Ombi.Api.Plex
return await Api.Request<OAuthPin>(request); return await Api.Request<OAuthPin>(request);
} }
public async Task<Uri> GetOAuthUrl(int pinId, string code, string applicationUrl, bool wizard) public async Task<Uri> GetOAuthUrl(int pinId, string code, string applicationUrl)
{ {
var request = new Request("auth#", "https://app.plex.tv", HttpMethod.Get); var request = new Request("auth#", "https://app.plex.tv", HttpMethod.Get);
await AddHeaders(request); await AddHeaders(request);
var forwardUrl = wizard
? new Request($"Wizard/OAuth/{pinId}", applicationUrl, HttpMethod.Get)
: new Request($"Login/OAuth/{pinId}", applicationUrl, HttpMethod.Get);
request.AddQueryString("forwardUrl", forwardUrl.FullUri.ToString());
request.AddQueryString("pinID", pinId.ToString()); request.AddQueryString("pinID", pinId.ToString());
request.AddQueryString("code", code); request.AddQueryString("code", code);
request.AddQueryString("context[device][product]", ApplicationName); request.AddQueryString("context[device][product]", ApplicationName);

@ -28,19 +28,6 @@ namespace Ombi.Core.Authentication
return string.Empty; return string.Empty;
} }
if (pin.authToken.IsNullOrEmpty())
{
// Looks like we do not have a pin yet, we should retry a few times.
var retryCount = 0;
var retryMax = 5;
var retryWaitMs = 1000;
while (pin.authToken.IsNullOrEmpty() && retryCount < retryMax)
{
retryCount++;
await Task.Delay(retryWaitMs);
pin = await _api.GetPin(pinId);
}
}
return pin.authToken; return pin.authToken;
} }
@ -52,14 +39,14 @@ namespace Ombi.Core.Authentication
public async Task<Uri> GetOAuthUrl(int pinId, string code, string websiteAddress = null) public async Task<Uri> GetOAuthUrl(int pinId, string code, string websiteAddress = null)
{ {
var settings = await _customizationSettingsService.GetSettingsAsync(); var settings = await _customizationSettingsService.GetSettingsAsync();
var url = await _api.GetOAuthUrl(pinId, code, settings.ApplicationUrl.IsNullOrEmpty() ? websiteAddress : settings.ApplicationUrl, false); var url = await _api.GetOAuthUrl(pinId, code, settings.ApplicationUrl.IsNullOrEmpty() ? websiteAddress : settings.ApplicationUrl);
return url; return url;
} }
public async Task<Uri> GetWizardOAuthUrl(int pinId, string code, string websiteAddress) public async Task<Uri> GetWizardOAuthUrl(int pinId, string code, string websiteAddress)
{ {
var url = await _api.GetOAuthUrl(pinId, code, websiteAddress, true); var url = await _api.GetOAuthUrl(pinId, code, websiteAddress);
return url; return url;
} }
} }

@ -30,6 +30,7 @@ export class LoginComponent implements OnDestroy, OnInit {
public landingFlag: boolean; public landingFlag: boolean;
public baseUrl: string; public baseUrl: string;
public loginWithOmbi: boolean; public loginWithOmbi: boolean;
public pinTimer: any;
public get appName(): string { public get appName(): string {
if (this.customizationSettings.applicationName) { if (this.customizationSettings.applicationName) {
@ -115,6 +116,7 @@ export class LoginComponent implements OnDestroy, OnInit {
localStorage.setItem("id_token", x.access_token); localStorage.setItem("id_token", x.access_token);
if (this.authService.loggedIn()) { if (this.authService.loggedIn()) {
this.ngOnDestroy();
this.router.navigate(["search"]); this.router.navigate(["search"]);
} else { } else {
this.notify.error(this.errorBody); this.notify.error(this.errorBody);
@ -128,19 +130,46 @@ export class LoginComponent implements OnDestroy, OnInit {
this.plexTv.GetPin(this.clientId, this.appName).subscribe((pin: any) => { this.plexTv.GetPin(this.clientId, this.appName).subscribe((pin: any) => {
this.authService.login({ usePlexOAuth: true, password: "", rememberMe: true, username: "", plexTvPin: pin }).subscribe(x => { this.authService.login({ usePlexOAuth: true, password: "", rememberMe: true, username: "", plexTvPin: pin }).subscribe(x => {
if (window.frameElement) {
// in frame window.open(x.url, "_blank", `toolbar=0,
window.open(x.url, "_blank"); location=0,
} else { status=0,
// not in frame menubar=0,
window.location.href = x.url; scrollbars=1,
} resizable=1,
width=500,
height=500`);
this.pinTimer = setInterval(() => {
this.notify.info("Authenticating", "Loading... Please Wait");
this.getPinResult(x.pinId);
}, 10000);
}); });
}); });
} }
public getPinResult(pinId: number) {
this.authService.oAuth(pinId).subscribe(x => {
if(x.access_token) {
localStorage.setItem("id_token", x.access_token);
if (this.authService.loggedIn()) {
this.ngOnDestroy();
this.router.navigate(["search"]);
return;
}
}
}, err => {
this.notify.error(err.statusText);
this.router.navigate(["login"]);
});
}
public ngOnDestroy() { public ngOnDestroy() {
clearInterval(this.timer); clearInterval(this.timer);
clearInterval(this.pinTimer);
} }
private cycleBackground() { private cycleBackground() {

@ -91,7 +91,7 @@ namespace Ombi.Controllers
error = "Application URL has not been set" error = "Application URL has not been set"
}); });
} }
return new JsonResult(new { url = url.ToString() }); return new JsonResult(new { url = url.ToString(), pinId = model.PlexTvPin.id });
} }
return new UnauthorizedResult(); return new UnauthorizedResult();

Loading…
Cancel
Save