1
1
from requests import Session
2
2
from bs4 import BeautifulSoup , Tag
3
3
import re
4
+ from typing import Any
4
5
5
6
import config
6
7
import totp
8
+ from helpers import send_request
7
9
8
10
9
11
def login_with_drexel_connect (session : Session ) -> Session :
10
- response = session .get (config .drexel_connect_base_url )
12
+ response = send_request (session , config .drexel_connect_base_url , method = "GET" )
13
+ assert response .status_code == 200 , "Failed to get Drexel Connect login page"
11
14
soup = BeautifulSoup (response .text , "html.parser" )
12
15
13
16
csrf_token = extract_csrf_token (soup )
@@ -21,26 +24,44 @@ def login_with_drexel_connect(session: Session) -> Session:
21
24
}
22
25
23
26
# this should send the credentials and send the MFA request
24
- response = session .post (
25
- config .drexel_connect_base_url + form_action_path , data = login_payload
27
+ response = send_request (
28
+ session ,
29
+ config .drexel_connect_base_url + form_action_path ,
30
+ data = login_payload ,
31
+ method = "POST" ,
26
32
)
33
+ assert (
34
+ response .status_code == 200
35
+ ), "Failed to send request to Drexel Connect with username and password"
27
36
28
37
soup = BeautifulSoup (response .text , "html.parser" )
29
38
data = parse_initial_mfa_page (soup )
30
39
31
- response = session .post (
32
- config .drexel_connect_base_url + data ["url" ], data = data ["form-data" ]
40
+ response = send_request (
41
+ session ,
42
+ config .drexel_connect_base_url + data ["url" ],
43
+ data = data ["form-data" ],
44
+ method = "POST" ,
33
45
)
46
+ assert (
47
+ response .status_code == 200
48
+ ), "Failed to request MFA code page from Drexel Connect"
34
49
json_response = response .json ()
35
50
36
51
data = {
37
52
json_response ["csrfN" ]: json_response ["csrfV" ],
38
53
"_eventId" : json_response ["actValue" ],
39
54
}
40
55
41
- response = session .post (
42
- config .drexel_connect_base_url + json_response ["flowExURL" ], data = data
56
+ response = send_request (
57
+ session ,
58
+ config .drexel_connect_base_url + json_response ["flowExURL" ],
59
+ data = data ,
60
+ method = "POST" ,
43
61
)
62
+ assert (
63
+ response .status_code == 200
64
+ ), "Failed to receive MFA code page from Drexel Connect"
44
65
soup = BeautifulSoup (response .text , "html.parser" )
45
66
46
67
parsed_data = parse_final_mfa_page (soup )
@@ -53,9 +74,15 @@ def login_with_drexel_connect(session: Session) -> Session:
53
74
"j_mfaToken" : totp_code ,
54
75
}
55
76
56
- response = session .post (
57
- config .drexel_connect_base_url + parsed_data ["url" ], data = data
77
+ response = send_request (
78
+ session ,
79
+ config .drexel_connect_base_url + parsed_data ["url" ],
80
+ data = data ,
81
+ method = "POST" ,
58
82
)
83
+ assert (
84
+ response .status_code == 200
85
+ ), "Failed to send MFA code to Drexel Connect (final step)"
59
86
60
87
return session
61
88
@@ -98,7 +125,7 @@ def extract_form_action_path(soup: BeautifulSoup) -> str:
98
125
return form_action_path
99
126
100
127
101
- def parse_initial_mfa_page (soup : BeautifulSoup ) -> dict [str , str ]:
128
+ def parse_initial_mfa_page (soup : BeautifulSoup ) -> dict [str , Any ]:
102
129
data = {}
103
130
104
131
# get the first script tag that isn't empty
0 commit comments