update github.com/coreos/go-oidc to v2.3.0

Signed-off-by: Davanum Srinivas <davanum@gmail.com>
This commit is contained in:
Davanum Srinivas
2025-01-22 13:41:04 -05:00
parent c9e81cd84c
commit faf30b3067
49 changed files with 76 additions and 9214 deletions

View File

@@ -1,9 +1,11 @@
language: go
go:
- "1.12"
- "1.13"
- "1.14"
- "1.15"
arch:
- AMD64
- ppc64le
install:
- go get -v -t github.com/coreos/go-oidc/...
- go get golang.org/x/tools/cmd/cover

View File

@@ -10,7 +10,7 @@ import (
"time"
"github.com/pquerna/cachecontrol"
jose "gopkg.in/square/go-jose.v2"
jose "gopkg.in/go-jose/go-jose.v2"
)
// keysExpiryDelta is the allowed clock skew between a client and the OpenID Connect

View File

@@ -13,11 +13,12 @@ import (
"io/ioutil"
"mime"
"net/http"
"strconv"
"strings"
"time"
"golang.org/x/oauth2"
jose "gopkg.in/square/go-jose.v2"
jose "gopkg.in/go-jose/go-jose.v2"
)
const (
@@ -192,6 +193,16 @@ type UserInfo struct {
claims []byte
}
type userInfoRaw struct {
Subject string `json:"sub"`
Profile string `json:"profile"`
Email string `json:"email"`
// Handle providers that return email_verified as a string
// https://forums.aws.amazon.com/thread.jspa?messageID=949441&#949441 and
// https://discuss.elastic.co/t/openid-error-after-authenticating-against-aws-cognito/206018/11
EmailVerified stringAsBool `json:"email_verified"`
}
// Claims unmarshals the raw JSON object claims into the provided object.
func (u *UserInfo) Claims(v interface{}) error {
if u.claims == nil {
@@ -230,12 +241,27 @@ func (p *Provider) UserInfo(ctx context.Context, tokenSource oauth2.TokenSource)
return nil, fmt.Errorf("%s: %s", resp.Status, body)
}
var userInfo UserInfo
ct := resp.Header.Get("Content-Type")
mediaType, _, parseErr := mime.ParseMediaType(ct)
if parseErr == nil && mediaType == "application/jwt" {
payload, err := p.remoteKeySet.VerifySignature(ctx, string(body))
if err != nil {
return nil, fmt.Errorf("oidc: invalid userinfo jwt signature %v", err)
}
body = payload
}
var userInfo userInfoRaw
if err := json.Unmarshal(body, &userInfo); err != nil {
return nil, fmt.Errorf("oidc: failed to decode userinfo: %v", err)
}
userInfo.claims = body
return &userInfo, nil
return &UserInfo{
Subject: userInfo.Subject,
Profile: userInfo.Profile,
Email: userInfo.Email,
EmailVerified: bool(userInfo.EmailVerified),
claims: body,
}, nil
}
// IDToken is an OpenID Connect extension that provides a predictable representation
@@ -357,6 +383,28 @@ type claimSource struct {
AccessToken string `json:"access_token"`
}
type stringAsBool bool
func (sb *stringAsBool) UnmarshalJSON(b []byte) error {
var result bool
err := json.Unmarshal(b, &result)
if err == nil {
*sb = stringAsBool(result)
return nil
}
var s string
err = json.Unmarshal(b, &s)
if err != nil {
return err
}
result, err = strconv.ParseBool(s)
if err != nil {
return err
}
*sb = stringAsBool(result)
return nil
}
type audience []string
func (a *audience) UnmarshalJSON(b []byte) error {

View File

@@ -13,7 +13,7 @@ import (
"time"
"golang.org/x/oauth2"
jose "gopkg.in/square/go-jose.v2"
jose "gopkg.in/go-jose/go-jose.v2"
)
const (
@@ -185,7 +185,7 @@ func parseClaim(raw []byte, name string, v interface{}) error {
return json.Unmarshal([]byte(val), v)
}
// Verify parses a raw ID Token, verifies it's been signed by the provider, preforms
// Verify parses a raw ID Token, verifies it's been signed by the provider, performs
// any additional checks depending on the Config, and returns the payload.
//
// Verify does NOT do nonce validation, which is the callers responsibility.