Skip to content

Commit

Permalink
fix(idtoken): provide default scope for cert endpoint (#1198)
Browse files Browse the repository at this point in the history
When NewValidator is called without any options passed in it will
fail talking to the google cert endpoint because the dailed
authenticated client will not have proper scopes and leads to the
error: "invalid_scope". We should set a default scope so this method
can be called with no extra options.

Fixes: #1187
  • Loading branch information
codyoss committed Aug 30, 2021
1 parent bb29bf5 commit 7019080
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions idtoken/validate.go
Expand Up @@ -19,6 +19,7 @@ import (
"strings"
"time"

"google.golang.org/api/option/internaloption"
htransport "google.golang.org/api/transport/http"
)

Expand All @@ -34,6 +35,10 @@ var (
now = time.Now
)

func defaultValidatorOpts() []ClientOption {
return []ClientOption{internaloption.WithDefaultScopes("https://www.googleapis.com/auth/cloud-platform")}
}

// Payload represents a decoded payload of an ID Token.
type Payload struct {
Issuer string `json:"iss"`
Expand Down Expand Up @@ -88,6 +93,7 @@ type Validator struct {
// NewValidator creates a Validator that uses the options provided to configure
// a the internal http.Client that will be used to make requests to fetch JWKs.
func NewValidator(ctx context.Context, opts ...ClientOption) (*Validator, error) {
opts = append(defaultValidatorOpts(), opts...)
client, _, err := htransport.NewClient(ctx, opts...)
if err != nil {
return nil, err
Expand Down

0 comments on commit 7019080

Please sign in to comment.