summaryrefslogtreecommitdiff
path: root/main.go
blob: 27dc3fdd6b690192f6f66c9e6d7cad1fed20ec93 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
package main

import (
	"fmt"
	"io"
	"net/http"
	"os"
)

func main() {
	client := http.Client{
		CheckRedirect: func(req *http.Request, via []*http.Request) error {
			fmt.Println("Redirected to:", req.URL)
			return nil
		},
	}

	base_link := "https://floridapolytechnic.instructure.com/api/v1"
	token := os.Getenv("CANVAS_API_KEY")

	// select_course()

	aplus_link := fmt.Sprintf("%s/courses/%d/external_tools/sessionless_launch?id=913&access_token=%s", base_link, 7329, token) // 7329 always works
	aplus := get_aplus(token, aplus_link, client)
	fmt.Println(aplus)
	resp, err := client.Get(aplus)

	if err != nil {
		fmt.Println("Error while performing GET request to aplus auth link.")
	}

	defer resp.Body.Close()
	body, err := io.ReadAll(resp.Body)

	if err != nil {
		fmt.Println("Error reading body of initial aplus html response.")
	}

	form_str := get_form_from_request_body(body)
	fmt.Println(form_str)

	form_values := parse_form(form_str)

	fmt.Println("Form Values:")
	for key, values := range form_values {
		fmt.Printf("%s: %s\n", key, values)
	}

	req, err := client.PostForm("https://floridapoly.aplusattendance.com/canvas", form_values)

	if err != nil {
		fmt.Println("Error posting form to Aplus Attendance.")
	}

	body, err = io.ReadAll(req.Body)

	if err != nil {
		fmt.Println("Error reading body of post form response from aplus attendance.")
	}

	fmt.Println(string(body))
	fmt.Println(req)

	// 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)

	//fmt.Println(string(body))
	//fmt.Println(req)
}