Skip to content

Commit

Permalink
Merge pull request #8 from oneee-playground/tidy
Browse files Browse the repository at this point in the history
Tidy
  • Loading branch information
onee-only authored Oct 23, 2024
2 parents da1b4b7 + 548b324 commit f655ad6
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 20 deletions.
30 changes: 12 additions & 18 deletions gauth.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,14 @@ package gauth
import (
"bytes"
"encoding/json"
"fmt"
"io"
"net/http"
"time"
)

const (
AuthURL = "https://server.gauth.co.kr"
ResourceURL = "https://open.gauth.co.kr"
AuthURL = "https://server-gauth.msg-team.com"
ResourceURL = "https://resource-gauth.msg-team.com"
)

const (
Expand Down Expand Up @@ -56,7 +55,6 @@ func NewDefaultClient(opts ClientOpts) *Client {

// IssueCode retrieves code with given email and password
func (c *Client) IssueCode(email, password string) (code string, err error) {

data, err := toJSON(issueCodeRequest{
Email: email,
Password: password,
Expand All @@ -65,12 +63,12 @@ func (c *Client) IssueCode(email, password string) (code string, err error) {
return "", err
}

r, err := http.NewRequest("POST", fmt.Sprint(AuthURL, "/oauth/code"), data)
req, err := http.NewRequest(http.MethodPost, AuthURL+"/oauth/code", data)
if err != nil {
return "", err
}

body, err := c.do(r)
body, err := c.do(req)
if err != nil {
return "", err
}
Expand All @@ -87,7 +85,6 @@ func (c *Client) IssueCode(email, password string) (code string, err error) {

// IssueToken retrieves access & refresh token with given code
func (c *Client) IssueToken(code string) (access, refresh string, err error) {

data, err := toJSON(issueTokenRequest{
Code: code,
ClientID: c.clientID,
Expand All @@ -99,12 +96,12 @@ func (c *Client) IssueToken(code string) (access, refresh string, err error) {
return "", "", err
}

r, err := http.NewRequest("POST", fmt.Sprint(AuthURL, "/oauth/token"), data)
req, err := http.NewRequest(http.MethodPost, AuthURL+"/oauth/token", data)
if err != nil {
return "", "", err
}

body, err := c.do(r)
body, err := c.do(req)
if err != nil {
return "", "", err
}
Expand All @@ -121,15 +118,14 @@ func (c *Client) IssueToken(code string) (access, refresh string, err error) {

// ReIssueToken retrieves access & refresh token with given refresh token
func (c *Client) ReIssueToken(refreshToken string) (access, refresh string, err error) {

r, err := http.NewRequest("PATCH", fmt.Sprint(AuthURL, "/oauth/token"), nil)
req, err := http.NewRequest(http.MethodPatch, AuthURL+"/oauth/token", nil)
if err != nil {
return "", "", err
}

r.Header.Set("refreshToken", fmt.Sprintf("Bearer %s", refreshToken))
req.Header.Set("refreshToken", "Bearer "+refreshToken)

body, err := c.do(r)
body, err := c.do(req)
if err != nil {
return "", "", err
}
Expand All @@ -146,15 +142,14 @@ func (c *Client) ReIssueToken(refreshToken string) (access, refresh string, err

// GetUserInfo retrieves userInfo with given access token
func (c *Client) GetUserInfo(accessToken string) (info UserInfo, err error) {

r, err := http.NewRequest("GET", fmt.Sprint(ResourceURL, "/user"), nil)
req, err := http.NewRequest(http.MethodGet, ResourceURL+"/user", nil)
if err != nil {
return UserInfo{}, err
}

r.Header.Set("Authorization", fmt.Sprintf("Bearer %s", accessToken))
req.Header.Set("Authorization", "Bearer "+accessToken)

body, err := c.do(r)
body, err := c.do(req)
if err != nil {
return UserInfo{}, err
}
Expand All @@ -170,7 +165,6 @@ func (c *Client) GetUserInfo(accessToken string) (info UserInfo, err error) {
}

func (c *Client) do(request *http.Request) (body io.ReadCloser, err error) {

request.Header.Set("Content-Type", "application/json")
res, err := c.httpClient.Do(request)
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion gauth_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"reflect"
"testing"

"github.com/onee-only/gauth-go"
"github.com/oneee-playground/gauth-go"
)

func TestGAuth(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module github.com/onee-only/gauth-go
module github.com/oneee-playground/gauth-go

go 1.20

0 comments on commit f655ad6

Please sign in to comment.