summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJuan Roig <jaroig@outlook.com>2023-11-12 15:05:16 -0500
committerJuan Roig <jaroig@outlook.com>2023-11-12 15:05:16 -0500
commit78fd5e4e1f084b1f031c80c964f795e225f0d25a (patch)
tree411e145015f1cb69491c6403a90d5697acd1ffbe
parentaa816a646e43e44a43579e45228b28ad4ac92f57 (diff)
add cookie jar to allow cross site origin requests to carry cookies
-rw-r--r--go.mod2
-rw-r--r--go.sum2
-rw-r--r--main.go29
3 files changed, 28 insertions, 5 deletions
diff --git a/go.mod b/go.mod
index a5570a0..10fe00c 100644
--- a/go.mod
+++ b/go.mod
@@ -1,3 +1,5 @@
1module codeberg.org/flpolyaplus/aplus 1module codeberg.org/flpolyaplus/aplus
2 2
3go 1.21.3 3go 1.21.3
4
5require golang.org/x/net v0.18.0 // indirect
diff --git a/go.sum b/go.sum
index e69de29..ee9cb73 100644
--- a/go.sum
+++ b/go.sum
@@ -0,0 +1,2 @@
1golang.org/x/net v0.18.0 h1:mIYleuAkSbHh0tCv7RvjL3F6ZVbLjq4+R7zbOn3Kokg=
2golang.org/x/net v0.18.0/go.mod h1:/czyP5RqHAH4odGYxBJ1qz0+CE5WZ+2j1YgoEo8F2jQ=
diff --git a/main.go b/main.go
index 0480117..473b027 100644
--- a/main.go
+++ b/main.go
@@ -4,17 +4,28 @@ import (
4 "fmt" 4 "fmt"
5 "io" 5 "io"
6 "net/http" 6 "net/http"
7 "net/http/cookiejar"
8 "strings"
9
10 "golang.org/x/net/publicsuffix"
7) 11)
8 12
9var base_link string 13var base_link string
10var token string 14var token string
11 15
12func main() { 16func main() {
17
18 jar, _ := cookiejar.New(&cookiejar.Options{
19 PublicSuffixList: publicsuffix.List,
20 })
21
13 client := http.Client{ 22 client := http.Client{
14 CheckRedirect: func(req *http.Request, via []*http.Request) error { 23 CheckRedirect: func(req *http.Request, via []*http.Request) error {
15 fmt.Println("Redirected to:", req.URL) 24 fmt.Println("Redirected to:", req.URL)
25 fmt.Println(req.Cookies())
16 return nil 26 return nil
17 }, 27 },
28 Jar: jar,
18 } 29 }
19 30
20 initialize() 31 initialize()
@@ -43,23 +54,31 @@ func main() {
43 fmt.Printf("%s: %s\n", key, values) 54 fmt.Printf("%s: %s\n", key, values)
44 } 55 }
45 56
46 req, err := client.PostForm("https://floridapoly.aplusattendance.com/canvas", form_values) 57 //req, _ := client.PostForm("https://floridapoly.aplusattendance.com/canvas", form_values)
58 req, _ := http.NewRequest(http.MethodPost, "https://floridapoly.aplusattendance.com/canvas", strings.NewReader(form_values.Encode()))
59 req.Header.Set("Content-Type", "application/x-www-form-urlencoded")
60 req.Header.Set("Access-Control-Allow-Origin", "*")
61 req.Header.Set("Access-Control-Allow-Credentials", "true")
62 req.Header.Set("Access-Control-Allow-Headers", "Content-Type,access-control-allow-origin, access-control-allow-headers,access-control-allow-credentials")
63
64 resp, err = client.Do(req)
47 65
48 if err != nil { 66 if err != nil {
49 fmt.Println("Error posting form to Aplus Attendance.") 67 fmt.Println("Error posting form to Aplus Attendance.")
50 } 68 }
51 69
52 body, err = io.ReadAll(req.Body) 70 body, err = io.ReadAll(resp.Body)
53 71
54 if err != nil { 72 if err != nil {
55 fmt.Println("Error reading body of post form response from aplus attendance.") 73 fmt.Println("Error reading body of post form response from aplus attendance.")
56 } 74 }
57 75
58 fmt.Println(string(body)) 76 fmt.Println(string(body))
59 fmt.Println(req) 77 //fmt.Println(resp)
60 78 fmt.Println(resp.Header)
79 fmt.Println(resp.Cookies())
61 // we need to submit the above post request correctly in order to submit this request. 80 // we need to submit the above post request correctly in order to submit this request.
62 //resp, _ = client.Get("https://floridapoly.aplusattendance.com/canvas/student/?canvasCourse=7329&doStudentAuth=true") 81 //resp, _ = client.Get("https://floridapoly.aplusattendance.com/canvas/student/?canvasCourse=7329&amp;doStudentAuth=truee")
63 //body, _ = io.ReadAll(resp.Body) 82 //body, _ = io.ReadAll(resp.Body)
64 83
65 //fmt.Println(string(body)) 84 //fmt.Println(string(body))