all: deprecate NoContext
There is no good reason why we suggest NoContext rather than context.Background(). When the oauth2 library first came around, the community was not familiar with the x/net/context package. For documentation reasons, we decided to add NoContext to the oauth2 package. It was not a good idea even back then. And given that context package is fairly popular, there is no good reason why we are depending on this. Updating all the references of NoContext with context.Background and documenting it as deprecated. Change-Id: I18e390f1351023a29b567777a3f963dd550cf657 Reviewed-on: https://go-review.googlesource.com/27690 Reviewed-by: Chris Broadfoot <cbro@golang.org>
This commit is contained in:
@@ -5,11 +5,13 @@
|
||||
package jwt_test
|
||||
|
||||
import (
|
||||
"golang.org/x/oauth2"
|
||||
"context"
|
||||
|
||||
"golang.org/x/oauth2/jwt"
|
||||
)
|
||||
|
||||
func ExampleJWTConfig() {
|
||||
ctx := context.Background()
|
||||
conf := &jwt.Config{
|
||||
Email: "xxx@developer.com",
|
||||
// The contents of your RSA private key or your PEM file
|
||||
@@ -26,6 +28,6 @@ func ExampleJWTConfig() {
|
||||
}
|
||||
// Initiate an http.Client, the following GET request will be
|
||||
// authorized and authenticated on the behalf of user@example.com.
|
||||
client := conf.Client(oauth2.NoContext)
|
||||
client := conf.Client(ctx)
|
||||
client.Get("...")
|
||||
}
|
||||
|
||||
@@ -5,11 +5,10 @@
|
||||
package jwt
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"testing"
|
||||
|
||||
"golang.org/x/oauth2"
|
||||
)
|
||||
|
||||
var dummyPrivateKey = []byte(`-----BEGIN RSA PRIVATE KEY-----
|
||||
@@ -57,7 +56,7 @@ func TestJWTFetch_JSONResponse(t *testing.T) {
|
||||
PrivateKey: dummyPrivateKey,
|
||||
TokenURL: ts.URL,
|
||||
}
|
||||
tok, err := conf.TokenSource(oauth2.NoContext).Token()
|
||||
tok, err := conf.TokenSource(context.Background()).Token()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
@@ -91,7 +90,7 @@ func TestJWTFetch_BadResponse(t *testing.T) {
|
||||
PrivateKey: dummyPrivateKey,
|
||||
TokenURL: ts.URL,
|
||||
}
|
||||
tok, err := conf.TokenSource(oauth2.NoContext).Token()
|
||||
tok, err := conf.TokenSource(context.Background()).Token()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
@@ -124,7 +123,7 @@ func TestJWTFetch_BadResponseType(t *testing.T) {
|
||||
PrivateKey: dummyPrivateKey,
|
||||
TokenURL: ts.URL,
|
||||
}
|
||||
tok, err := conf.TokenSource(oauth2.NoContext).Token()
|
||||
tok, err := conf.TokenSource(context.Background()).Token()
|
||||
if err == nil {
|
||||
t.Error("got a token; expected error")
|
||||
if tok.AccessToken != "" {
|
||||
|
||||
Reference in New Issue
Block a user