*: update go-oidc and use standard library's context package

This commit is contained in:
Eric Chiang 2017-03-08 10:33:19 -08:00
parent 3e5480a859
commit 777eeafabc
16 changed files with 33 additions and 29 deletions

View File

@ -1,6 +1,7 @@
package main package main
import ( import (
"context"
"crypto/tls" "crypto/tls"
"crypto/x509" "crypto/x509"
"errors" "errors"
@ -15,7 +16,6 @@ import (
"github.com/Sirupsen/logrus" "github.com/Sirupsen/logrus"
"github.com/ghodss/yaml" "github.com/ghodss/yaml"
"github.com/spf13/cobra" "github.com/spf13/cobra"
"golang.org/x/net/context"
"google.golang.org/grpc" "google.golang.org/grpc"
"google.golang.org/grpc/credentials" "google.golang.org/grpc/credentials"

View File

@ -2,6 +2,7 @@ package main
import ( import (
"bytes" "bytes"
"context"
"crypto/tls" "crypto/tls"
"crypto/x509" "crypto/x509"
"encoding/json" "encoding/json"
@ -19,7 +20,6 @@ import (
"github.com/coreos/go-oidc" "github.com/coreos/go-oidc"
"github.com/spf13/cobra" "github.com/spf13/cobra"
"golang.org/x/net/context"
"golang.org/x/oauth2" "golang.org/x/oauth2"
) )
@ -175,7 +175,7 @@ func cmd() *cobra.Command {
} }
a.provider = provider a.provider = provider
a.verifier = provider.Verifier(oidc.VerifyAudience(a.clientID)) a.verifier = provider.Verifier(&oidc.Config{ClientID: a.clientID})
http.HandleFunc("/", a.handleIndex) http.HandleFunc("/", a.handleIndex)
http.HandleFunc("/login", a.handleLogin) http.HandleFunc("/login", a.handleLogin)

View File

@ -2,9 +2,8 @@
package connector package connector
import ( import (
"context"
"net/http" "net/http"
"golang.org/x/net/context"
) )
// Connector is a mechanism for federating login to a remote identity service. // Connector is a mechanism for federating login to a remote identity service.

View File

@ -2,6 +2,7 @@
package github package github
import ( import (
"context"
"encoding/json" "encoding/json"
"errors" "errors"
"fmt" "fmt"
@ -10,7 +11,6 @@ import (
"regexp" "regexp"
"strconv" "strconv"
"golang.org/x/net/context"
"golang.org/x/oauth2" "golang.org/x/oauth2"
"golang.org/x/oauth2/github" "golang.org/x/oauth2/github"

View File

@ -2,6 +2,7 @@
package gitlab package gitlab
import ( import (
"context"
"encoding/json" "encoding/json"
"errors" "errors"
"fmt" "fmt"
@ -12,7 +13,6 @@ import (
"github.com/Sirupsen/logrus" "github.com/Sirupsen/logrus"
"github.com/coreos/dex/connector" "github.com/coreos/dex/connector"
"golang.org/x/net/context"
"golang.org/x/oauth2" "golang.org/x/oauth2"
) )

View File

@ -2,6 +2,7 @@
package ldap package ldap
import ( import (
"context"
"crypto/tls" "crypto/tls"
"crypto/x509" "crypto/x509"
"encoding/json" "encoding/json"
@ -9,7 +10,6 @@ import (
"io/ioutil" "io/ioutil"
"net" "net"
"golang.org/x/net/context"
"gopkg.in/ldap.v2" "gopkg.in/ldap.v2"
"github.com/Sirupsen/logrus" "github.com/Sirupsen/logrus"

View File

@ -2,13 +2,12 @@
package mock package mock
import ( import (
"context"
"errors" "errors"
"fmt" "fmt"
"net/http" "net/http"
"net/url" "net/url"
"golang.org/x/net/context"
"github.com/Sirupsen/logrus" "github.com/Sirupsen/logrus"
"github.com/coreos/dex/connector" "github.com/coreos/dex/connector"
) )

View File

@ -2,13 +2,13 @@
package oidc package oidc
import ( import (
"context"
"errors" "errors"
"fmt" "fmt"
"net/http" "net/http"
"github.com/Sirupsen/logrus" "github.com/Sirupsen/logrus"
"github.com/coreos/go-oidc" "github.com/coreos/go-oidc"
"golang.org/x/net/context"
"golang.org/x/oauth2" "golang.org/x/oauth2"
"github.com/coreos/dex/connector" "github.com/coreos/dex/connector"
@ -53,10 +53,10 @@ func (c *Config) Open(logger logrus.FieldLogger) (conn connector.Connector, err
RedirectURL: c.RedirectURI, RedirectURL: c.RedirectURI,
}, },
verifier: provider.Verifier( verifier: provider.Verifier(
oidc.VerifyExpiry(), &oidc.Config{ClientID: clientID},
oidc.VerifyAudience(clientID),
), ),
logger: logger, logger: logger,
cancel: cancel,
}, nil }, nil
} }

View File

@ -35,7 +35,6 @@ import:
version: 6a513affb38dc9788b449d59ffed099b8de18fa0 version: 6a513affb38dc9788b449d59ffed099b8de18fa0
subpackages: subpackages:
- context - context
- context/ctxhttp
- http2 - http2
- http2/hpack - http2/hpack
- internal/timeseries - internal/timeseries
@ -68,7 +67,7 @@ import:
# Used for server integration tests and OpenID Connect connector. # Used for server integration tests and OpenID Connect connector.
- package: github.com/coreos/go-oidc - package: github.com/coreos/go-oidc
version: 2b5d73091ea4b7ddb15e3ac00077f153120b5b61 version: be73733bb8cc830d0205609b95d125215f8e9c70
- package: github.com/pquerna/cachecontrol - package: github.com/pquerna/cachecontrol
version: c97913dcbd76de40b051a9b4cd827f7eaeb7a868 version: c97913dcbd76de40b051a9b4cd827f7eaeb7a868
- package: golang.org/x/oauth2 - package: golang.org/x/oauth2

View File

@ -5,6 +5,9 @@ import (
"fmt" "fmt"
"golang.org/x/crypto/bcrypt" "golang.org/x/crypto/bcrypt"
// go-grpc doesn't use the standard library's context.
// https://github.com/grpc/grpc-go/issues/711
"golang.org/x/net/context" "golang.org/x/net/context"
"github.com/Sirupsen/logrus" "github.com/Sirupsen/logrus"

View File

@ -1,11 +1,10 @@
package server package server
import ( import (
"context"
"net/http" "net/http"
"net/http/httptest" "net/http/httptest"
"testing" "testing"
"golang.org/x/net/context"
) )
func TestHandleHealth(t *testing.T) { func TestHandleHealth(t *testing.T) {

View File

@ -1,6 +1,7 @@
package server package server
import ( import (
"context"
"crypto/rand" "crypto/rand"
"crypto/rsa" "crypto/rsa"
"encoding/hex" "encoding/hex"
@ -9,7 +10,6 @@ import (
"io" "io"
"time" "time"
"golang.org/x/net/context"
"gopkg.in/square/go-jose.v2" "gopkg.in/square/go-jose.v2"
"github.com/Sirupsen/logrus" "github.com/Sirupsen/logrus"

View File

@ -1,6 +1,7 @@
package server package server
import ( import (
"context"
"errors" "errors"
"fmt" "fmt"
"net/http" "net/http"
@ -10,7 +11,6 @@ import (
"time" "time"
"golang.org/x/crypto/bcrypt" "golang.org/x/crypto/bcrypt"
"golang.org/x/net/context"
"github.com/Sirupsen/logrus" "github.com/Sirupsen/logrus"
"github.com/gorilla/handlers" "github.com/gorilla/handlers"

View File

@ -1,6 +1,7 @@
package server package server
import ( import (
"context"
"crypto/rsa" "crypto/rsa"
"crypto/x509" "crypto/x509"
"encoding/json" "encoding/json"
@ -24,7 +25,6 @@ import (
oidc "github.com/coreos/go-oidc" oidc "github.com/coreos/go-oidc"
"github.com/kylelemons/godebug/pretty" "github.com/kylelemons/godebug/pretty"
"golang.org/x/crypto/bcrypt" "golang.org/x/crypto/bcrypt"
"golang.org/x/net/context"
"golang.org/x/oauth2" "golang.org/x/oauth2"
jose "gopkg.in/square/go-jose.v2" jose "gopkg.in/square/go-jose.v2"
@ -175,6 +175,8 @@ func TestOAuth2CodeFlow(t *testing.T) {
// Connector used by the tests. // Connector used by the tests.
var conn *mock.Callback var conn *mock.Callback
oidcConfig := &oidc.Config{SkipClientIDCheck: true}
tests := []struct { tests := []struct {
name string name string
// If specified these set of scopes will be used during the test case. // If specified these set of scopes will be used during the test case.
@ -189,7 +191,7 @@ func TestOAuth2CodeFlow(t *testing.T) {
if !ok { if !ok {
return fmt.Errorf("no id token found") return fmt.Errorf("no id token found")
} }
if _, err := p.Verifier().Verify(ctx, idToken); err != nil { if _, err := p.Verifier(oidcConfig).Verify(ctx, idToken); err != nil {
return fmt.Errorf("failed to verify id token: %v", err) return fmt.Errorf("failed to verify id token: %v", err)
} }
return nil return nil
@ -212,7 +214,7 @@ func TestOAuth2CodeFlow(t *testing.T) {
if !ok { if !ok {
return fmt.Errorf("no id token found") return fmt.Errorf("no id token found")
} }
idToken, err := p.Verifier().Verify(ctx, rawIDToken) idToken, err := p.Verifier(oidcConfig).Verify(ctx, rawIDToken)
if err != nil { if err != nil {
return fmt.Errorf("failed to verify id token: %v", err) return fmt.Errorf("failed to verify id token: %v", err)
} }
@ -229,7 +231,7 @@ func TestOAuth2CodeFlow(t *testing.T) {
if !ok { if !ok {
return fmt.Errorf("no id token found") return fmt.Errorf("no id token found")
} }
idToken, err := p.Verifier().Verify(ctx, rawIDToken) idToken, err := p.Verifier(oidcConfig).Verify(ctx, rawIDToken)
if err != nil { if err != nil {
return fmt.Errorf("failed to verify id token: %v", err) return fmt.Errorf("failed to verify id token: %v", err)
} }
@ -391,7 +393,7 @@ func TestOAuth2CodeFlow(t *testing.T) {
if !ok { if !ok {
return fmt.Errorf("no id_token in refreshed token") return fmt.Errorf("no id_token in refreshed token")
} }
idToken, err := p.Verifier().Verify(ctx, rawIDToken) idToken, err := p.Verifier(oidcConfig).Verify(ctx, rawIDToken)
if err != nil { if err != nil {
return fmt.Errorf("failed to verify id token: %v", err) return fmt.Errorf("failed to verify id token: %v", err)
} }
@ -632,7 +634,10 @@ func TestOAuth2ImplicitFlow(t *testing.T) {
src := &nonceSource{nonce: nonce} src := &nonceSource{nonce: nonce}
idTokenVerifier := p.Verifier(oidc.VerifyAudience(client.ID), oidc.VerifyNonce(src)) idTokenVerifier := p.Verifier(&oidc.Config{
ClientID: client.ID,
ClaimNonce: src.ClaimNonce,
})
oauth2Config = &oauth2.Config{ oauth2Config = &oauth2.Config{
ClientID: client.ID, ClientID: client.ID,
@ -749,7 +754,7 @@ func TestCrossClientScopes(t *testing.T) {
t.Errorf("no id token found: %v", err) t.Errorf("no id token found: %v", err)
return return
} }
idToken, err := p.Verifier().Verify(ctx, rawIDToken) idToken, err := p.Verifier(&oidc.Config{ClientID: testClientID}).Verify(ctx, rawIDToken)
if err != nil { if err != nil {
t.Errorf("failed to parse ID Token: %v", err) t.Errorf("failed to parse ID Token: %v", err)
return return

View File

@ -2,6 +2,7 @@ package kubernetes
import ( import (
"bytes" "bytes"
"context"
"crypto/tls" "crypto/tls"
"crypto/x509" "crypto/x509"
"encoding/base32" "encoding/base32"
@ -24,7 +25,6 @@ import (
"github.com/Sirupsen/logrus" "github.com/Sirupsen/logrus"
"github.com/ghodss/yaml" "github.com/ghodss/yaml"
"github.com/gtank/cryptopasta" "github.com/gtank/cryptopasta"
"golang.org/x/net/context"
"golang.org/x/net/http2" "golang.org/x/net/http2"
"github.com/coreos/dex/storage" "github.com/coreos/dex/storage"

View File

@ -1,13 +1,12 @@
package kubernetes package kubernetes
import ( import (
"context"
"errors" "errors"
"fmt" "fmt"
"strings" "strings"
"time" "time"
"golang.org/x/net/context"
"github.com/Sirupsen/logrus" "github.com/Sirupsen/logrus"
"github.com/coreos/dex/storage" "github.com/coreos/dex/storage"
"github.com/coreos/dex/storage/kubernetes/k8sapi" "github.com/coreos/dex/storage/kubernetes/k8sapi"
@ -85,6 +84,7 @@ func (c *Config) open(logger logrus.FieldLogger, errOnTPRs bool) (*client, error
if !cli.createThirdPartyResources() { if !cli.createThirdPartyResources() {
if errOnTPRs { if errOnTPRs {
cancel()
return nil, fmt.Errorf("failed creating third party resources") return nil, fmt.Errorf("failed creating third party resources")
} }