reddy-api-srm 1.0.9 → 1.0.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -1,9 +1,40 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.validatePassword = validatePassword;
|
|
4
|
+
async function getSigninSessionHeaders() {
|
|
5
|
+
const signinUrl = "https://academia.srmist.edu.in/accounts/p/40-10002227248/signin?hide_fp=true&servicename=ZohoCreator&service_language=en&dcc=true&serviceurl=https%3A%2F%2Facademia.srmist.edu.in%2Fportal%2Facademia-academic-services%2FredirectFromLogin";
|
|
6
|
+
const seedRes = await fetch(signinUrl, {
|
|
7
|
+
method: "GET",
|
|
8
|
+
redirect: "manual",
|
|
9
|
+
headers: {
|
|
10
|
+
accept: "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8",
|
|
11
|
+
"accept-language": "en-US,en;q=0.9",
|
|
12
|
+
},
|
|
13
|
+
});
|
|
14
|
+
const setCookieHeaders = (typeof seedRes.headers.getSetCookie === "function"
|
|
15
|
+
? seedRes.headers.getSetCookie()
|
|
16
|
+
: [seedRes.headers.get("set-cookie")].filter(Boolean));
|
|
17
|
+
const cookiePairs = [];
|
|
18
|
+
let csrfToken = null;
|
|
19
|
+
for (const header of setCookieHeaders) {
|
|
20
|
+
const pair = header.split(";")[0]?.trim();
|
|
21
|
+
if (!pair || !pair.includes("="))
|
|
22
|
+
continue;
|
|
23
|
+
cookiePairs.push(pair);
|
|
24
|
+
if (pair.startsWith("iamcsr="))
|
|
25
|
+
csrfToken = pair.slice("iamcsr=".length);
|
|
26
|
+
if (!csrfToken && pair.startsWith("_zcsr_tmp="))
|
|
27
|
+
csrfToken = pair.slice("_zcsr_tmp=".length);
|
|
28
|
+
}
|
|
29
|
+
return {
|
|
30
|
+
cookie: cookiePairs.join("; "),
|
|
31
|
+
csrfToken,
|
|
32
|
+
};
|
|
33
|
+
}
|
|
4
34
|
async function validatePassword({ identifier, digest, password, }) {
|
|
5
35
|
let res;
|
|
6
36
|
try {
|
|
37
|
+
const seed = await getSigninSessionHeaders();
|
|
7
38
|
res = await fetch(`https://academia.srmist.edu.in/accounts/p/40-10002227248/signin/v2/primary/${identifier}/password?digest=${digest}&cli_time=${Date.now()}&servicename=ZohoCreator&service_language=en&serviceurl=https%3A%2F%2Facademia.srmist.edu.in%2Fportal%2Facademia-academic-services%2FredirectFromLogin`, {
|
|
8
39
|
headers: {
|
|
9
40
|
accept: "*/*",
|
|
@@ -12,12 +43,25 @@ async function validatePassword({ identifier, digest, password, }) {
|
|
|
12
43
|
"sec-fetch-dest": "empty",
|
|
13
44
|
"sec-fetch-mode": "cors",
|
|
14
45
|
"sec-fetch-site": "same-origin",
|
|
46
|
+
...(seed.csrfToken ? { "x-zcsrf-token": `iamcsrcoo=${seed.csrfToken}` } : {}),
|
|
47
|
+
...(seed.cookie ? { cookie: seed.cookie } : {}),
|
|
15
48
|
Referer: "https://academia.srmist.edu.in/accounts/p/40-10002227248/signin?hide_fp=true&servicename=ZohoCreator&service_language=en&dcc=true&serviceurl=https%3A%2F%2Facademia.srmist.edu.in%2Fportal%2Facademia-academic-services%2FredirectFromLogin",
|
|
16
49
|
"Referrer-Policy": "strict-origin-when-cross-origin",
|
|
17
50
|
},
|
|
18
51
|
body: `{"passwordauth":{"password":"${password}"}}`,
|
|
19
52
|
method: "POST",
|
|
53
|
+
redirect: "manual",
|
|
20
54
|
});
|
|
55
|
+
const location = res.headers.get("location") ?? "";
|
|
56
|
+
if ([301, 302, 303, 307, 308].includes(res.status) && location.includes("sessions-reminder")) {
|
|
57
|
+
let flowId = null;
|
|
58
|
+
try {
|
|
59
|
+
const u = new URL(location, "https://academia.srmist.edu.in");
|
|
60
|
+
flowId = u.searchParams.get("flowId") ?? u.searchParams.get("flow_id") ?? null;
|
|
61
|
+
}
|
|
62
|
+
catch (_) { }
|
|
63
|
+
return { data: { statusCode: 435, message: "Maximum concurrent sessions reached. Please terminate existing sessions to continue.", captcha: { required: false, digest: null }, isConcurrentLimit: true, flowId }, isAuthenticated: false };
|
|
64
|
+
}
|
|
21
65
|
// ── Detect redirect to Zoho sessions-reminder page ───────────────────────
|
|
22
66
|
if (res.redirected && res.url && res.url.includes("sessions-reminder")) {
|
|
23
67
|
let flowId = null;
|
|
@@ -36,7 +80,7 @@ async function validatePassword({ identifier, digest, password, }) {
|
|
|
36
80
|
}
|
|
37
81
|
return { error: "Internal Server Error", errorReason: new Error("Non-JSON response from login endpoint") };
|
|
38
82
|
}
|
|
39
|
-
if (response.status_code === 201) {
|
|
83
|
+
if (response.status_code === 201 || response.status_code === 200) {
|
|
40
84
|
const setCookieHeaders = (typeof res.headers.getSetCookie === "function"
|
|
41
85
|
? res.headers.getSetCookie()
|
|
42
86
|
: [res.headers.get("set-cookie")].filter(Boolean));
|
|
@@ -49,10 +93,29 @@ async function validatePassword({ identifier, digest, password, }) {
|
|
|
49
93
|
const extractedCookies = matches.map((m) => m[0]).join("; ") + ";";
|
|
50
94
|
const data = {
|
|
51
95
|
cookies: extractedCookies,
|
|
52
|
-
statusCode:
|
|
96
|
+
statusCode: response.status_code,
|
|
53
97
|
};
|
|
54
98
|
return { data, isAuthenticated: true };
|
|
55
99
|
}
|
|
100
|
+
if ([301, 302, 303, 307, 308].includes(res.status) &&
|
|
101
|
+
(location.includes("redirectFromLogin") || location.includes("/portal/academia-academic-services"))) {
|
|
102
|
+
const setCookieHeaders = (typeof res.headers.getSetCookie === "function"
|
|
103
|
+
? res.headers.getSetCookie()
|
|
104
|
+
: [res.headers.get("set-cookie")].filter(Boolean));
|
|
105
|
+
const combinedCookieHeader = setCookieHeaders.join("; ");
|
|
106
|
+
const matches = [
|
|
107
|
+
...combinedCookieHeader.matchAll(/(_(?:iamadt|iambdt)_client_\d+|_z_identity)=[^;]+/g),
|
|
108
|
+
];
|
|
109
|
+
if (matches.length > 0) {
|
|
110
|
+
return {
|
|
111
|
+
data: {
|
|
112
|
+
cookies: matches.map((m) => m[0]).join("; ") + ";",
|
|
113
|
+
statusCode: 201,
|
|
114
|
+
},
|
|
115
|
+
isAuthenticated: true,
|
|
116
|
+
};
|
|
117
|
+
}
|
|
118
|
+
}
|
|
56
119
|
// ── Concurrent / device-limit detection ──────────────────────────────────
|
|
57
120
|
const msg = (response.localized_message ?? response.message ?? "").toLowerCase();
|
|
58
121
|
const isConcurrentLimit =
|
|
@@ -1,8 +1,39 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.validateUser = validateUser;
|
|
4
|
+
async function getSigninSessionHeaders() {
|
|
5
|
+
const signinUrl = "https://academia.srmist.edu.in/accounts/p/40-10002227248/signin?hide_fp=true&servicename=ZohoCreator&service_language=en&dcc=true&serviceurl=https%3A%2F%2Facademia.srmist.edu.in%2Fportal%2Facademia-academic-services%2FredirectFromLogin";
|
|
6
|
+
const seedRes = await fetch(signinUrl, {
|
|
7
|
+
method: "GET",
|
|
8
|
+
redirect: "manual",
|
|
9
|
+
headers: {
|
|
10
|
+
accept: "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8",
|
|
11
|
+
"accept-language": "en-US,en;q=0.9",
|
|
12
|
+
},
|
|
13
|
+
});
|
|
14
|
+
const setCookieHeaders = (typeof seedRes.headers.getSetCookie === "function"
|
|
15
|
+
? seedRes.headers.getSetCookie()
|
|
16
|
+
: [seedRes.headers.get("set-cookie")].filter(Boolean));
|
|
17
|
+
const cookiePairs = [];
|
|
18
|
+
let csrfToken = null;
|
|
19
|
+
for (const header of setCookieHeaders) {
|
|
20
|
+
const pair = header.split(";")[0]?.trim();
|
|
21
|
+
if (!pair || !pair.includes("="))
|
|
22
|
+
continue;
|
|
23
|
+
cookiePairs.push(pair);
|
|
24
|
+
if (pair.startsWith("iamcsr="))
|
|
25
|
+
csrfToken = pair.slice("iamcsr=".length);
|
|
26
|
+
if (!csrfToken && pair.startsWith("_zcsr_tmp="))
|
|
27
|
+
csrfToken = pair.slice("_zcsr_tmp=".length);
|
|
28
|
+
}
|
|
29
|
+
return {
|
|
30
|
+
cookie: cookiePairs.join("; "),
|
|
31
|
+
csrfToken,
|
|
32
|
+
};
|
|
33
|
+
}
|
|
4
34
|
async function validateUser(username) {
|
|
5
35
|
try {
|
|
36
|
+
const seed = await getSigninSessionHeaders();
|
|
6
37
|
const res = await fetch(`https://academia.srmist.edu.in/accounts/p/40-10002227248/signin/v2/lookup/${username}`, {
|
|
7
38
|
headers: {
|
|
8
39
|
accept: "*/*",
|
|
@@ -11,6 +42,8 @@ async function validateUser(username) {
|
|
|
11
42
|
"sec-fetch-dest": "empty",
|
|
12
43
|
"sec-fetch-mode": "cors",
|
|
13
44
|
"sec-fetch-site": "same-origin",
|
|
45
|
+
...(seed.csrfToken ? { "x-zcsrf-token": `iamcsrcoo=${seed.csrfToken}` } : {}),
|
|
46
|
+
...(seed.cookie ? { cookie: seed.cookie } : {}),
|
|
14
47
|
Referer: "https://academia.srmist.edu.in/accounts/p/40-10002227248/signin?hide_fp=true&servicename=ZohoCreator&service_language=en&dcc=true&serviceurl=https%3A%2F%2Facademia.srmist.edu.in%2Fportal%2Facademia-academic-services%2FredirectFromLogin",
|
|
15
48
|
"Referrer-Policy": "strict-origin-when-cross-origin",
|
|
16
49
|
},
|
|
@@ -27,7 +60,6 @@ async function validateUser(username) {
|
|
|
27
60
|
return { data };
|
|
28
61
|
}
|
|
29
62
|
catch (e) {
|
|
30
|
-
console.error(e);
|
|
31
63
|
return {
|
|
32
64
|
error: "Internal Server Error",
|
|
33
65
|
errorReason: e,
|