Skip to content

Commit

Permalink
feat: use a custom challenge since not checked in backend
Browse files Browse the repository at this point in the history
  • Loading branch information
Vexcited committed Aug 25, 2024
1 parent 37bc802 commit 2f7ebdb
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 12 deletions.
14 changes: 4 additions & 10 deletions src/models/Authenticator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,8 @@ export class Authenticator {
const params = new URLSearchParams();
params.set("user", username);

const START = "<input type=\"hidden\" name=\"";
const START_BETWEEN = "\" value=\"";
const END = "\" />";
const read = (name: string) => {
return findValueBetween(html, START + name + START_BETWEEN, END);
};

const challenge = read("challenge");
const pid = findValueBetween(html, "<input type=\"hidden\" name=\"pid\" value=\"", "\" />");
const challenge = "69".repeat(16);

let hashed_password = md5(password);
hashed_password = md5(username + ":" + hashed_password + ":" + challenge);
Expand All @@ -38,7 +32,7 @@ export class Authenticator {

params.set("submit", "VALIDER");
params.set("logintype", "login");
params.set("pid", read("pid"));
params.set("pid", pid);
params.set("redirect_url", "");
params.set("challenge", challenge);

Expand All @@ -55,7 +49,7 @@ export class Authenticator {
const cookies = getCookiesFromResponse(response);
this.check(cookies);

return Client.fromAPI(response.content, cookies);
return Client.fromAPI(response.content, cookies, pid);
}

/**
Expand Down
5 changes: 3 additions & 2 deletions src/models/Client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { findValueBetween } from "@literate.ink/utilities";

export class Client {
public constructor (
public pid: string,
public schoolID: string,
public schoolName: string,
public schoolImageURL: string,
Expand All @@ -15,11 +16,11 @@ export class Client {
return getOnlinePayments(this.schoolID, this.cookies);
}

public static fromAPI (html: string, cookies: string[]) {
public static fromAPI (html: string, cookies: string[] = [], pid = "") {
const schoolID = findValueBetween(html, ARD_BASE_ENDPOINT.slice(1) + "/", "/accueil.html");
const [schoolImagePath, , schoolName] = findValueBetween(html, "<img src=\"", "\" />").split("\"");
const schoolImageURL = ARD_HOST + "/" + schoolImagePath;

return new Client(schoolID, schoolName, schoolImageURL, cookies);
return new Client(pid, schoolID, schoolName, schoolImageURL, cookies);
}
}

0 comments on commit 2f7ebdb

Please sign in to comment.