Skip to content

Commit

Permalink
Merge pull request #263 from GSM-MSG/262-add/prometheus-jwt-authoriza…
Browse files Browse the repository at this point in the history
…tion-script

🔀  :: golang를 사용한 accessToken 갱신 스크립트
  • Loading branch information
KimTaeO authored Feb 7, 2024
2 parents 046827f + 5ac618e commit ae6c1cc
Showing 1 changed file with 57 additions and 0 deletions.
57 changes: 57 additions & 0 deletions renew_jwt.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,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)
}
}

0 comments on commit ae6c1cc

Please sign in to comment.