Made the OAuth a Popout to work with Org

pull/2452/head
Jamie 6 years ago
parent c4b21c5f77
commit b6645c8b58

@ -24,7 +24,7 @@ namespace Ombi.Api.Plex
Task<PlexAccount> GetAccount(string authToken);
Task<PlexMetadata> GetRecentlyAdded(string authToken, string uri, string sectionId);
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);
}
}

@ -217,15 +217,11 @@ namespace Ombi.Api.Plex
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);
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("code", code);
request.AddQueryString("context[device][product]", ApplicationName);

@ -28,19 +28,6 @@ namespace Ombi.Core.Authentication
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;
}
@ -52,14 +39,14 @@ namespace Ombi.Core.Authentication
public async Task<Uri> GetOAuthUrl(int pinId, string code, string websiteAddress = null)
{
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;
}
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;
}
}

@ -40,6 +40,7 @@ export class LoginComponent implements OnDestroy, OnInit {
}
private timer: any;
private pinTimer: any;
private clientId: string;
private errorBody: string;
@ -128,17 +129,33 @@ export class LoginComponent implements OnDestroy, OnInit {
this.plexTv.GetPin(this.clientId, this.appName).subscribe((pin: any) => {
this.authService.login({ usePlexOAuth: true, password: "", rememberMe: true, username: "", plexTvPin: pin }).subscribe(x => {
if (window.frameElement) {
// in frame
window.open(x.url, "_blank");
} else {
// not in frame
window.location.href = x.url;
}
window.open(x.url, "_blank");
this.pinTimer = setInterval(() => {
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.router.navigate(["search"]);
return;
}
}
}, err => {
this.notify.error(err.statusText);
this.router.navigate(["login"]);
});
}
public ngOnDestroy() {
clearInterval(this.timer);
}

@ -91,7 +91,7 @@ namespace Ombi.Controllers
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();

Loading…
Cancel
Save