Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CXL lite: SSO redirect, videos access #12

Merged
merged 3 commits into from
Oct 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions packages/hooks-react/src/useContentProtection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import AccountController from '@jwp/ott-common/src/controllers/AccountController
import { useConfigStore } from '@jwp/ott-common/src/stores/ConfigStore';
import { isTruthyCustomParamValue } from '@jwp/ott-common/src/utils/common';
import { useAccountStore } from '@jwp/ott-common/src/stores/AccountStore';
import env from '@jwp/ott-common/src/env';

import { generateJwtSignedContentToken, useOAuth } from './useOAuth';

Expand Down Expand Up @@ -57,11 +58,15 @@ const useContentProtection = <T>(
// if self-signed is enabled in jwp dashboard
// and
// isOAuthMode is enabled and user is logged in and in premium mode
if (!!id && signingEnabled && isOAuthMode && !!user && !!user?.isPremium) {
if (!!id && signingEnabled && isOAuthMode && !!user && (env.APP_OAUTH_UNLOCK_ONLY_PREMIUM ? !!user?.isPremium : true)) {
return generateJwtSignedContentToken(id, `Bearer ${bearerToken}`);
}
},
{ enabled: signingEnabled && enabled && !!id && (isOAuthMode ? !!user?.isPremium : false), keepPreviousData: false, staleTime: 15 * 60 * 1000 },
{
enabled: signingEnabled && enabled && !!id && (isOAuthMode ? (env.APP_OAUTH_UNLOCK_ONLY_PREMIUM ? !!user?.isPremium : true) : false),
keepPreviousData: false,
staleTime: 15 * 60 * 1000,
},
);

const queryResult = useQuery<T | undefined>([type, id, params, token], async () => callback(token, drmPolicyId), {
Expand Down
3 changes: 2 additions & 1 deletion packages/hooks-react/src/useProtectedMedia.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { useEffect, useState } from 'react';
import type { PlaylistItem } from '@jwp/ott-common/types/playlist';
import ApiService from '@jwp/ott-common/src/services/ApiService';
import { getModule } from '@jwp/ott-common/src/modules/container';
import env from '@jwp/ott-common/src/env';

import useContentProtection from './useContentProtection';

Expand All @@ -15,7 +16,7 @@ export default function useProtectedMedia(item: PlaylistItem) {
useEffect(() => {
const m3u8 = contentProtectionQuery.data?.sources.find((source) => source.file.indexOf('.m3u8') !== -1);
if (!m3u8) {
setIsUserBlocked(!contentProtectionQuery?.user?.isPremium);
setIsUserBlocked(env.APP_OAUTH_UNLOCK_ONLY_PREMIUM ? !contentProtectionQuery?.user?.isPremium : false);
return;
}
fetch(m3u8.file, { method: 'HEAD' }).then((response) => {
Expand Down
2 changes: 2 additions & 0 deletions packages/ui-react/src/components/Header/Header.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
openLanguageMenu={vi.fn()}
closeLanguageMenu={vi.fn()}
isLoggedIn={false}
isPremium={false}
canLogin={true}
showPaymentsMenuItem={true}
supportedLanguages={[]}
Expand All @@ -50,7 +51,7 @@
</Header>,
);

expect(container).toMatchSnapshot();

Check failure on line 54 in packages/ui-react/src/components/Header/Header.test.tsx

View workflow job for this annotation

GitHub Actions / test (18.x)

src/components/Header/Header.test.tsx > <Header /> > renders header

Error: Snapshot `<Header /> > renders header 1` mismatched - Expected + Received @@ -40,10 +40,13 @@ class="_nav_f4f7a7" > a </nav> <div + class="_customActions_f4f7a7" + /> + <div class="_actions_f4f7a7" > <button aria-label="Open search" class="_iconButton_0fef65 _iconButton_f4f7a7 _actionButton_f4f7a7" @@ -55,10 +58,31 @@ viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg" > <path d="M15.5 14h-.79l-.28-.27C15.41 12.59 16 11.11 16 9.5 16 5.91 13.09 3 9.5 3S3 5.91 3 9.5 5.91 16 9.5 16c1.61 0 3.09-.59 4.23-1.57l.27.28v.79l5 4.99L20.49 19l-4.99-5zm-6 0C7.01 14 5 11.99 5 9.5S7.01 5 9.5 5 14 7.01 14 9.5 11.99 14 9.5 14z" + /> + </svg> + </button> + <button + aria-controls="language-panel" + aria-expanded="false" + aria-haspopup="menu" + aria-label="language_menu" + class="_iconButton_0fef65 _iconButton_f4f7a7 _actionButton_f4f7a7" + data-testid="language-menu-button" + type="button" + > + <svg + aria-hidden="true" + class="_icon_585b29" + viewBox="0 0 24 24" + xmlns="http://www.w3.org/2000/svg" + > + <path + d="M11.99 2C6.47 2 2 6.48 2 12s4.47 10 9.99 10C17.52 22 22 17.52 22 12S17.52 2 11.99 2zm6.93 6h-2.95c-.32-1.25-.78-2.45-1.38-3.56 1.84.63 3.37 1.91 4.33 3.56zM12 4.04c.83 1.2 1.48 2.53 1.91 3.96h-3.82c.43-1.43 1.08-2.76 1.91-3.96zM4.26 14C4.1 13.36 4 12.69 4 12s.1-1.36.26-2h3.38c-.08.66-.14 1.32-.14 2 0 .68.06 1.34.14 2H4.26zm.82 2h2.95c.32 1.25.78 2.45 1.38 3.56-1.84-.63-3.37-1.9-4.33-3.56zm2.95-8H5.08c.96-1.66 2.49-2.93 4.33-3.56C8.81 5.55 8.35 6.75 8.03 8zM12 19.96c-.83-1.2-1.48-2.53-1.91-3.96h3.82c-.43 1.43-1.08 2.76-1.91 3.96zM14.34 14H9.66c-.09-.66-.16-1.32-.16-2 0-.68.07-1.35.16-2h4.68c.09.65.16 1.32.16 2 0 .68-.07 1.34-.16 2zm.25 5.56c.6-1.11 1.06-2.31 1.38-3.56h2.95c-.96 1.65-2.49 2.93-4.33 3.56zM16.36 14c.08-.66.14-1.32.14-2 0-.68-.06-1.34-.14-2h3.38c.16.64.26 1.31.26 2s-.1 1.36-.26 2h-3.38z" + fill="currentColor" /> </svg> </button> <div class="_buttonContainer_f4f7a7" ❯ src/components/Header/Header.test.tsx:54:23
});

test('renders header with nav buttons', () => {
Expand All @@ -77,6 +78,7 @@
openLanguageMenu={vi.fn()}
closeLanguageMenu={vi.fn()}
isLoggedIn={false}
isPremium={false}
canLogin={true}
showPaymentsMenuItem={true}
supportedLanguages={[]}
Expand All @@ -87,6 +89,6 @@
/>,
);

expect(container).toMatchSnapshot();

Check failure on line 92 in packages/ui-react/src/components/Header/Header.test.tsx

View workflow job for this annotation

GitHub Actions / test (18.x)

src/components/Header/Header.test.tsx > <Header /> > renders header with nav buttons

Error: Snapshot `<Header /> > renders header with nav buttons 1` mismatched - Expected + Received @@ -47,10 +47,13 @@ a </li> </ul> </nav> <div + class="_customActions_f4f7a7" + /> + <div class="_actions_f4f7a7" > <button aria-label="Open search" class="_iconButton_0fef65 _iconButton_f4f7a7 _actionButton_f4f7a7" @@ -62,10 +65,31 @@ viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg" > <path d="M15.5 14h-.79l-.28-.27C15.41 12.59 16 11.11 16 9.5 16 5.91 13.09 3 9.5 3S3 5.91 3 9.5 5.91 16 9.5 16c1.61 0 3.09-.59 4.23-1.57l.27.28v.79l5 4.99L20.49 19l-4.99-5zm-6 0C7.01 14 5 11.99 5 9.5S7.01 5 9.5 5 14 7.01 14 9.5 11.99 14 9.5 14z" + /> + </svg> + </button> + <button + aria-controls="language-panel" + aria-expanded="false" + aria-haspopup="menu" + aria-label="language_menu" + class="_iconButton_0fef65 _iconButton_f4f7a7 _actionButton_f4f7a7" + data-testid="language-menu-button" + type="button" + > + <svg + aria-hidden="true" + class="_icon_585b29" + viewBox="0 0 24 24" + xmlns="http://www.w3.org/2000/svg" + > + <path + d="M11.99 2C6.47 2 2 6.48 2 12s4.47 10 9.99 10C17.52 22 22 17.52 22 12S17.52 2 11.99 2zm6.93 6h-2.95c-.32-1.25-.78-2.45-1.38-3.56 1.84.63 3.37 1.91 4.33 3.56zM12 4.04c.83 1.2 1.48 2.53 1.91 3.96h-3.82c.43-1.43 1.08-2.76 1.91-3.96zM4.26 14C4.1 13.36 4 12.69 4 12s.1-1.36.26-2h3.38c-.08.66-.14 1.32-.14 2 0 .68.06 1.34.14 2H4.26zm.82 2h2.95c.32 1.25.78 2.45 1.38 3.56-1.84-.63-3.37-1.9-4.33-3.56zm2.95-8H5.08c.96-1.66 2.49-2.93 4.33-3.56C8.81 5.55 8.35 6.75 8.03 8zM12 19.96c-.83-1.2-1.48-2.53-1.91-3.96h3.82c-.43 1.43-1.08 2.76-1.91 3.96zM14.34 14H9.66c-.09-.66-.16-1.32-.16-2 0-.68.07-1.35.16-2h4.68c.09.65.16 1.32.16 2 0 .68-.07 1.34-.16 2zm.25 5.56c.6-1.11 1.06-2.31 1.38-3.56h2.95c-.96 1.65-2.49 2.93-4.33 3.56zM16.36 14c.08-.66.14-1.32.14-2 0-.68-.06-1.34-.14-2h3.38c.16.64.26 1.31.26 2s-.1 1.36-.26 2h-3.38z" + fill="currentColor" /> </svg> </button> <div class="_buttonContainer_f4f7a7" ❯ src/components/Header/Header.test.tsx:92:23
});
});
4 changes: 3 additions & 1 deletion packages/ui-react/src/components/Header/Header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ type Props = {
closeLanguageMenu: () => void;
children?: ReactNode;
isLoggedIn: boolean;
isPremium: boolean;
sideBarOpen: boolean;
userMenuOpen: boolean;
languageMenuOpen: boolean;
Expand Down Expand Up @@ -92,6 +93,7 @@ const Header: React.FC<Props> = ({
onCloseSearchButtonClick,
onSignUpButtonClick,
isLoggedIn,
isPremium,
sideBarOpen,
userMenuOpen,
languageMenuOpen,
Expand Down Expand Up @@ -154,7 +156,7 @@ const Header: React.FC<Props> = ({

// FEAT:: back to main account cta if oauth mode
if (isLoggedIn && isOAuthMode) {
return <OAuthBackToAccountButton targetUrl={env.APP_OAUTH_DASHBOARD_URL as string} className={styles.backToAccountButton} />;
return isPremium ? <OAuthBackToAccountButton targetUrl={env.APP_OAUTH_DASHBOARD_URL as string} className={styles.backToAccountButton} /> : null;
}

return isLoggedIn ? (
Expand Down
2 changes: 2 additions & 0 deletions packages/ui-react/src/containers/Layout/Layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ const Layout = () => {
);
const userMenuTitleId = useOpaqueId('usermenu-title');
const isLoggedIn = !!useAccountStore(({ user }) => user);
const isPremium = !!useAccountStore(({ user }) => user)?.isPremium;
const favoritesEnabled = !!config.features?.favoritesList;
const { menu, assets, siteName, description, features, styling, custom } = config;

Expand Down Expand Up @@ -228,6 +229,7 @@ const Layout = () => {
supportedLanguages={supportedLanguages}
currentLanguage={currentLanguage}
isLoggedIn={isLoggedIn}
isPremium={isPremium}
sideBarOpen={sideBarOpen}
userMenuOpen={userMenuOpen}
languageMenuOpen={languageMenuOpen}
Expand Down
16 changes: 16 additions & 0 deletions packages/ui-react/src/pages/RedirectToExternal/RedirectToSSO.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import React, { useEffect } from 'react';
import { useOAuth } from '@jwp/ott-hooks-react/src/useOAuth';
import { useNavigate } from 'react-router-dom';

const RedirectToSSO: React.FC = () => {
const navigate = useNavigate();
const { login: oAuthLogin } = useOAuth();

useEffect(() => {
oAuthLogin();
}, [navigate, oAuthLogin]);

return null; // Render nothing
};

export default RedirectToSSO;
2 changes: 2 additions & 0 deletions platforms/web/src/containers/AppRoutes/AppRoutes.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import Home from '@jwp/ott-ui-react/src/pages/Home/Home';
import Search from '@jwp/ott-ui-react/src/pages/Search/Search';
import User from '@jwp/ott-ui-react/src/pages/User/User';
import LegacySeries from '@jwp/ott-ui-react/src/pages/LegacySeries/LegacySeries';
import RedirectToSSO from '@jwp/ott-ui-react/src/pages/RedirectToExternal/RedirectToSSO';
import MediaScreenRouter from '@jwp/ott-ui-react/src/pages/ScreenRouting/MediaScreenRouter';
import PlaylistScreenRouter from '@jwp/ott-ui-react/src/pages/ScreenRouting/PlaylistScreenRouter';
import Layout from '@jwp/ott-ui-react/src/containers/Layout/Layout';
Expand Down Expand Up @@ -92,6 +93,7 @@ export default function AppRoutes() {
element={<ErrorPage title={t('notfound_error_heading', 'Not found')} message={t('notfound_error_description', "This page doesn't exist.")} />}
/>
</Route>
<Route path="/cxl-sso" element={<RedirectToSSO />} />
</Routes>
);
}
Loading