Skip to content

Commit

Permalink
Modify module path to github.com/go-oauth2/oauth2/v4
Browse files Browse the repository at this point in the history
  • Loading branch information
LyricTian committed Jun 30, 2020
1 parent a6ff933 commit a156fbe
Show file tree
Hide file tree
Showing 29 changed files with 119 additions and 210 deletions.
4 changes: 2 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
language: go
sudo: false
go_import_path: gopkg.in/oauth2.v4
go_import_path: github.com/go-oauth2/oauth2/v4
go:
- 1.9
- 1.13
before_install:
- go get -t -v ./...

Expand Down
22 changes: 11 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
### Download and install

``` bash
go get -u -v gopkg.in/oauth2.v4/...
go get -u -v github.com/go-oauth2/oauth2/v4/...
```

### Create file `server.go`
Expand All @@ -43,11 +43,11 @@ import (
"log"
"net/http"

"gopkg.in/oauth2.v4/errors"
"gopkg.in/oauth2.v4/manage"
"gopkg.in/oauth2.v4/models"
"gopkg.in/oauth2.v4/server"
"gopkg.in/oauth2.v4/store"
"github.com/go-oauth2/oauth2/v4/errors"
"github.com/go-oauth2/oauth2/v4/manage"
"github.com/go-oauth2/oauth2/v4/models"
"github.com/go-oauth2/oauth2/v4/server"
"github.com/go-oauth2/oauth2/v4/store"
)

func main() {
Expand Down Expand Up @@ -135,7 +135,7 @@ Simulation examples of authorization code model, please check [example](/example
```go

import (
"gopkg.in/oauth2.v4/generates"
"github.com/go-oauth2/oauth2/v4/generates"
"github.com/dgrijalva/jwt-go"
)

Expand Down Expand Up @@ -180,9 +180,9 @@ if !ok || !token.Valid {
[Build-Status-Image]: https://travis-ci.org/go-oauth2/oauth2.svg?branch=master
[codecov-url]: https://codecov.io/gh/go-oauth2/oauth2
[codecov-image]: https://codecov.io/gh/go-oauth2/oauth2/branch/master/graph/badge.svg
[reportcard-url]: https://goreportcard.com/report/gopkg.in/oauth2.v4
[reportcard-image]: https://goreportcard.com/badge/gopkg.in/oauth2.v4
[godoc-url]: https://godoc.org/gopkg.in/oauth2.v4
[godoc-image]: https://godoc.org/gopkg.in/oauth2.v4?status.svg
[reportcard-url]: https://goreportcard.com/report/github.com/go-oauth2/oauth2/v4
[reportcard-image]: https://goreportcard.com/badge/github.com/go-oauth2/oauth2/v4
[godoc-url]: https://godoc.org/github.com/go-oauth2/oauth2/v4
[godoc-image]: https://godoc.org/github.com/go-oauth2/oauth2/v4?status.svg
[license-url]: http://opensource.org/licenses/MIT
[license-image]: https://img.shields.io/npm/l/express.svg
6 changes: 3 additions & 3 deletions doc.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
// package main
// import (
// "net/http"
// "gopkg.in/oauth2.v4/manage"
// "gopkg.in/oauth2.v4/server"
// "gopkg.in/oauth2.v4/store"
// "github.com/go-oauth2/oauth2/v4/manage"
// "github.com/go-oauth2/oauth2/v4/server"
// "github.com/go-oauth2/oauth2/v4/store"
// )
// func main() {
// manager := manage.NewDefaultManager()
Expand Down
3 changes: 3 additions & 0 deletions errors/error.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ package errors

import "errors"

// New returns an error that formats as the given text.
var New = errors.New

// known errors
var (
ErrInvalidRedirectURI = errors.New("invalid redirect uri")
Expand Down
5 changes: 0 additions & 5 deletions errors/response.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,6 @@ import (
"net/http"
)

// Define alias
var (
New = errors.New
)

// Response error response
type Response struct {
Error error
Expand Down
12 changes: 6 additions & 6 deletions example/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@ import (
"time"

"github.com/dgrijalva/jwt-go"
"github.com/go-oauth2/oauth2/v4/errors"
"github.com/go-oauth2/oauth2/v4/generates"
"github.com/go-oauth2/oauth2/v4/manage"
"github.com/go-oauth2/oauth2/v4/models"
"github.com/go-oauth2/oauth2/v4/server"
"github.com/go-oauth2/oauth2/v4/store"
"github.com/go-session/session"
"gopkg.in/oauth2.v4/errors"
"gopkg.in/oauth2.v4/generates"
"gopkg.in/oauth2.v4/manage"
"gopkg.in/oauth2.v4/models"
"gopkg.in/oauth2.v4/server"
"gopkg.in/oauth2.v4/store"
)

func main() {
Expand Down
8 changes: 4 additions & 4 deletions generates/access.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import (
"strconv"
"strings"

"gopkg.in/oauth2.v4"
"gopkg.in/oauth2.v4/utils/uuid"
"github.com/go-oauth2/oauth2/v4"
"github.com/google/uuid"
)

// NewAccessGenerate create to generate the access token instance
Expand All @@ -26,11 +26,11 @@ func (ag *AccessGenerate) Token(ctx context.Context, data *oauth2.GenerateBasic,
buf.WriteString(data.UserID)
buf.WriteString(strconv.FormatInt(data.CreateAt.UnixNano(), 10))

access := base64.URLEncoding.EncodeToString(uuid.NewMD5(uuid.Must(uuid.NewRandom()), buf.Bytes()).Bytes())
access := base64.URLEncoding.EncodeToString([]byte(uuid.NewMD5(uuid.Must(uuid.NewRandom()), buf.Bytes()).String()))
access = strings.ToUpper(strings.TrimRight(access, "="))
refresh := ""
if isGenRefresh {
refresh = base64.URLEncoding.EncodeToString(uuid.NewSHA1(uuid.Must(uuid.NewRandom()), buf.Bytes()).Bytes())
refresh = base64.URLEncoding.EncodeToString([]byte(uuid.NewSHA1(uuid.Must(uuid.NewRandom()), buf.Bytes()).String()))
refresh = strings.ToUpper(strings.TrimRight(refresh, "="))
}

Expand Down
6 changes: 3 additions & 3 deletions generates/access_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ import (
"testing"
"time"

"gopkg.in/oauth2.v4"
"gopkg.in/oauth2.v4/generates"
"gopkg.in/oauth2.v4/models"
"github.com/go-oauth2/oauth2/v4"
"github.com/go-oauth2/oauth2/v4/generates"
"github.com/go-oauth2/oauth2/v4/models"

. "github.com/smartystreets/goconvey/convey"
)
Expand Down
6 changes: 3 additions & 3 deletions generates/authorize.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import (
"encoding/base64"
"strings"

"gopkg.in/oauth2.v4"
"gopkg.in/oauth2.v4/utils/uuid"
"github.com/go-oauth2/oauth2/v4"
"github.com/google/uuid"
)

// NewAuthorizeGenerate create to generate the authorize code instance
Expand All @@ -23,7 +23,7 @@ func (ag *AuthorizeGenerate) Token(ctx context.Context, data *oauth2.GenerateBas
buf := bytes.NewBufferString(data.Client.GetID())
buf.WriteString(data.UserID)
token := uuid.NewMD5(uuid.Must(uuid.NewRandom()), buf.Bytes())
code := base64.URLEncoding.EncodeToString(token.Bytes())
code := base64.URLEncoding.EncodeToString([]byte(token.String()))
code = strings.ToUpper(strings.TrimRight(code, "="))

return code, nil
Expand Down
6 changes: 3 additions & 3 deletions generates/authorize_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ import (
"testing"
"time"

"gopkg.in/oauth2.v4"
"gopkg.in/oauth2.v4/generates"
"gopkg.in/oauth2.v4/models"
"github.com/go-oauth2/oauth2/v4"
"github.com/go-oauth2/oauth2/v4/generates"
"github.com/go-oauth2/oauth2/v4/models"

. "github.com/smartystreets/goconvey/convey"
)
Expand Down
21 changes: 10 additions & 11 deletions generates/jwt_access.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,10 @@ import (
"strings"
"time"

errs "errors"

"github.com/dgrijalva/jwt-go"
"gopkg.in/oauth2.v4"
"gopkg.in/oauth2.v4/errors"
"gopkg.in/oauth2.v4/utils/uuid"
"github.com/go-oauth2/oauth2/v4"
"github.com/go-oauth2/oauth2/v4/errors"
"github.com/google/uuid"
)

// JWTAccessClaims jwt claims
Expand All @@ -30,15 +28,15 @@ func (a *JWTAccessClaims) Valid() error {
// NewJWTAccessGenerate create to generate the jwt access token instance
func NewJWTAccessGenerate(kid string, key []byte, method jwt.SigningMethod) *JWTAccessGenerate {
return &JWTAccessGenerate{
SignedKeyId: kid,
SignedKeyID: kid,
SignedKey: key,
SignedMethod: method,
}
}

// JWTAccessGenerate generate the jwt access token
type JWTAccessGenerate struct {
SignedKeyId string
SignedKeyID string
SignedKey []byte
SignedMethod jwt.SigningMethod
}
Expand All @@ -54,8 +52,8 @@ func (a *JWTAccessGenerate) Token(ctx context.Context, data *oauth2.GenerateBasi
}

token := jwt.NewWithClaims(a.SignedMethod, claims)
if a.SignedKeyId != "" {
token.Header["kid"] = a.SignedKeyId
if a.SignedKeyID != "" {
token.Header["kid"] = a.SignedKeyID
}
var key interface{}
if a.isEs() {
Expand All @@ -73,7 +71,7 @@ func (a *JWTAccessGenerate) Token(ctx context.Context, data *oauth2.GenerateBasi
} else if a.isHs() {
key = a.SignedKey
} else {
return "", "", errs.New("unsupported sign method")
return "", "", errors.New("unsupported sign method")
}

access, err := token.SignedString(key)
Expand All @@ -83,7 +81,8 @@ func (a *JWTAccessGenerate) Token(ctx context.Context, data *oauth2.GenerateBasi
refresh := ""

if isGenRefresh {
refresh = base64.URLEncoding.EncodeToString(uuid.NewSHA1(uuid.Must(uuid.NewRandom()), []byte(access)).Bytes())
t := uuid.NewSHA1(uuid.Must(uuid.NewRandom()), []byte(access)).String()
refresh = base64.URLEncoding.EncodeToString([]byte(t))
refresh = strings.ToUpper(strings.TrimRight(refresh, "="))
}

Expand Down
6 changes: 3 additions & 3 deletions generates/jwt_access_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ import (
"time"

"github.com/dgrijalva/jwt-go"
"gopkg.in/oauth2.v4"
"gopkg.in/oauth2.v4/generates"
"gopkg.in/oauth2.v4/models"
"github.com/go-oauth2/oauth2/v4"
"github.com/go-oauth2/oauth2/v4/generates"
"github.com/go-oauth2/oauth2/v4/models"

. "github.com/smartystreets/goconvey/convey"
)
Expand Down
17 changes: 10 additions & 7 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module gopkg.in/oauth2.v4
module github.com/go-oauth2/oauth2/v4

go 1.13

Expand All @@ -10,26 +10,29 @@ require (
github.com/gavv/httpexpect v2.0.0+incompatible
github.com/go-session/session v3.1.2+incompatible
github.com/google/go-querystring v1.0.0 // indirect
github.com/google/uuid v1.1.1
github.com/gorilla/websocket v1.4.2 // indirect
github.com/imkira/go-interpol v1.1.0 // indirect
github.com/k0kubun/colorstring v0.0.0-20150214042306-9440f1994b88 // indirect
github.com/klauspost/compress v1.10.6 // indirect
github.com/mattn/go-colorable v0.1.6 // indirect
github.com/klauspost/compress v1.10.10 // indirect
github.com/mattn/go-colorable v0.1.7 // indirect
github.com/moul/http2curl v1.0.0 // indirect
github.com/onsi/ginkgo v1.12.2 // indirect
github.com/onsi/ginkgo v1.13.0 // indirect
github.com/sergi/go-diff v1.1.0 // indirect
github.com/smartystreets/goconvey v1.6.4
github.com/stretchr/testify v1.5.1 // indirect
github.com/stretchr/testify v1.6.1 // indirect
github.com/tidwall/buntdb v1.1.2
github.com/tidwall/gjson v1.6.0 // indirect
github.com/tidwall/pretty v1.0.1 // indirect
github.com/valyala/fasthttp v1.12.0 // indirect
github.com/valyala/fasthttp v1.14.0 // indirect
github.com/xeipuuv/gojsonschema v1.2.0 // indirect
github.com/yalp/jsonpath v0.0.0-20180802001716-5cc68e5049a0 // indirect
github.com/yudai/gojsondiff v1.0.0 // indirect
github.com/yudai/golcs v0.0.0-20170316035057-ecda9a501e82 // indirect
github.com/yudai/pp v2.0.1+incompatible // indirect
golang.org/x/net v0.0.0-20200520182314-0ba52f642ac2 // indirect
golang.org/x/net v0.0.0-20200625001655-4c5254603344 // indirect
golang.org/x/oauth2 v0.0.0-20200107190931-bf48bf16ab8d
golang.org/x/sys v0.0.0-20200625212154-ddb9806d33ae // indirect
google.golang.org/appengine v1.6.6 // indirect
gopkg.in/yaml.v3 v3.0.0-20200615113413-eeeca48fe776 // indirect
)
Loading

0 comments on commit a156fbe

Please sign in to comment.