Improved the Plex OAuth flow

pull/4185/head
tidusjar 3 years ago
parent f18aa778e6
commit 5d8a212312

@ -146,6 +146,9 @@ export class LoginComponent implements OnDestroy, OnInit {
} }
public oauth() { public oauth() {
if (this.oAuthWindow) {
this.oAuthWindow.close();
}
this.oAuthWindow = window.open(window.location.toString(), "_blank", `toolbar=0, this.oAuthWindow = window.open(window.location.toString(), "_blank", `toolbar=0,
location=0, location=0,
status=0, status=0,
@ -159,16 +162,22 @@ export class LoginComponent implements OnDestroy, OnInit {
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 => {
this.oAuthWindow!.location.replace(x.url); this.oAuthWindow!.location.replace(x.url);
this.pinTimer = setInterval(() => { if (this.pinTimer) {
clearInterval(this.pinTimer);
}
this.oauthLoading = true; this.pinTimer = setInterval(() => {
this.getPinResult(x.pinId); if(this.oAuthWindow.closed) {
}, 4000); this.oauthLoading = true;
this.getPinResult(x.pinId);
}
}, 1000);
}); });
}); });
} }
public getPinResult(pinId: number) { public getPinResult(pinId: number) {
clearInterval(this.pinTimer);
this.authService.oAuth(pinId).subscribe(x => { this.authService.oAuth(pinId).subscribe(x => {
if(x.access_token) { if(x.access_token) {
this.store.save("id_token", x.access_token); this.store.save("id_token", x.access_token);
@ -176,7 +185,7 @@ export class LoginComponent implements OnDestroy, OnInit {
if (this.authService.loggedIn()) { if (this.authService.loggedIn()) {
this.ngOnDestroy(); this.ngOnDestroy();
if(this.oAuthWindow) { if (this.oAuthWindow) {
this.oAuthWindow.close(); this.oAuthWindow.close();
} }
this.oauthLoading = false; this.oauthLoading = false;
@ -184,6 +193,10 @@ export class LoginComponent implements OnDestroy, OnInit {
return; return;
} }
} }
this.notify.open("Could not log you in!", "OK", {
duration: 3000
});
this.oauthLoading = false;
}, err => { }, err => {
console.log(err); console.log(err);

Loading…
Cancel
Save