Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: golang/oauth2
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v0.26.0
Choose a base ref
...
head repository: golang/oauth2
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: v0.28.0
Choose a head ref
  • 9 commits
  • 12 files changed
  • 9 contributors

Commits on Feb 6, 2025

  1. endpoints: add patreon endpoint

    Adds the patreon endpoints from their documentation.
    
    https://docs.patreon.com/#oauth.
    
    I've tested these thoroughly whilst making a pr to pocketbase.
    
    pocketbase/pocketbase#3323.
    
    Change-Id: I023871a4340ee4ebcba9fd808d4a8f0c081fc10e
    GitHub-Last-Rev: 890ef05
    GitHub-Pull-Request: #668
    Reviewed-on: https://go-review.googlesource.com/c/oauth2/+/528640
    Reviewed-by: Cherry Mui <[email protected]>
    Reviewed-by: Carlos Amedee <[email protected]>
    Reviewed-by: Jorropo <[email protected]>
    Auto-Submit: Jorropo <[email protected]>
    LUCI-TryBot-Result: Go LUCI <[email protected]>
    ghostdevv authored and gopherbot committed Feb 6, 2025
    Copy the full SHA
    314ee5b View commit details

Commits on Feb 13, 2025

  1. oauth2: fix docs for Config.DeviceAuth

    Config.DeviceAccess should be Config.DeviceAuth when using GenerateVerifier() or S256ChallengeOption()
    
    Change-Id: Ie21a808387f731d270ae54ea1705de3e786cad7f
    GitHub-Last-Rev: 2d6b4fd
    GitHub-Pull-Request: #763
    Reviewed-on: https://go-review.googlesource.com/c/oauth2/+/636216
    Reviewed-by: Dmitri Shuralyov <[email protected]>
    Reviewed-by: Cherry Mui <[email protected]>
    LUCI-TryBot-Result: Go LUCI <[email protected]>
    Auto-Submit: Jorropo <[email protected]>
    Reviewed-by: Jorropo <[email protected]>
    eest authored and gopherbot committed Feb 13, 2025
    Copy the full SHA
    ac571fa View commit details
  2. endpoints: add links/provider for Discord

    Endpoints are provided from
    https://discord.com/developers/docs/topics/oauth2#shared-resources-oauth2-urls.
    
    Change-Id: I7bcc8b4cb5527959acb8f177ffb8bbafbe727e82
    GitHub-Last-Rev: 6869fc3
    GitHub-Pull-Request: #768
    Reviewed-on: https://go-review.googlesource.com/c/oauth2/+/649115
    Reviewed-by: Dmitri Shuralyov <[email protected]>
    Reviewed-by: Cherry Mui <[email protected]>
    Reviewed-by: Dmitri Shuralyov <[email protected]>
    Auto-Submit: Dmitri Shuralyov <[email protected]>
    LUCI-TryBot-Result: Go LUCI <[email protected]>
    hhhapz authored and gopherbot committed Feb 13, 2025
    Copy the full SHA
    109dabf View commit details

Commits on Feb 14, 2025

  1. all: upgrade go directive to at least 1.23.0 [generated]

    By now Go 1.24.0 has been released, and Go 1.22 is no longer supported
    per the Go Release Policy (https://go.dev/doc/devel/release#policy).
    
    For golang/go#69095.
    
    [git-generate]
    (cd . && go get [email protected] && go mod tidy && go fix ./... && go mod edit -toolchain=none)
    
    Change-Id: I718ce0afa60729aeb89396db2b559faf03b90a68
    Reviewed-on: https://go-review.googlesource.com/c/oauth2/+/649795
    Auto-Submit: Gopher Robot <[email protected]>
    Reviewed-by: Dmitri Shuralyov <[email protected]>
    Reviewed-by: Cherry Mui <[email protected]>
    LUCI-TryBot-Result: Go LUCI <[email protected]>
    gopherbot committed Feb 14, 2025
    Copy the full SHA
    3f78298 View commit details

Commits on Feb 24, 2025

  1. jws: split token into fixed number of parts

    Thanks to 'jub0bs' for reporting this issue.
    
    Fixes #71490
    Fixes CVE-2025-22868
    
    Change-Id: I2552731f46d4907f29aafe7863c558387b6bd6e2
    Reviewed-on: https://go-review.googlesource.com/c/oauth2/+/652155
    Auto-Submit: Gopher Robot <[email protected]>
    Reviewed-by: Damien Neil <[email protected]>
    Reviewed-by: Roland Shoemaker <[email protected]>
    LUCI-TryBot-Result: Go LUCI <[email protected]>
    thatnealpatel authored and gopherbot committed Feb 24, 2025
    Copy the full SHA
    681b4d8 View commit details

Commits on Feb 28, 2025

  1. oauth2.go: use a more straightforward return value

    Change-Id: I72d94836c93dabe50fe67ddb762389f674ba6490
    Reviewed-on: https://go-review.googlesource.com/c/oauth2/+/653215
    Reviewed-by: Ian Lance Taylor <[email protected]>
    LUCI-TryBot-Result: Go LUCI <[email protected]>
    Reviewed-by: Michael Pratt <[email protected]>
    Auto-Submit: Ian Lance Taylor <[email protected]>
    cuishuang authored and gopherbot committed Feb 28, 2025
    Copy the full SHA
    9c82a8c View commit details

Commits on Mar 3, 2025

  1. google: fix typos

    Change-Id: I8fc92767c1ea73e731736056c72628977017301e
    Reviewed-on: https://go-review.googlesource.com/c/oauth2/+/645775
    Reviewed-by: Michael Pratt <[email protected]>
    Auto-Submit: Sean Liao <[email protected]>
    LUCI-TryBot-Result: Go LUCI <[email protected]>
    Reviewed-by: Sean Liao <[email protected]>
    Reviewed-by: Junyang Shao <[email protected]>
    alexandear authored and gopherbot committed Mar 3, 2025
    Copy the full SHA
    44967ab View commit details
  2. oauth2: remove unneeded TokenSource implementation in transport test

    Change-Id: I2dca3a211f7b7e30ae023635c5ac44b6237ee01c
    Reviewed-on: https://go-review.googlesource.com/c/oauth2/+/114957
    Reviewed-by: Michael Pratt <[email protected]>
    Auto-Submit: Sean Liao <[email protected]>
    Reviewed-by: Sean Liao <[email protected]>
    LUCI-TryBot-Result: Go LUCI <[email protected]>
    Reviewed-by: Junyang Shao <[email protected]>
    Tim Cooper authored and gopherbot committed Mar 3, 2025
    Copy the full SHA
    ce350bf View commit details
  3. oauth2: Deep copy context client in NewClient

    OAuth2 client creation currently doesn't faithfully reuse the client
    passed into the context. This causes config settings such as timeout to
    be set to Default and may end up to be a gotcha for anyone who sends in
    a context client with timeout set assuming that the timeout will be
    copied to the new client.
    
    Fix: #368
    Change-Id: I4f5f052361ebe07f50fbd694379892833cd1056c
    Reviewed-on: https://go-review.googlesource.com/c/oauth2/+/180920
    Auto-Submit: Sean Liao <[email protected]>
    Reviewed-by: Sean Liao <[email protected]>
    Reviewed-by: Junyang Shao <[email protected]>
    LUCI-TryBot-Result: Go LUCI <[email protected]>
    Reviewed-by: Michael Pratt <[email protected]>
    abeltay authored and gopherbot committed Mar 3, 2025
    Copy the full SHA
    0042180 View commit details
12 changes: 12 additions & 0 deletions endpoints/endpoints.go
Original file line number Diff line number Diff line change
@@ -35,6 +35,12 @@ var Cern = oauth2.Endpoint{
TokenURL: "https://oauth.web.cern.ch/OAuth/Token",
}

// Discord is the endpoint for Discord.
var Discord = oauth2.Endpoint{
AuthURL: "https://discord.com/oauth2/authorize",
TokenURL: "https://discord.com/api/oauth2/token",
}

// Facebook is the endpoint for Facebook.
var Facebook = oauth2.Endpoint{
AuthURL: "https://www.facebook.com/v3.2/dialog/oauth",
@@ -146,6 +152,12 @@ var Odnoklassniki = oauth2.Endpoint{
TokenURL: "https://api.odnoklassniki.ru/oauth/token.do",
}

// Patreon is the endpoint for Patreon.
var Patreon = oauth2.Endpoint{
AuthURL: "https://www.patreon.com/oauth2/authorize",
TokenURL: "https://www.patreon.com/api/oauth2/token",
}

// PayPal is the endpoint for PayPal.
var PayPal = oauth2.Endpoint{
AuthURL: "https://www.paypal.com/webapps/auth/protocol/openidconnect/v1/authorize",
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module golang.org/x/oauth2

go 1.18
go 1.23.0

require (
cloud.google.com/go/compute/metadata v0.3.0
2 changes: 1 addition & 1 deletion google/externalaccount/basecredentials.go
Original file line number Diff line number Diff line change
@@ -263,7 +263,7 @@ const (
fileTypeJSON = "json"
)

// Format contains information needed to retireve a subject token for URL or File sourced credentials.
// Format contains information needed to retrieve a subject token for URL or File sourced credentials.
type Format struct {
// Type should be either "text" or "json". This determines whether the file or URL sourced credentials
// expect a simple text subject token or if the subject token will be contained in a JSON object.
6 changes: 3 additions & 3 deletions google/externalaccount/basecredentials_test.go
Original file line number Diff line number Diff line change
@@ -347,12 +347,12 @@ func TestNonworkforceWithWorkforcePoolUserProject(t *testing.T) {
t.Fatalf("Expected error but found none")
}
if got, want := err.Error(), "oauth2/google/externalaccount: Workforce pool user project should not be set for non-workforce pool credentials"; got != want {
t.Errorf("Incorrect error received.\nExpected: %s\nRecieved: %s", want, got)
t.Errorf("Incorrect error received.\nExpected: %s\nReceived: %s", want, got)
}
}

func TestWorkforcePoolCreation(t *testing.T) {
var audienceValidatyTests = []struct {
var audienceValidityTests = []struct {
audience string
expectSuccess bool
}{
@@ -371,7 +371,7 @@ func TestWorkforcePoolCreation(t *testing.T) {
}

ctx := context.Background()
for _, tt := range audienceValidatyTests {
for _, tt := range audienceValidityTests {
t.Run(" "+tt.audience, func(t *testing.T) { // We prepend a space ahead of the test input when outputting for sake of readability.
config := testConfig
config.TokenURL = "https://sts.googleapis.com" // Setting the most basic acceptable tokenURL
8 changes: 4 additions & 4 deletions google/externalaccount/executablecredsource_test.go
Original file line number Diff line number Diff line change
@@ -654,7 +654,7 @@ func TestRetrieveOutputFileSubjectTokenNotJSON(t *testing.T) {
if _, err = base.subjectToken(); err == nil {
t.Fatalf("Expected error but found none")
} else if got, want := err.Error(), jsonParsingError(outputFileSource, "tokentokentoken").Error(); got != want {
t.Errorf("Incorrect error received.\nExpected: %s\nRecieved: %s", want, got)
t.Errorf("Incorrect error received.\nExpected: %s\nReceived: %s", want, got)
}

_, deadlineSet := te.getDeadline()
@@ -801,7 +801,7 @@ func TestRetrieveOutputFileSubjectTokenFailureTests(t *testing.T) {
if _, err = ecs.subjectToken(); err == nil {
t.Errorf("Expected error but found none")
} else if got, want := err.Error(), tt.expectedErr.Error(); got != want {
t.Errorf("Incorrect error received.\nExpected: %s\nRecieved: %s", want, got)
t.Errorf("Incorrect error received.\nExpected: %s\nReceived: %s", want, got)
}

if _, deadlineSet := te.getDeadline(); deadlineSet {
@@ -923,7 +923,7 @@ func TestRetrieveOutputFileSubjectTokenInvalidCache(t *testing.T) {
}

if got, want := out, "tokentokentoken"; got != want {
t.Errorf("Incorrect token received.\nExpected: %s\nRecieved: %s", want, got)
t.Errorf("Incorrect token received.\nExpected: %s\nReceived: %s", want, got)
}
})
}
@@ -1012,7 +1012,7 @@ func TestRetrieveOutputFileSubjectTokenJwt(t *testing.T) {
if out, err := ecs.subjectToken(); err != nil {
t.Errorf("retrieveSubjectToken() failed: %v", err)
} else if got, want := out, "tokentokentoken"; got != want {
t.Errorf("Incorrect token received.\nExpected: %s\nRecieved: %s", want, got)
t.Errorf("Incorrect token received.\nExpected: %s\nReceived: %s", want, got)
}

if _, deadlineSet := te.getDeadline(); deadlineSet {
2 changes: 1 addition & 1 deletion google/google_test.go
Original file line number Diff line number Diff line change
@@ -72,7 +72,7 @@ func TestConfigFromJSON(t *testing.T) {
t.Errorf("ClientSecret = %q; want %q", got, want)
}
if got, want := conf.RedirectURL, "https://www.example.com/oauth2callback"; got != want {
t.Errorf("RedictURL = %q; want %q", got, want)
t.Errorf("RedirectURL = %q; want %q", got, want)
}
if got, want := strings.Join(conf.Scopes, ","), "scope1,scope2"; got != want {
t.Errorf("Scopes = %q; want %q", got, want)
Original file line number Diff line number Diff line change
@@ -38,7 +38,7 @@ type testRefreshTokenServer struct {
server *httptest.Server
}

func TestExernalAccountAuthorizedUser_JustToken(t *testing.T) {
func TestExternalAccountAuthorizedUser_JustToken(t *testing.T) {
config := &Config{
Token: "AAAAAAA",
Expiry: now().Add(time.Hour),
@@ -57,7 +57,7 @@ func TestExernalAccountAuthorizedUser_JustToken(t *testing.T) {
}
}

func TestExernalAccountAuthorizedUser_TokenRefreshWithRefreshTokenInRespondse(t *testing.T) {
func TestExternalAccountAuthorizedUser_TokenRefreshWithRefreshTokenInResponse(t *testing.T) {
server := &testRefreshTokenServer{
URL: "/",
Authorization: "Basic Q0xJRU5UX0lEOkNMSUVOVF9TRUNSRVQ=",
@@ -99,7 +99,7 @@ func TestExernalAccountAuthorizedUser_TokenRefreshWithRefreshTokenInRespondse(t
}
}

func TestExernalAccountAuthorizedUser_MinimumFieldsRequiredForRefresh(t *testing.T) {
func TestExternalAccountAuthorizedUser_MinimumFieldsRequiredForRefresh(t *testing.T) {
server := &testRefreshTokenServer{
URL: "/",
Authorization: "Basic Q0xJRU5UX0lEOkNMSUVOVF9TRUNSRVQ=",
@@ -187,7 +187,7 @@ func TestExternalAccountAuthorizedUser_MissingRefreshFields(t *testing.T) {
},
},
{
name: "missing client secrect",
name: "missing client secret",
config: Config{
RefreshToken: "BBBBBBBBB",
TokenURL: url,
2 changes: 1 addition & 1 deletion google/internal/stsexchange/sts_exchange_test.go
Original file line number Diff line number Diff line change
@@ -142,7 +142,7 @@ func TestExchangeToken_Opts(t *testing.T) {
}
strOpts, ok := data["options"]
if !ok {
t.Errorf("Server didn't recieve an \"options\" field.")
t.Errorf("Server didn't receive an \"options\" field.")
} else if len(strOpts) < 1 {
t.Errorf("\"options\" field has length 0.")
}
4 changes: 2 additions & 2 deletions jws/jws.go
Original file line number Diff line number Diff line change
@@ -165,11 +165,11 @@ func Encode(header *Header, c *ClaimSet, key *rsa.PrivateKey) (string, error) {
// Verify tests whether the provided JWT token's signature was produced by the private key
// associated with the supplied public key.
func Verify(token string, key *rsa.PublicKey) error {
parts := strings.Split(token, ".")
if len(parts) != 3 {
if strings.Count(token, ".") != 2 {
return errors.New("jws: invalid token received, token must have 3 parts")
}

parts := strings.SplitN(token, ".", 3)
signedContent := parts[0] + "." + parts[1]
signatureString, err := base64.RawURLEncoding.DecodeString(parts[2])
if err != nil {
8 changes: 6 additions & 2 deletions oauth2.go
Original file line number Diff line number Diff line change
@@ -288,7 +288,7 @@ func (tf *tokenRefresher) Token() (*Token, error) {
if tf.refreshToken != tk.RefreshToken {
tf.refreshToken = tk.RefreshToken
}
return tk, err
return tk, nil
}

// reuseTokenSource is a TokenSource that holds a single token in memory
@@ -356,11 +356,15 @@ func NewClient(ctx context.Context, src TokenSource) *http.Client {
if src == nil {
return internal.ContextClient(ctx)
}
cc := internal.ContextClient(ctx)
return &http.Client{
Transport: &Transport{
Base: internal.ContextClient(ctx).Transport,
Base: cc.Transport,
Source: ReuseTokenSource(nil, src),
},
CheckRedirect: cc.CheckRedirect,
Jar: cc.Jar,
Timeout: cc.Timeout,
}
}

4 changes: 2 additions & 2 deletions pkce.go
Original file line number Diff line number Diff line change
@@ -21,7 +21,7 @@ const (
//
// A fresh verifier should be generated for each authorization.
// S256ChallengeOption(verifier) should then be passed to Config.AuthCodeURL
// (or Config.DeviceAccess) and VerifierOption(verifier) to Config.Exchange
// (or Config.DeviceAuth) and VerifierOption(verifier) to Config.Exchange
// (or Config.DeviceAccessToken).
func GenerateVerifier() string {
// "RECOMMENDED that the output of a suitable random number generator be
@@ -51,7 +51,7 @@ func S256ChallengeFromVerifier(verifier string) string {
}

// S256ChallengeOption derives a PKCE code challenge derived from verifier with
// method S256. It should be passed to Config.AuthCodeURL or Config.DeviceAccess
// method S256. It should be passed to Config.AuthCodeURL or Config.DeviceAuth
// only.
func S256ChallengeOption(verifier string) AuthCodeOption {
return challengeOption{
24 changes: 6 additions & 18 deletions transport_test.go
Original file line number Diff line number Diff line change
@@ -9,12 +9,6 @@ import (
"time"
)

type tokenSource struct{ token *Token }

func (t *tokenSource) Token() (*Token, error) {
return t.token, nil
}

func TestTransportNilTokenSource(t *testing.T) {
tr := &Transport{}
server := newMockServer(func(w http.ResponseWriter, r *http.Request) {})
@@ -88,13 +82,10 @@ func TestTransportCloseRequestBodySuccess(t *testing.T) {
}

func TestTransportTokenSource(t *testing.T) {
ts := &tokenSource{
token: &Token{
AccessToken: "abc",
},
}
tr := &Transport{
Source: ts,
Source: StaticTokenSource(&Token{
AccessToken: "abc",
}),
}
server := newMockServer(func(w http.ResponseWriter, r *http.Request) {
if got, want := r.Header.Get("Authorization"), "Bearer abc"; got != want {
@@ -123,14 +114,11 @@ func TestTransportTokenSourceTypes(t *testing.T) {
{key: "basic", val: val, want: "Basic abc"},
}
for _, tc := range tests {
ts := &tokenSource{
token: &Token{
tr := &Transport{
Source: StaticTokenSource(&Token{
AccessToken: tc.val,
TokenType: tc.key,
},
}
tr := &Transport{
Source: ts,
}),
}
server := newMockServer(func(w http.ResponseWriter, r *http.Request) {
if got, want := r.Header.Get("Authorization"), tc.want; got != want {