diff --git a/src/frontend/apps/lti_site/components/App/AppContentLoader/index.spec.tsx b/src/frontend/apps/lti_site/components/App/AppContentLoader/index.spec.tsx index 8bb821ae62..3e2aff4c74 100644 --- a/src/frontend/apps/lti_site/components/App/AppContentLoader/index.spec.tsx +++ b/src/frontend/apps/lti_site/components/App/AppContentLoader/index.spec.tsx @@ -41,7 +41,7 @@ describe('', () => { it('initialize current user before loading content', async () => { useJwt.setState({ - jwt: 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzZXNzaW9uX2lkIjoic29tZV9zZXNzaW9uX2lkIiwidXNlciI6eyJhbm9ueW1vdXNfaWQiOiJhbm9ueW1vdXMgaWQiLCJlbWFpbCI6InNvbWUgZW1haWwiLCJpZCI6ImlkIiwidXNlcm5hbWUiOiJ1c2VyIG5hbWUiLCJ1c2VyX2Z1bGxuYW1lIjoidXNlciBmdWxsIG5hbWUifSwibG9jYWxlIjoicGwiLCJtYWludGVuYW5jZSI6ZmFsc2UsInBlcm1pc3Npb25zIjp7ImNhbl9hY2Nlc3NfZGFzaGJvYXJkIjpmYWxzZSwiY2FuX3VwZGF0ZSI6ZmFsc2V9LCJyZXNvdXJjZV9pZCI6InJlc291cmNlIGlkIiwicm9sZXMiOltdfQ.gv0kmitQfOv93TQuFTHsiqQJFWeTkbmb1h8J8uMVX70', + jwt: 'ewogICJhbGciOiAiSFMyNTYiLAogICJ0eXAiOiAiSldUIgp9.ewogICJzZXNzaW9uX2lkIjogInNvbWVfc2Vzc2lvbl9pZCIsCiAgInVzZXIiOiB7CiAgICAiYW5vbnltb3VzX2lkIjogImFub255bW91cyBpZCIsCiAgICAiZW1haWwiOiAic29tZSBlbWFpbCIsCiAgICAiaWQiOiAiaWQiLAogICAgInVzZXJuYW1lIjogInVzZXIgbmFtZSIsCiAgICAidXNlcl9mdWxsbmFtZSI6ICJ1c2VyIGZ1bGwgbmFtZSIKICB9LAogICJsb2NhbGUiOiAicGwiLAogICJtYWludGVuYW5jZSI6IGZhbHNlLAogICJwZXJtaXNzaW9ucyI6IHsKICAgICJjYW5fYWNjZXNzX2Rhc2hib2FyZCI6IGZhbHNlLAogICAgImNhbl91cGRhdGUiOiBmYWxzZQogIH0sCiAgInBsYXlsaXN0X2lkIjogInBsYXlsaXN0IGlkIiwKICAicm9sZXMiOiBbXQp9.gv0kmitQfOv93TQuFTHsiqQJFWeTkbmb1h8J8uMVX70', }); const playlist = playlistMockFactory({ id: '488db2d0' }); diff --git a/src/frontend/apps/lti_site/components/App/AppContentLoader/index.tsx b/src/frontend/apps/lti_site/components/App/AppContentLoader/index.tsx index 823c12917f..43852d5140 100644 --- a/src/frontend/apps/lti_site/components/App/AppContentLoader/index.tsx +++ b/src/frontend/apps/lti_site/components/App/AppContentLoader/index.tsx @@ -115,6 +115,7 @@ const AppContent = () => { }; const AppContentLoader = () => { + const appData = useAppConfig(); const [isLoaded, setIsLoaded] = useState(false); const queryClient = new QueryClient(); @@ -141,10 +142,14 @@ const AppContentLoader = () => { }; if (decodedJwt) { - return { ...decodedJwt }; + return { + ...decodedJwt, + resource_id: appData.resource?.id || '', + playlist_id: (decodedJwt.port_to_playlist_id as string) || '', + }; } return defaultResourceContext; - }, [decodedJwt]); + }, [appData.resource?.id, decodedJwt]); useEffect(() => { const loadIntl = async () => { diff --git a/src/frontend/apps/lti_site/components/ClaimLink/index.spec.tsx b/src/frontend/apps/lti_site/components/ClaimLink/index.spec.tsx index b69b3e8368..0eb2c59657 100644 --- a/src/frontend/apps/lti_site/components/ClaimLink/index.spec.tsx +++ b/src/frontend/apps/lti_site/components/ClaimLink/index.spec.tsx @@ -66,8 +66,8 @@ describe('', () => { ', () => { 'Please login to manage this resource on http://localhost:8000/', ); expect(link.getAttribute('href')).toEqual( - 'http://localhost:8000//claim-resource?lti_consumer_site_id=32a1c2d0&resource_id=e8c0b8d0&modelName=videos&playlist_id=488db2d0<i_user_id=6b45a4d6', + `http://localhost:8000//claim-resource?lti_consumer_site_id=32a1c2d0&resource_id=${video.id}&modelName=videos&playlist_id=488db2d0<i_user_id=6b45a4d6`, ); expect(link.getAttribute('target')).toEqual('_blank'); expect(link.getAttribute('rel')).toEqual('noopener noreferrer'); @@ -135,8 +135,8 @@ describe('', () => { ', () => { { let claimUrl = `${appConfig.frontend_home_url}/claim-resource`; if (showClaimLink) { claimUrl += `?lti_consumer_site_id=${decodedJwt.consumer_site}`; - claimUrl += `&resource_id=${decodedJwt.resource_id}`; + claimUrl += `&resource_id=${resource.id}`; claimUrl += `&modelName=${appConfig.modelName}`; claimUrl += `&playlist_id=${resource.playlist.id}`; claimUrl += `<i_user_id=${decodedJwt.user?.id}`; diff --git a/src/frontend/apps/standalone_site/src/features/Authentication/hooks/useAuthenticator.spec.tsx b/src/frontend/apps/standalone_site/src/features/Authentication/hooks/useAuthenticator.spec.tsx index c4b91b17b2..4ea501c78c 100644 --- a/src/frontend/apps/standalone_site/src/features/Authentication/hooks/useAuthenticator.spec.tsx +++ b/src/frontend/apps/standalone_site/src/features/Authentication/hooks/useAuthenticator.spec.tsx @@ -177,7 +177,7 @@ describe('', () => { featureContentLoader([]); const classroom = classroomMockFactory(); const legacyInvite = - 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ0b2tlbl90eXBlIjoicmVzb3VyY2VfYWNjZXNzIiwiZXhwIjoxNjg5MjA2NDAwLCJpYXQiOjE2ODY1ODYwMzgsImp0aSI6ImNsYXNzcm9vbS1pbnZpdGUtMGJjZWIxZDItM2IxOS00NGI3LWE2NDctNGMxNTU2ZjU5MmZlLTIwMjMtMDYtMTIiLCJzZXNzaW9uX2lkIjoiMGJjZWIxZDItM2IxOS00NGI3LWE2NDctNGMxNTU2ZjU5MmZlLWludml0ZSIsInJlc291cmNlX2lkIjoiMGJjZWIxZDItM2IxOS00NGI3LWE2NDctNGMxNTU2ZjU5MmZlIiwicm9sZXMiOlsibm9uZSJdLCJsb2NhbGUiOiJlbl9VUyIsInBlcm1pc3Npb25zIjp7ImNhbl9hY2Nlc3NfZGFzaGJvYXJkIjpmYWxzZSwiY2FuX3VwZGF0ZSI6ZmFsc2V9LCJtYWludGVuYW5jZSI6ZmFsc2V9.68xSZYUAzrLD49pLkoOQy-ud7uaJVHgZ69zgkoW7umA'; + 'ewogICJhbGciOiAiSFMyNTYiLAogICJ0eXAiOiAiSldUIgp9.ewogICJ0b2tlbl90eXBlIjogInBsYXlsaXN0X2FjY2VzcyIsCiAgImV4cCI6IDE2ODkyMDY0MDAsCiAgImlhdCI6IDE2ODY1ODYwMzgsCiAgImp0aSI6ICJjbGFzc3Jvb20taW52aXRlLTBiY2ViMWQyLTNiMTktNDRiNy1hNjQ3LTRjMTU1NmY1OTJmZS0yMDIzLTA2LTEyIiwKICAic2Vzc2lvbl9pZCI6ICIwYmNlYjFkMi0zYjE5LTQ0YjctYTY0Ny00YzE1NTZmNTkyZmUtaW52aXRlIiwKICAicGxheWxpc3RfaWQiOiAiMGJjZWIxZDItM2IxOS00NGI3LWE2NDctNGMxNTU2ZjU5MmZlIiwKICAicm9sZXMiOiBbCiAgICAibm9uZSIKICBdLAogICJsb2NhbGUiOiAiZW5fVVMiLAogICJwZXJtaXNzaW9ucyI6IHsKICAgICJjYW5fYWNjZXNzX2Rhc2hib2FyZCI6IGZhbHNlLAogICAgImNhbl91cGRhdGUiOiBmYWxzZQogIH0sCiAgIm1haW50ZW5hbmNlIjogZmFsc2UKfQ.68xSZYUAzrLD49pLkoOQy-ud7uaJVHgZ69zgkoW7umA'; fetchMock.get('/api/users/whoami/', whoAmIResponse200); const { result } = renderHook(() => useAuthenticator(), { diff --git a/src/frontend/packages/lib_components/src/types/jwt.ts b/src/frontend/packages/lib_components/src/types/jwt.ts index 54a9ca8f24..76658b10bc 100644 --- a/src/frontend/packages/lib_components/src/types/jwt.ts +++ b/src/frontend/packages/lib_components/src/types/jwt.ts @@ -12,9 +12,10 @@ export interface DecodedJwtUser { export type DecodedJwt = DecodedJwtLTI | DecodedJwtWeb; -export interface DecodedJwtLTI extends ResourceContext { +export interface DecodedJwtLTI extends Omit { locale: string; maintenance: boolean; + port_to_playlist_id?: string; session_id: string; user?: DecodedJwtUser; } diff --git a/src/frontend/packages/lib_components/src/utils/checkToken.spec.ts b/src/frontend/packages/lib_components/src/utils/checkToken.spec.ts index 1bdf3ddbfa..ed1b758095 100644 --- a/src/frontend/packages/lib_components/src/utils/checkToken.spec.ts +++ b/src/frontend/packages/lib_components/src/utils/checkToken.spec.ts @@ -14,7 +14,7 @@ describe('checkToken', () => { can_access_dashboard: false, can_update: false, }, - resource_id: '26debfee-8c3b-4c23-b08f-67f223de9832', + playlist_id: '26debfee-8c3b-4c23-b08f-67f223de9832', roles: ['student'], session_id: '6bbb8d1d-442d-4575-a0ad-d1e34f37cae3', user: { @@ -36,7 +36,7 @@ describe('checkToken', () => { can_access_dashboard: false, can_update: false, }, - resource_id: '26debfee-8c3b-4c23-b08f-67f223de9832', + playlist_id: '26debfee-8c3b-4c23-b08f-67f223de9832', roles: ['student'], session_id: '6bbb8d1d-442d-4575-a0ad-d1e34f37cae3', user: { @@ -59,7 +59,7 @@ describe('checkToken', () => { can_access_dashboard: false, can_update: false, }, - resource_id: '26debfee-8c3b-4c23-b08f-67f223de9832', + playlist_id: '26debfee-8c3b-4c23-b08f-67f223de9832', roles: ['student'], session_id: '6bbb8d1d-442d-4575-a0ad-d1e34f37cae3', user: { @@ -83,7 +83,7 @@ describe('checkToken', () => { can_access_dashboard: false, can_update: false, }, - resource_id: '26debfee-8c3b-4c23-b08f-67f223de9832', + playlist_id: '26debfee-8c3b-4c23-b08f-67f223de9832', roles: ['student'], session_id: '6bbb8d1d-442d-4575-a0ad-d1e34f37cae3', }; diff --git a/src/frontend/packages/lib_components/src/utils/decodeJwt.spec.ts b/src/frontend/packages/lib_components/src/utils/decodeJwt.spec.ts index 2398ef1621..c60ef16af1 100644 --- a/src/frontend/packages/lib_components/src/utils/decodeJwt.spec.ts +++ b/src/frontend/packages/lib_components/src/utils/decodeJwt.spec.ts @@ -28,9 +28,9 @@ describe('decodeJwt', () => { // "sub": "1234567890", // "name": "John Doe", // "iat": 1516239022 - // "resource_id": "" + // "playlist_id": "" const jwt = - 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyLCJyZXNvdXJjZV9pZCI6IiJ9.2AAf0eZ75jFyAdREUMXr3CyOt9QPoqSuIZ5lNj3c7CE'; + 'ewogICJhbGciOiAiSFMyNTYiLAogICJ0eXAiOiAiSldUIgp9.ewogICJzdWIiOiAiMTIzNDU2Nzg5MCIsCiAgIm5hbWUiOiAiSm9obiBEb2UiLAogICJpYXQiOiAxNTE2MjM5MDIyLAogICJwbGF5bGlzdF9pZCI6ICIiCn0.2AAf0eZ75jFyAdREUMXr3CyOt9QPoqSuIZ5lNj3c7CE'; expect(() => { decodeJwt(jwt); @@ -41,13 +41,13 @@ describe('decodeJwt', () => { // "sub": "1234567890", // "name": "John Doe", // "iat": 1516239022, - // "resource_id": "2c85dc9e-4ee0-11ed-b9c1-635afde8841a" + // "playlist_id": "2c85dc9e-4ee0-11ed-b9c1-635afde8841a" const jwt = - 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyLCJyZXNvdXJjZV9pZCI6IjJjODVkYzllLTRlZTAtMTFlZC1iOWMxLTYzNWFmZGU4ODQxYSJ9.fQuKBTccQyt9fJGctJsLK5KL5lRisAGDZGFrBRdVPg8'; + 'ewogICJhbGciOiAiSFMyNTYiLAogICJ0eXAiOiAiSldUIgp9.ewogICJzdWIiOiAiMTIzNDU2Nzg5MCIsCiAgIm5hbWUiOiAiSm9obiBEb2UiLAogICJpYXQiOiAxNTE2MjM5MDIyLAogICJwbGF5bGlzdF9pZCI6ICIyYzg1ZGM5ZS00ZWUwLTExZWQtYjljMS02MzVhZmRlODg0MWEiCn0.fQuKBTccQyt9fJGctJsLK5KL5lRisAGDZGFrBRdVPg8'; const decodedJwt = decodeJwt(jwt); expect(isDecodedJwtLTI(decodedJwt)).toBeTruthy(); - expect((decodedJwt as DecodedJwtLTI).resource_id).toEqual( + expect((decodedJwt as DecodedJwtLTI).playlist_id).toEqual( '2c85dc9e-4ee0-11ed-b9c1-635afde8841a', ); }); @@ -56,16 +56,16 @@ describe('decodeJwt', () => { // "sub": "1234567890", // "name": "John Doe", // "iat": 1516239022, - // "resource_id": "", - // "playlist_id": "8cb4b9fa-4ee0-11ed-a972-87a03ecac56f", + // "playlist_id": "", + // "port_to_playlist_id": "8cb4b9fa-4ee0-11ed-a972-87a03ecac56f", // "user": {"id": "8d6d0ec4-4ee0-11ed-8d9b-97f53b688cde"} const jwt = - 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyLCJyZXNvdXJjZV9pZCI6IiIsInBsYXlsaXN0X2lkIjoiOGNiNGI5ZmEtNGVlMC0xMWVkLWE5NzItODdhMDNlY2FjNTZmIiwidXNlciI6eyJpZCI6IjhkNmQwZWM0LTRlZTAtMTFlZC04ZDliLTk3ZjUzYjY4OGNkZSJ9fQ._ha6x03gxBMYXPpofIAVDB3HBJXg0JRnmPUr2YPdG-A'; + 'ewogICJhbGciOiAiSFMyNTYiLAogICJ0eXAiOiAiSldUIgp9.ewogICJzdWIiOiAiMTIzNDU2Nzg5MCIsCiAgIm5hbWUiOiAiSm9obiBEb2UiLAogICJpYXQiOiAxNTE2MjM5MDIyLAogICJwbGF5bGlzdF9pZCI6ICIiLAogICJwb3J0X3RvX3BsYXlsaXN0X2lkIjogIjhjYjRiOWZhLTRlZTAtMTFlZC1hOTcyLTg3YTAzZWNhYzU2ZiIsCiAgInVzZXIiOiB7CiAgICAiaWQiOiAiOGQ2ZDBlYzQtNGVlMC0xMWVkLThkOWItOTdmNTNiNjg4Y2RlIgogIH0KfQ._ha6x03gxBMYXPpofIAVDB3HBJXg0JRnmPUr2YPdG-A'; const decodedJwt = decodeJwt(jwt); expect(isDecodedJwtLTI(decodedJwt)).toBeTruthy(); - expect((decodedJwt as DecodedJwtLTI).resource_id).toEqual(''); - expect((decodedJwt as DecodedJwtLTI).playlist_id).toEqual( + expect((decodedJwt as DecodedJwtLTI).playlist_id).toEqual(''); + expect((decodedJwt as DecodedJwtLTI).port_to_playlist_id).toEqual( '8cb4b9fa-4ee0-11ed-a972-87a03ecac56f', ); expect((decodedJwt as DecodedJwtLTI).user!.id).toEqual( diff --git a/src/frontend/packages/lib_components/src/utils/decodeJwt.ts b/src/frontend/packages/lib_components/src/utils/decodeJwt.ts index badd520e60..b17dccd886 100644 --- a/src/frontend/packages/lib_components/src/utils/decodeJwt.ts +++ b/src/frontend/packages/lib_components/src/utils/decodeJwt.ts @@ -8,14 +8,14 @@ import { export const isDecodedJwtLTI = (jwt: unknown): jwt is DecodedJwtLTI => { if (jwt && typeof jwt === 'object') { - const resourceId = (jwt as DecodedJwtLTI).resource_id; const playlistId = (jwt as DecodedJwtLTI).playlist_id; + const portToPlaylistId = (jwt as DecodedJwtLTI).port_to_playlist_id; const userId = (jwt as DecodedJwtLTI).user?.id; return ( // A resource is defined // Or we are in a portability request context and a playlist and user ID are mandatory - (!!resourceId && typeof resourceId === 'string') || - (!resourceId && !!playlistId && !!userId) + (!!playlistId && typeof playlistId === 'string') || + (!playlistId && !!portToPlaylistId && !!userId) ); } diff --git a/src/frontend/packages/lib_components/src/utils/tests/factories.ts b/src/frontend/packages/lib_components/src/utils/tests/factories.ts index 4077d78441..3a77cfca4a 100644 --- a/src/frontend/packages/lib_components/src/utils/tests/factories.ts +++ b/src/frontend/packages/lib_components/src/utils/tests/factories.ts @@ -296,7 +296,7 @@ export const ltiPublicTokenMockFactory = ( can_update: false, ...permission, }, - resource_id: faker.datatype.uuid(), + playlist_id: faker.datatype.uuid(), roles: ['none'], session_id: faker.datatype.uuid(), ...token, diff --git a/src/frontend/packages/lib_video/src/components/live/Student/StudentLiveStarter/StudentLiveAdvertising/StudentLiveRegistration/RegistrationForm/index.spec.tsx b/src/frontend/packages/lib_video/src/components/live/Student/StudentLiveStarter/StudentLiveAdvertising/StudentLiveRegistration/RegistrationForm/index.spec.tsx index db06d33895..aba881aec1 100644 --- a/src/frontend/packages/lib_video/src/components/live/Student/StudentLiveStarter/StudentLiveAdvertising/StudentLiveRegistration/RegistrationForm/index.spec.tsx +++ b/src/frontend/packages/lib_video/src/components/live/Student/StudentLiveStarter/StudentLiveAdvertising/StudentLiveRegistration/RegistrationForm/index.spec.tsx @@ -51,7 +51,7 @@ describe('', () => { can_access_dashboard: false, can_update: false, }, - resource_id: 'resource id', + playlist_id: 'playlist id', roles: ['student'], session_id: 'session id', user: { @@ -121,7 +121,7 @@ describe('', () => { can_access_dashboard: false, can_update: false, }, - resource_id: 'resource id', + playlist_id: 'playlist_id', roles: ['student'], session_id: 'session id', user: { diff --git a/src/frontend/packages/lib_video/src/components/live/Student/StudentLiveStarter/StudentLiveAdvertising/StudentLiveRegistration/index.spec.tsx b/src/frontend/packages/lib_video/src/components/live/Student/StudentLiveStarter/StudentLiveAdvertising/StudentLiveRegistration/index.spec.tsx index b541d4146c..58e9aa52e0 100644 --- a/src/frontend/packages/lib_video/src/components/live/Student/StudentLiveStarter/StudentLiveAdvertising/StudentLiveRegistration/index.spec.tsx +++ b/src/frontend/packages/lib_video/src/components/live/Student/StudentLiveStarter/StudentLiveAdvertising/StudentLiveRegistration/index.spec.tsx @@ -62,7 +62,7 @@ describe('', () => { can_access_dashboard: false, can_update: false, }, - resource_id: 'ressource_id', + playlist_id: 'playlist_id', roles: [], session_id: 'session_id', user: { @@ -254,7 +254,7 @@ describe('', () => { can_access_dashboard: false, can_update: false, }, - resource_id: 'ressource_id', + playlist_id: 'playlist_id', roles: [], session_id: 'session_id', user: undefined, diff --git a/src/frontend/packages/lib_video/src/components/live/Student/StudentLiveStarter/StudentLiveAdvertising/index.spec.tsx b/src/frontend/packages/lib_video/src/components/live/Student/StudentLiveStarter/StudentLiveAdvertising/index.spec.tsx index 94d61c8dfb..8b130fde28 100644 --- a/src/frontend/packages/lib_video/src/components/live/Student/StudentLiveStarter/StudentLiveAdvertising/index.spec.tsx +++ b/src/frontend/packages/lib_video/src/components/live/Student/StudentLiveStarter/StudentLiveAdvertising/index.spec.tsx @@ -40,7 +40,7 @@ jest.mock('lib-components', () => ({ can_access_dashboard: false, can_update: false, }, - resource_id: 'ressource_id', + playlist_id: 'playlist_id', roles: [], session_id: 'session_id', user: { diff --git a/src/frontend/packages/lib_video/src/utils/getOrInitAnonymousId.spec.ts b/src/frontend/packages/lib_video/src/utils/getOrInitAnonymousId.spec.ts index e0d8a37644..96a2b033fc 100644 --- a/src/frontend/packages/lib_video/src/utils/getOrInitAnonymousId.spec.ts +++ b/src/frontend/packages/lib_video/src/utils/getOrInitAnonymousId.spec.ts @@ -1,4 +1,9 @@ -import { decodeJwt, useCurrentUser, useJwt } from 'lib-components'; +import { + DecodedJwtLTI, + decodeJwt, + useCurrentUser, + useJwt, +} from 'lib-components'; import { v4 as uuidv4 } from 'uuid'; import { getOrInitAnonymousId } from './getOrInitAnonymousId'; @@ -34,7 +39,7 @@ const webToken = { user_id: '1324', }; -const ltiToken = { +const ltiToken: DecodedJwtLTI = { context_id: 'course-v1:ufr+mathematics+0001', consumer_site: '112cf553-b8c3-4b98-9d47-d0793284b9b3', locale: 'en_US', @@ -43,7 +48,7 @@ const ltiToken = { can_access_dashboard: false, can_update: false, }, - resource_id: '26debfee-8c3b-4c23-b08f-67f223de9832', + playlist_id: '26debfee-8c3b-4c23-b08f-67f223de9832', roles: ['student'], session_id: '6bbb8d1d-442d-4575-a0ad-d1e34f37cae3', user: {