Skip to content

Commit

Permalink
Improved the Plex OAuth flow
Browse files Browse the repository at this point in the history
  • Loading branch information
tidusjar committed May 6, 2021
1 parent f18aa77 commit 5d8a212
Showing 1 changed file with 18 additions and 5 deletions.
23 changes: 18 additions & 5 deletions src/Ombi/ClientApp/src/app/login/login.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,9 @@ export class LoginComponent implements OnDestroy, OnInit {
}

public oauth() {
if (this.oAuthWindow) {
this.oAuthWindow.close();
}
this.oAuthWindow = window.open(window.location.toString(), "_blank", `toolbar=0,
location=0,
status=0,
Expand All @@ -159,31 +162,41 @@ export class LoginComponent implements OnDestroy, OnInit {
this.authService.login({ usePlexOAuth: true, password: "", rememberMe: true, username: "", plexTvPin: pin }).subscribe(x => {
this.oAuthWindow!.location.replace(x.url);

this.pinTimer = setInterval(() => {
if (this.pinTimer) {
clearInterval(this.pinTimer);
}

this.oauthLoading = true;
this.getPinResult(x.pinId);
}, 4000);
this.pinTimer = setInterval(() => {
if(this.oAuthWindow.closed) {
this.oauthLoading = true;
this.getPinResult(x.pinId);
}
}, 1000);
});
});
}

public getPinResult(pinId: number) {
clearInterval(this.pinTimer);
this.authService.oAuth(pinId).subscribe(x => {
if(x.access_token) {
this.store.save("id_token", x.access_token);

if (this.authService.loggedIn()) {
this.ngOnDestroy();

if(this.oAuthWindow) {
if (this.oAuthWindow) {
this.oAuthWindow.close();
}
this.oauthLoading = false;
this.router.navigate(["search"]);
return;
}
}
this.notify.open("Could not log you in!", "OK", {
duration: 3000
});
this.oauthLoading = false;

}, err => {
console.log(err);
Expand Down

0 comments on commit 5d8a212

Please sign in to comment.