-
Notifications
You must be signed in to change notification settings - Fork 1
/
renew_jwt.go
57 lines (44 loc) · 912 Bytes
/
renew_jwt.go
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
package main
import (
"bytes"
"encoding/json"
"io"
"net/http"
"os"
)
type User struct {
Email string `json:"email"`
Password string `json:"password"`
}
type Token struct {
AccessToken string `json:"accessToken"`
}
func main() {
client := &http.Client{}
url := os.Getenv("GAUTH_SERVER_URL")
user := User{
Email: os.Getenv("GAUTH_USER_NAME"),
Password: os.Getenv("GAUTH_PASSWORD"),
}
reqBody, _ := json.Marshal(user)
req, err := http.NewRequest("POST", url, bytes.NewBuffer(reqBody))
req.Header.Set("Content-Type", "application/json")
res, err := client.Do(req)
if err != nil {
panic(err)
}
defer res.Body.Close()
body, err := io.ReadAll(res.Body)
if err != nil {
panic(err)
}
var token Token
err = json.Unmarshal(body, &token)
if err != nil {
panic(err)
}
err = os.WriteFile("../jwt.txt", []byte(token.AccessToken), 0777)
if err != nil {
panic(err)
}
}