Skip to content

Commit

Permalink
go mod v0.1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
chiuwah committed May 6, 2020
1 parent d147c0d commit eac43d6
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 43 deletions.
9 changes: 9 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
module github.com/chiuwah/fd_oauth-go

go 1.14

require (
github.com/chiuwah/fd_utils-go v0.1.0
github.com/federicoleon/golang-restclient v0.0.0-20191104170228-162ed620df66
github.com/stretchr/testify v1.5.1 // indirect
)
15 changes: 15 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
github.com/chiuwah/fd_utils-go v0.1.0 h1:6yN6HIOESTiiNWY5ZGd4ayS96OdHTxPVXnuM8VLWhPM=
github.com/chiuwah/fd_utils-go v0.1.0/go.mod h1:6Tbw5hgblKbNyMTeD0fhpmhGbwpm3pQLJ2oRxxa2DuM=
github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/federicoleon/golang-restclient v0.0.0-20191104170228-162ed620df66 h1:QESWlOIiziWcM4bCvtT7TFg4PXjudKMnO3ArjxuIJj4=
github.com/federicoleon/golang-restclient v0.0.0-20191104170228-162ed620df66/go.mod h1:lvjF6h5LrES4h39ha/njlBBBqCmISh6BNSEiXH+mT5k=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.5.1 h1:nOGnQDM7FYENwehXlg/kFVnos3rEvtKTjRvOWSzb6H4=
github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v2 v2.2.2 h1:ZCJp+EgiOT7lHqUV2J862kp8Qj64Jo6az82+3Td9dZw=
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
35 changes: 0 additions & 35 deletions oauth/errors/errors.go

This file was deleted.

16 changes: 8 additions & 8 deletions oauth/oauth.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package oauth
import (
"encoding/json"
"fmt"
"github.com/chiuwah/fd_oauth-go/oauth/errors"
"github.com/chiuwah/fd_utils-go/rest_errors"
"github.com/federicoleon/golang-restclient/rest"
"net/http"
"strconv"
Expand Down Expand Up @@ -61,14 +61,14 @@ func GetClientId(request *http.Request) int64 {
return clientId
}

func AuthenticateRequest(request *http.Request) *errors.RestErr {
func AuthenticateRequest(request *http.Request) *rest_errors.RestErr {
if request == nil {
return nil
}

cleanRequest(request)

accessTokenId := strings.TrimSpace(request.URL.Query().Get(paramAccessToken))
accessTokenId := strings.TrimSpace(request.URL. Query().Get(paramAccessToken))
if accessTokenId == "" {
return nil
}
Expand Down Expand Up @@ -96,22 +96,22 @@ func cleanRequest(request *http.Request) {

}

func getAccessToken(accessTokenId string) (*accessToken, *errors.RestErr) {
func getAccessToken(accessTokenId string) (*accessToken, *rest_errors.RestErr) {
response := oauthRestClient.Get(fmt.Sprintf("/oauth/access_token/%s", accessTokenId))

if response == nil || response.Response == nil {
return nil, errors.NewInternalServerError("invalid restclient response when trying to get access token")
return nil, rest_errors.NewInternalServerError("invalid restclient response when trying to get access token", rest_errors.NewError("invalid response"))
}
if response.StatusCode > 299 {
var restErr errors.RestErr
var restErr rest_errors.RestErr
if err := json.Unmarshal(response.Bytes(), &restErr); err != nil {
return nil, errors.NewInternalServerError("invalid error interface when trying to get access token")
return nil, rest_errors.NewInternalServerError("invalid error interface when trying to get access token", err)
}
return nil, &restErr
}
var at accessToken
if err := json.Unmarshal(response.Bytes(), &at); err != nil {
return nil, errors.NewInternalServerError("error when trying to unmarshal access token response")
return nil, rest_errors.NewInternalServerError("error when trying to unmarshal access token response", err)
}
return &at, nil
}

0 comments on commit eac43d6

Please sign in to comment.