From 80b48877cae18b132f70492a22b8d413831ff4aa Mon Sep 17 00:00:00 2001 From: Jordan Jones Date: Tue, 12 Mar 2024 19:13:23 -0500 Subject: [PATCH 1/2] feat(plex-login): use application name for plex product name on login --- src/components/PlexLoginButton/index.tsx | 6 +++++- src/utils/plex.ts | 16 ++++++++++++---- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/src/components/PlexLoginButton/index.tsx b/src/components/PlexLoginButton/index.tsx index 36323173..8809f5fc 100644 --- a/src/components/PlexLoginButton/index.tsx +++ b/src/components/PlexLoginButton/index.tsx @@ -1,3 +1,4 @@ +import useSettings from '@app/hooks/useSettings'; import globalMessages from '@app/i18n/globalMessages'; import PlexOAuth from '@app/utils/plex'; import { ArrowLeftOnRectangleIcon } from '@heroicons/react/24/outline'; @@ -24,11 +25,14 @@ const PlexLoginButton = ({ }: PlexLoginButtonProps) => { const intl = useIntl(); const [loading, setLoading] = useState(false); + const settings = useSettings(); const getPlexLogin = async () => { setLoading(true); try { - const authToken = await plexOAuth.login(); + const authToken = await plexOAuth.login( + settings.currentSettings.applicationTitle + ); setLoading(false); onAuthToken(authToken); } catch (e) { diff --git a/src/utils/plex.ts b/src/utils/plex.ts index f773d868..f8521811 100644 --- a/src/utils/plex.ts +++ b/src/utils/plex.ts @@ -40,8 +40,11 @@ class PlexOAuth { private popup?: Window; private authToken?: string; + private DEFAULT_APPLICATION_NAME = 'Overseerr'; - public initializeHeaders(): void { + public initializeHeaders( + applicationName = this.DEFAULT_APPLICATION_NAME + ): void { if (!window) { throw new Error( 'Window is not defined. Are you calling this in the browser?' @@ -55,10 +58,15 @@ class PlexOAuth { clientId = uuid; } + const plexProductName = + applicationName === this.DEFAULT_APPLICATION_NAME + ? applicationName + : `${applicationName} - Overseerr`; + const browser = Bowser.getParser(window.navigator.userAgent); this.plexHeaders = { Accept: 'application/json', - 'X-Plex-Product': 'Overseerr', + 'X-Plex-Product': plexProductName, 'X-Plex-Version': 'Plex OAuth', 'X-Plex-Client-Identifier': clientId, 'X-Plex-Model': 'Plex OAuth', @@ -93,8 +101,8 @@ class PlexOAuth { this.openPopup({ title: 'Plex Auth', w: 600, h: 700 }); } - public async login(): Promise { - this.initializeHeaders(); + public async login(applicationName?: string): Promise { + this.initializeHeaders(applicationName); await this.getPin(); if (!this.plexHeaders || !this.pin) { From 9815e2e0eb9499dd5cb035fc561e4929b7852bac Mon Sep 17 00:00:00 2001 From: Jordan Jones Date: Wed, 13 Mar 2024 09:26:35 -0500 Subject: [PATCH 2/2] refactor(plex): use default application name const instead of Overseerr text --- src/utils/plex.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/utils/plex.ts b/src/utils/plex.ts index f8521811..890a588e 100644 --- a/src/utils/plex.ts +++ b/src/utils/plex.ts @@ -61,7 +61,7 @@ class PlexOAuth { const plexProductName = applicationName === this.DEFAULT_APPLICATION_NAME ? applicationName - : `${applicationName} - Overseerr`; + : `${applicationName} - ${this.DEFAULT_APPLICATION_NAME}`; const browser = Bowser.getParser(window.navigator.userAgent); this.plexHeaders = {