2023-10-27 19:02:38 -04:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"io"
|
|
|
|
"net/http"
|
2023-11-04 01:55:30 -04:00
|
|
|
"os"
|
2023-10-27 19:02:38 -04:00
|
|
|
)
|
|
|
|
|
|
|
|
func main() {
|
2023-10-30 01:00:50 -04:00
|
|
|
client := http.Client{
|
|
|
|
CheckRedirect: func(req *http.Request, via []*http.Request) error {
|
|
|
|
fmt.Println("Redirected to:", req.URL)
|
|
|
|
return nil
|
|
|
|
},
|
|
|
|
}
|
2023-10-27 19:02:38 -04:00
|
|
|
|
|
|
|
base_link := "https://floridapolytechnic.instructure.com/api/v1"
|
2023-11-04 01:55:30 -04:00
|
|
|
token := os.Getenv("CANVAS_API_KEY")
|
|
|
|
|
|
|
|
// select_course()
|
2023-10-30 17:58:38 -04:00
|
|
|
|
2023-10-27 19:02:38 -04:00
|
|
|
aplus_link := fmt.Sprintf("%s/courses/%d/external_tools/sessionless_launch?id=913&access_token=%s", base_link, 7329, token) // 7329 always works
|
2023-11-04 01:55:30 -04:00
|
|
|
aplus := get_aplus(token, aplus_link, client)
|
2023-10-27 19:02:38 -04:00
|
|
|
fmt.Println(aplus)
|
2023-10-30 01:00:50 -04:00
|
|
|
resp, err := client.Get(aplus)
|
2023-10-27 19:02:38 -04:00
|
|
|
|
|
|
|
if err != nil {
|
2023-11-04 01:55:30 -04:00
|
|
|
fmt.Println("Error while performing GET request to aplus auth link.")
|
2023-10-27 19:02:38 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
defer resp.Body.Close()
|
2023-10-30 17:58:38 -04:00
|
|
|
body, err := io.ReadAll(resp.Body)
|
2023-10-30 01:00:50 -04:00
|
|
|
|
2023-10-30 17:58:38 -04:00
|
|
|
if err != nil {
|
2023-11-04 01:55:30 -04:00
|
|
|
fmt.Println("Error reading body of initial aplus html response.")
|
2023-10-30 17:58:38 -04:00
|
|
|
}
|
|
|
|
|
2023-11-04 01:55:30 -04:00
|
|
|
form_str := get_form_from_request_body(body)
|
|
|
|
fmt.Println(form_str)
|
2023-10-30 17:58:38 -04:00
|
|
|
|
2023-11-04 01:55:30 -04:00
|
|
|
form_values := parse_form(form_str)
|
2023-10-31 02:06:01 -04:00
|
|
|
|
|
|
|
fmt.Println("Form Values:")
|
|
|
|
for key, values := range form_values {
|
|
|
|
fmt.Printf("%s: %s\n", key, values)
|
|
|
|
}
|
2023-10-31 02:30:30 -04:00
|
|
|
|
|
|
|
req, err := client.PostForm("https://floridapoly.aplusattendance.com/canvas", form_values)
|
2023-10-30 17:58:38 -04:00
|
|
|
|
2023-11-04 01:55:30 -04:00
|
|
|
if err != nil {
|
|
|
|
fmt.Println("Error posting form to Aplus Attendance.")
|
2023-10-30 17:58:38 -04:00
|
|
|
}
|
|
|
|
|
2023-11-04 01:55:30 -04:00
|
|
|
body, err = io.ReadAll(req.Body)
|
2023-10-30 17:58:38 -04:00
|
|
|
|
|
|
|
if err != nil {
|
2023-11-04 01:55:30 -04:00
|
|
|
fmt.Println("Error reading body of post form response from aplus attendance.")
|
2023-10-30 17:58:38 -04:00
|
|
|
}
|
|
|
|
|
2023-11-04 01:55:30 -04:00
|
|
|
fmt.Println(string(body))
|
|
|
|
fmt.Println(req)
|
2023-10-30 17:58:38 -04:00
|
|
|
|
2023-11-04 01:55:30 -04:00
|
|
|
// we need to submit the above post request correctly in order to submit this request.
|
|
|
|
//resp, err = client.Get("https://floridapoly.aplusattendance.com/canvas/student/?canvasCourse=7329&doStudentAuth=true")
|
|
|
|
//body, err = io.ReadAll(req.Body)
|
2023-10-30 17:58:38 -04:00
|
|
|
|
2023-11-04 01:55:30 -04:00
|
|
|
//fmt.Println(string(body))
|
|
|
|
//fmt.Println(req)
|
|
|
|
}
|