Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable go module support for the project #3

Merged
merged 15 commits into from
May 29, 2021
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 3 additions & 5 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,7 @@ script:
- go test -v ./...

go:
- 1.3
- 1.4
- 1.5
- 1.6
- 1.7
- 1.14
oxisto marked this conversation as resolved.
Show resolved Hide resolved
- 1.15
- 1.16
- tip
20 changes: 10 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# jwt-go

[![Build Status](https://travis-ci.org/dgrijalva/jwt-go.svg?branch=master)](https://travis-ci.org/dgrijalva/jwt-go)
[![GoDoc](https://godoc.org/github.com/dgrijalva/jwt-go?status.svg)](https://godoc.org/github.com/dgrijalva/jwt-go)
[![GoDoc](https://godoc.org/github.com/golang-jwt/jwt?status.svg)](https://godoc.org/github.com/golang-jwt/jwt)

A [go](http://www.golang.org) (or 'golang' for search engine friendliness) implementation of [JSON Web Tokens](http://self-issued.info/docs/draft-ietf-oauth-json-web-token.html)

Expand All @@ -27,11 +27,11 @@ This library supports the parsing and verification as well as the generation and

## Examples

See [the project documentation](https://godoc.org/github.com/dgrijalva/jwt-go) for examples of usage:
See [the project documentation](https://godoc.org/github.com/golang-jwt/jwt) for examples of usage:

* [Simple example of parsing and validating a token](https://godoc.org/github.com/dgrijalva/jwt-go#example-Parse--Hmac)
* [Simple example of building and signing a token](https://godoc.org/github.com/dgrijalva/jwt-go#example-New--Hmac)
* [Directory of Examples](https://godoc.org/github.com/dgrijalva/jwt-go#pkg-examples)
* [Simple example of parsing and validating a token](https://godoc.org/github.com/golang-jwt/jwt#example-Parse--Hmac)
* [Simple example of building and signing a token](https://godoc.org/github.com/golang-jwt/jwt#example-New--Hmac)
* [Directory of Examples](https://godoc.org/github.com/golang-jwt/jwt#pkg-examples)

## Extensions

Expand All @@ -49,7 +49,7 @@ This library was last reviewed to comply with [RTF 7519](http://www.rfc-editor.o

This library is considered production ready. Feedback and feature requests are appreciated. The API should be considered stable. There should be very few backwards-incompatible changes outside of major version updates (and only with good reason).

This project uses [Semantic Versioning 2.0.0](http://semver.org). Accepted pull requests will land on `master`. Periodically, versions will be tagged from `master`. You can find all the releases on [the project releases page](https://github.com/dgrijalva/jwt-go/releases).
This project uses [Semantic Versioning 2.0.0](http://semver.org). Accepted pull requests will land on `master`. Periodically, versions will be tagged from `master`. You can find all the releases on [the project releases page](https://github.com/golang-jwt/jwt/releases).

While we try to make it obvious when we make breaking changes, there isn't a great mechanism for pushing announcements out to users. You may want to use this alternative package include: `gopkg.in/dgrijalva/jwt-go.v3`. It will do the right thing WRT semantic versioning.

Expand Down Expand Up @@ -79,9 +79,9 @@ Asymmetric signing methods, such as RSA, use different keys for signing and veri

Each signing method expects a different object type for its signing keys. See the package documentation for details. Here are the most common ones:

* The [HMAC signing method](https://godoc.org/github.com/dgrijalva/jwt-go#SigningMethodHMAC) (`HS256`,`HS384`,`HS512`) expect `[]byte` values for signing and validation
* The [RSA signing method](https://godoc.org/github.com/dgrijalva/jwt-go#SigningMethodRSA) (`RS256`,`RS384`,`RS512`) expect `*rsa.PrivateKey` for signing and `*rsa.PublicKey` for validation
* The [ECDSA signing method](https://godoc.org/github.com/dgrijalva/jwt-go#SigningMethodECDSA) (`ES256`,`ES384`,`ES512`) expect `*ecdsa.PrivateKey` for signing and `*ecdsa.PublicKey` for validation
* The [HMAC signing method](https://godoc.org/github.com/golang-jwt/jwt#SigningMethodHMAC) (`HS256`,`HS384`,`HS512`) expect `[]byte` values for signing and validation
* The [RSA signing method](https://godoc.org/github.com/golang-jwt/jwt#SigningMethodRSA) (`RS256`,`RS384`,`RS512`) expect `*rsa.PrivateKey` for signing and `*rsa.PublicKey` for validation
* The [ECDSA signing method](https://godoc.org/github.com/golang-jwt/jwt#SigningMethodECDSA) (`ES256`,`ES384`,`ES512`) expect `*ecdsa.PrivateKey` for signing and `*ecdsa.PublicKey` for validation

### JWT and OAuth

Expand All @@ -99,6 +99,6 @@ This library uses descriptive error messages whenever possible. If you are not g

## More

Documentation can be found [on godoc.org](http://godoc.org/github.com/dgrijalva/jwt-go).
Documentation can be found [on godoc.org](http://godoc.org/github.com/golang-jwt/jwt).

The command line utility included in this project (cmd/jwt) provides a straightforward example of token creation and parsing as well as a useful tool for debugging your own integration. You'll also find several implementation examples in the documentation.
2 changes: 1 addition & 1 deletion cmd/jwt/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,5 @@ To simply display a token, use:

You can install this tool with the following command:

go install github.com/dgrijalva/jwt-go/cmd/jwt
go install github.com/golang-jwt/jwt/cmd/jwt

2 changes: 1 addition & 1 deletion cmd/jwt/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import (
"regexp"
"strings"

jwt "github.com/dgrijalva/jwt-go"
"github.com/golang-jwt/jwt"
)

var (
Expand Down
2 changes: 1 addition & 1 deletion ecdsa_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"strings"
"testing"

"github.com/dgrijalva/jwt-go"
"github.com/golang-jwt/jwt"
)

var ecdsaTestData = []struct {
Expand Down
3 changes: 2 additions & 1 deletion example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@ package jwt_test

import (
"fmt"
"github.com/dgrijalva/jwt-go"
"time"

"github.com/golang-jwt/jwt"
)

// Example (atypical) using the StandardClaims type by itself to parse a token.
Expand Down
3 changes: 3 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module github.com/golang-jwt/jwt

go 1.16
sadmansakib marked this conversation as resolved.
Show resolved Hide resolved
5 changes: 3 additions & 2 deletions hmac_example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@ package jwt_test

import (
"fmt"
"github.com/dgrijalva/jwt-go"
"io/ioutil"
"time"

"github.com/golang-jwt/jwt"
)

// For HMAC signing method, the key can be any []byte. It is recommended to generate
Expand Down Expand Up @@ -51,7 +52,7 @@ func ExampleParse_hmac() {
if _, ok := token.Method.(*jwt.SigningMethodHMAC); !ok {
return nil, fmt.Errorf("Unexpected signing method: %v", token.Header["alg"])
}

// hmacSampleSecret is a []byte containing your secret, e.g. []byte("my_secret_key")
return hmacSampleSecret, nil
})
Expand Down
3 changes: 2 additions & 1 deletion hmac_test.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
package jwt_test

import (
"github.com/dgrijalva/jwt-go"
"io/ioutil"
"strings"
"testing"

"github.com/golang-jwt/jwt"
)

var hmacTestData = []struct {
Expand Down
6 changes: 4 additions & 2 deletions http_example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ import (
"bytes"
"crypto/rsa"
"fmt"
"github.com/dgrijalva/jwt-go"
"github.com/dgrijalva/jwt-go/request"
"io"
"io/ioutil"
"log"
Expand All @@ -17,6 +15,9 @@ import (
"net/url"
"strings"
"time"

"github.com/golang-jwt/jwt"
"github.com/golang-jwt/jwt/request"
)

// location of the files used for signing and verification
Expand Down Expand Up @@ -55,6 +56,7 @@ func init() {

// Setup listener
listener, err := net.ListenTCP("tcp", &net.TCPAddr{})
fatal(err)
serverPort = listener.Addr().(*net.TCPAddr).Port

log.Println("Listening...")
Expand Down
3 changes: 2 additions & 1 deletion none_test.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
package jwt_test

import (
"github.com/dgrijalva/jwt-go"
"strings"
"testing"

"github.com/golang-jwt/jwt"
)

var noneTestData = []struct {
Expand Down
4 changes: 2 additions & 2 deletions parser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ import (
"testing"
"time"

"github.com/dgrijalva/jwt-go"
"github.com/dgrijalva/jwt-go/test"
"github.com/golang-jwt/jwt"
"github.com/golang-jwt/jwt/test"
)

var keyFuncError error = fmt.Errorf("error loading key")
Expand Down
3 changes: 2 additions & 1 deletion request/request.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
package request

import (
"github.com/dgrijalva/jwt-go"
"net/http"

"github.com/golang-jwt/jwt"
)

// Extract and parse a JWT token from an HTTP request.
Expand Down
5 changes: 3 additions & 2 deletions request/request_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@ package request

import (
"fmt"
"github.com/dgrijalva/jwt-go"
"github.com/dgrijalva/jwt-go/test"
"net/http"
"net/url"
"reflect"
"strings"
"testing"

"github.com/golang-jwt/jwt"
"github.com/golang-jwt/jwt/test"
)

var requestTestData = []struct {
Expand Down
2 changes: 1 addition & 1 deletion rsa_pss.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ type SigningMethodRSAPSS struct {
// VerifyOptions is optional. If set overrides Options for rsa.VerifyPPS.
// Used to accept tokens signed with rsa.PSSSaltLengthAuto, what doesn't follow
// https://tools.ietf.org/html/rfc7518#section-3.5 but was used previously.
// See https://github.com/dgrijalva/jwt-go/issues/285#issuecomment-437451244 for details.
// See https://github.com/golang-jwt/jwt/issues/285#issuecomment-437451244 for details.
sadmansakib marked this conversation as resolved.
Show resolved Hide resolved
VerifyOptions *rsa.PSSOptions
}

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

"github.com/dgrijalva/jwt-go"
"github.com/dgrijalva/jwt-go/test"
"github.com/golang-jwt/jwt"
"github.com/golang-jwt/jwt/test"
)

var rsaPSSTestData = []struct {
Expand Down Expand Up @@ -106,7 +106,7 @@ func TestRSAPSSSaltLengthCompatibility(t *testing.T) {
},
}

// Behaves as before https://github.com/dgrijalva/jwt-go/issues/285 fix.
// Behaves as before https://github.com/golang-jwt/jwt/issues/285 fix.
sadmansakib marked this conversation as resolved.
Show resolved Hide resolved
ps256SaltLengthAuto := &jwt.SigningMethodRSAPSS{
SigningMethodRSA: jwt.SigningMethodPS256.SigningMethodRSA,
Options: &rsa.PSSOptions{
Expand Down
3 changes: 2 additions & 1 deletion rsa_test.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
package jwt_test

import (
"github.com/dgrijalva/jwt-go"
"io/ioutil"
"strings"
"testing"

"github.com/golang-jwt/jwt"
)

var rsaTestData = []struct {
Expand Down
3 changes: 2 additions & 1 deletion test/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@ package test

import (
"crypto/rsa"
"github.com/dgrijalva/jwt-go"
"io/ioutil"

"github.com/golang-jwt/jwt"
)

func LoadRSAPrivateKeyFromDisk(location string) *rsa.PrivateKey {
Expand Down
2 changes: 1 addition & 1 deletion token.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ func (t *Token) SignedString(key interface{}) (string, error) {
func (t *Token) SigningString() (string, error) {
var err error
parts := make([]string, 2)
for i, _ := range parts {
for i := range parts {
var jsonValue []byte
if i == 0 {
if jsonValue, err = json.Marshal(t.Header); err != nil {
Expand Down