|
1 | 1 | import { I18n } from '~/app/i18n';
|
2 | 2 | import { AuthLoggedAccount } from '~/framework/modules/auth/model';
|
3 | 3 | import { openUrl } from '~/framework/util/linking';
|
4 |
| -import { signedFetch } from '~/infra/fetchWithCache'; |
5 |
| - |
6 |
| -const profileMap = { |
7 |
| - PERSONNEL: 'direction', |
8 |
| - RELATIVE: 'parent', |
9 |
| - STUDENT: 'eleve', |
10 |
| - TEACHER: 'professeur', |
11 |
| -}; |
12 | 4 |
|
13 | 5 | const getRedirectUrl = (session: AuthLoggedAccount, connectorAddress: string, pageId?: string) => {
|
14 | 6 | const getSlash = (link: string) => {
|
15 | 7 | const service = decodeURIComponent(link);
|
16 | 8 | return service.charAt(service.length - 1) === '/' ? '' : '%2F';
|
17 | 9 | };
|
18 |
| - let link = `${session.platform.url}/cas/oauth/login?service=${encodeURIComponent(connectorAddress)}`; |
19 |
| - const role = profileMap[session.user.type.toUpperCase()]; |
20 |
| - // INTEG-1023: Not every PERSONNEL is a direction, so we don't add anything for them |
21 |
| - if (role !== profileMap.PERSONNEL) { |
22 |
| - link += `${getSlash(link)}mobile.${role}.html`; |
23 |
| - } |
| 10 | + let link = `${session.platform.url}/auth/redirect?url=${encodeURIComponent(connectorAddress)}`; |
| 11 | + |
| 12 | + link += `${getSlash(link)}mobile.html`; |
| 13 | + |
24 | 14 | if (pageId) {
|
25 | 15 | link += encodeURIComponent(`?page=${pageId}`);
|
26 | 16 | }
|
27 | 17 | return link;
|
28 | 18 | };
|
29 | 19 |
|
30 | 20 | export default async (session: AuthLoggedAccount, connectorAddress: string, pageId?: string, dryRun?: boolean) => {
|
31 |
| - const intermediateResponse = await signedFetch(getRedirectUrl(session, connectorAddress, pageId)); |
32 |
| - const finalUrl = intermediateResponse.headers.get('location'); |
| 21 | + const finalUrl = getRedirectUrl(session, connectorAddress, pageId); |
33 | 22 | if (dryRun) return finalUrl ?? undefined;
|
34 | 23 | openUrl(finalUrl ?? undefined, {
|
35 | 24 | error: I18n.get('pronote-redirect-error-message'),
|
|
0 commit comments