Skip to content

Commit c1856d1

Browse files
committed
chore: update constants
1 parent 93454b6 commit c1856d1

File tree

2 files changed

+32
-10
lines changed

2 files changed

+32
-10
lines changed

src/cas/constants.ts

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,19 @@
11
import type { ExternalClient } from "~cas/models";
22

3-
export const HOST = "https://cas.unilim.fr";
3+
// When internal server expires, we'll have to rollback to
4+
// export const HOST = "https://cas.unilim.fr";
5+
//
6+
// This is a workaround to bypass MFA: it hosts a `cloudflared` instance
7+
// in the internal servers of Unilim, thanks to `hosting.unilim.fr`
8+
// and exposes it to the following subdomain, managed by @Vexcited
9+
export const HOST = "https://cu-proxy.vexcited.com";
410

511
export const EXTERNAL_SERVICES = {
6-
COMMUNITIES_MOODLE: "https://communities.unilim.fr/login/index.php?authCAS=CAS",
12+
COMMUNITIES_MOODLE:
13+
"https://communities.unilim.fr/login/index.php?authCAS=CAS",
714
GRADING: "https://inscription.unilim.fr/gestion/etudiant/rvn/",
8-
IUT_COMMUNITY_MOODLE: "https://community-iut.unilim.fr/login/index.php?authCAS=CAS"
15+
IUT_COMMUNITY_MOODLE:
16+
"https://community-iut.unilim.fr/login/index.php?authCAS=CAS"
917
} as const;
1018

1119
export const EXTERNAL_CLIENTS = {
@@ -21,4 +29,3 @@ export const EXTERNAL_CLIENTS = {
2129
scopes: ["openid", "profile"]
2230
} satisfies ExternalClient
2331
} as const;
24-

src/cas/login.ts

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,25 @@
1-
import { defaultFetcher, type Fetcher, findValueBetween, getCookiesFromResponse } from "@literate.ink/utilities";
1+
import {
2+
defaultFetcher,
3+
type Fetcher,
4+
findValueBetween,
5+
getCookiesFromResponse
6+
} from "@literate.ink/utilities";
27
import { HOST } from "~cas/constants";
38

4-
const retrieveLoginToken = async (fetcher: Fetcher, retries = 0): Promise<string> => {
9+
const retrieveLoginToken = async (
10+
fetcher: Fetcher,
11+
retries = 0
12+
): Promise<string> => {
513
const response = await fetcher({
614
url: new URL(HOST)
715
});
816

917
// find the token that allows to send the login request.
10-
const token = findValueBetween(response.content, "name=\"token\" value=\"", "\" />");
18+
const token = findValueBetween(
19+
response.content,
20+
"name=\"token\" value=\"",
21+
"\" />"
22+
);
1123

1224
if (!token) {
1325
// we retry 5 times before throwing the actual error.
@@ -25,7 +37,11 @@ const retrieveLoginToken = async (fetcher: Fetcher, retries = 0): Promise<string
2537
* authenticates to `https://cas.unilim.fr` using the given `username` and `password`.
2638
* @returns the `lemonldap` cookie that is a token for further authenticated requests.
2739
*/
28-
export const login = async (username: string, password: string, fetcher: Fetcher = defaultFetcher): Promise<string> => {
40+
export const login = async (
41+
username: string,
42+
password: string,
43+
fetcher: Fetcher = defaultFetcher
44+
): Promise<string> => {
2945
const token = await retrieveLoginToken(fetcher);
3046

3147
// send the login request.
@@ -50,8 +66,7 @@ export const login = async (username: string, password: string, fetcher: Fetcher
5066
const cookies = getCookiesFromResponse(response);
5167
const lemonCookie = cookies[0].split("=")[1];
5268

53-
if (!lemonCookie)
54-
throw new Error("bad authentication");
69+
if (!lemonCookie) throw new Error("bad authentication");
5570

5671
return lemonCookie;
5772
};

0 commit comments

Comments
 (0)