Skip to content

Commit 7d68d33

Browse files
authored
Merge branch 'golang:master' into patreon
2 parents d9d4120 + b9c813b commit 7d68d33

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+2910
-1150
lines changed

LICENSE

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
Copyright (c) 2009 The Go Authors. All rights reserved.
1+
Copyright 2009 The Go Authors.
22

33
Redistribution and use in source and binary forms, with or without
44
modification, are permitted provided that the following conditions are
@@ -10,7 +10,7 @@ notice, this list of conditions and the following disclaimer.
1010
copyright notice, this list of conditions and the following disclaimer
1111
in the documentation and/or other materials provided with the
1212
distribution.
13-
* Neither the name of Google Inc. nor the names of its
13+
* Neither the name of Google LLC nor the names of its
1414
contributors may be used to endorse or promote products derived from
1515
this software without specific prior written permission.
1616

README.md

+5-10
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,6 @@
55

66
oauth2 package contains a client implementation for OAuth 2.0 spec.
77

8-
## Installation
9-
10-
~~~~
11-
go get golang.org/x/oauth2
12-
~~~~
13-
14-
Or you can manually git clone the repository to
15-
`$(go env GOPATH)/src/golang.org/x/oauth2`.
16-
178
See pkg.go.dev for further documentation and examples.
189

1910
* [pkg.go.dev/golang.org/x/oauth2](https://pkg.go.dev/golang.org/x/oauth2)
@@ -33,7 +24,11 @@ The main issue tracker for the oauth2 repository is located at
3324
https://github.com/golang/oauth2/issues.
3425

3526
This repository uses Gerrit for code changes. To learn how to submit changes to
36-
this repository, see https://golang.org/doc/contribute.html. In particular:
27+
this repository, see https://go.dev/doc/contribute.
28+
29+
The git repository is https://go.googlesource.com/oauth2.
30+
31+
Note:
3732

3833
* Excluding trivial changes, all contributions should be connected to an existing issue.
3934
* API changes must go through the [change proposal process](https://go.dev/s/proposal-process) before they can be accepted.

clientcredentials/clientcredentials.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ type Config struct {
3737
// URL. This is a constant specific to each server.
3838
TokenURL string
3939

40-
// Scope specifies optional requested permissions.
40+
// Scopes specifies optional requested permissions.
4141
Scopes []string
4242

4343
// EndpointParams specifies additional parameters for requests to the token endpoint.

deviceauth.go

+10
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package oauth2
33
import (
44
"context"
55
"encoding/json"
6+
"errors"
67
"fmt"
78
"io"
89
"net/http"
@@ -58,6 +59,8 @@ func (c *DeviceAuthResponse) UnmarshalJSON(data []byte) error {
5859
type Alias DeviceAuthResponse
5960
aux := &struct {
6061
ExpiresIn int64 `json:"expires_in"`
62+
// workaround misspelling of verification_uri
63+
VerificationURL string `json:"verification_url"`
6164
*Alias
6265
}{
6366
Alias: (*Alias)(c),
@@ -68,6 +71,9 @@ func (c *DeviceAuthResponse) UnmarshalJSON(data []byte) error {
6871
if aux.ExpiresIn != 0 {
6972
c.Expiry = time.Now().UTC().Add(time.Second * time.Duration(aux.ExpiresIn))
7073
}
74+
if c.VerificationURI == "" {
75+
c.VerificationURI = aux.VerificationURL
76+
}
7177
return nil
7278
}
7379

@@ -88,6 +94,10 @@ func (c *Config) DeviceAuth(ctx context.Context, opts ...AuthCodeOption) (*Devic
8894
}
8995

9096
func retrieveDeviceAuth(ctx context.Context, c *Config, v url.Values) (*DeviceAuthResponse, error) {
97+
if c.Endpoint.DeviceAuthURL == "" {
98+
return nil, errors.New("endpoint missing DeviceAuthURL")
99+
}
100+
91101
req, err := http.NewRequest("POST", c.Endpoint.DeviceAuthURL, strings.NewReader(v.Encode()))
92102
if err != nil {
93103
return nil, err

endpoints/endpoints.go

+6-4
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,9 @@ var GitHub = oauth2.Endpoint{
6262

6363
// GitLab is the endpoint for GitLab.
6464
var GitLab = oauth2.Endpoint{
65-
AuthURL: "https://gitlab.com/oauth/authorize",
66-
TokenURL: "https://gitlab.com/oauth/token",
65+
AuthURL: "https://gitlab.com/oauth/authorize",
66+
TokenURL: "https://gitlab.com/oauth/token",
67+
DeviceAuthURL: "https://gitlab.com/oauth/authorize_device",
6768
}
6869

6970
// Google is the endpoint for Google.
@@ -233,8 +234,9 @@ func AzureAD(tenant string) oauth2.Endpoint {
233234
tenant = "common"
234235
}
235236
return oauth2.Endpoint{
236-
AuthURL: "https://login.microsoftonline.com/" + tenant + "/oauth2/v2.0/authorize",
237-
TokenURL: "https://login.microsoftonline.com/" + tenant + "/oauth2/v2.0/token",
237+
AuthURL: "https://login.microsoftonline.com/" + tenant + "/oauth2/v2.0/authorize",
238+
TokenURL: "https://login.microsoftonline.com/" + tenant + "/oauth2/v2.0/token",
239+
DeviceAuthURL: "https://login.microsoftonline.com/" + tenant + "/oauth2/v2.0/devicecode",
238240
}
239241
}
240242

gitlab/gitlab.go

+2-5
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,8 @@
66
package gitlab // import "golang.org/x/oauth2/gitlab"
77

88
import (
9-
"golang.org/x/oauth2"
9+
"golang.org/x/oauth2/endpoints"
1010
)
1111

1212
// Endpoint is GitLab's OAuth 2.0 endpoint.
13-
var Endpoint = oauth2.Endpoint{
14-
AuthURL: "https://gitlab.com/oauth/authorize",
15-
TokenURL: "https://gitlab.com/oauth/token",
16-
}
13+
var Endpoint = endpoints.GitLab

go.mod

+1-9
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,6 @@ module golang.org/x/oauth2
33
go 1.18
44

55
require (
6-
cloud.google.com/go/compute/metadata v0.2.3
6+
cloud.google.com/go/compute/metadata v0.3.0
77
github.com/google/go-cmp v0.5.9
8-
google.golang.org/appengine v1.6.7
9-
)
10-
11-
require (
12-
cloud.google.com/go/compute v1.20.1 // indirect
13-
github.com/golang/protobuf v1.5.3 // indirect
14-
golang.org/x/net v0.15.0 // indirect
15-
google.golang.org/protobuf v1.31.0 // indirect
168
)

go.sum

+2-24
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,4 @@
1-
cloud.google.com/go/compute v1.20.1 h1:6aKEtlUiwEpJzM001l0yFkpXmUVXaN8W+fbkb2AZNbg=
2-
cloud.google.com/go/compute v1.20.1/go.mod h1:4tCnrn48xsqlwSAiLf1HXMQk8CONslYbdiEZc9FEIbM=
3-
cloud.google.com/go/compute/metadata v0.2.3 h1:mg4jlk7mCAj6xXp9UJ4fjI9VUI5rubuGBW5aJ7UnBMY=
4-
cloud.google.com/go/compute/metadata v0.2.3/go.mod h1:VAV5nSsACxMJvgaAuX6Pk2AawlZn8kiOGuCv6gTkwuA=
5-
github.com/golang/protobuf v1.3.1/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
6-
github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk=
7-
github.com/golang/protobuf v1.5.3 h1:KhyjKVUg7Usr/dYsdSqoFveMYd5ko72D+zANwlG1mmg=
8-
github.com/golang/protobuf v1.5.3/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY=
9-
github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
1+
cloud.google.com/go/compute/metadata v0.3.0 h1:Tz+eQXMEqDIKRsmY3cHTL6FVaynIjX2QxYC4trgAKZc=
2+
cloud.google.com/go/compute/metadata v0.3.0/go.mod h1:zFmK7XCadkQkj6TtorcaGlCW1hT1fIilQDwofLpJ20k=
103
github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38=
114
github.com/google/go-cmp v0.5.9/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
12-
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
13-
golang.org/x/net v0.0.0-20190603091049-60506f45cf65/go.mod h1:HSz+uSET+XFnRR8LxR5pz3Of3rY3CfYBVs4xY44aLks=
14-
golang.org/x/net v0.15.0 h1:ugBLEUaxABaB5AJqW9enI0ACdci2RUd4eP51NTBvuJ8=
15-
golang.org/x/net v0.15.0/go.mod h1:idbUs1IY1+zTqbi8yxTbhexhEEk5ur9LInksu6HrEpk=
16-
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
17-
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
18-
golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk=
19-
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
20-
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
21-
google.golang.org/appengine v1.6.7 h1:FZR1q0exgwxzPzp/aF+VccGrSfxfPpkBqjIIEq3ru6c=
22-
google.golang.org/appengine v1.6.7/go.mod h1:8WjMMxjGQR8xUklV/ARdw2HLXBOI7O7uCIDZVag1xfc=
23-
google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw=
24-
google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc=
25-
google.golang.org/protobuf v1.31.0 h1:g0LDEJHgrBl9N9r17Ru3sqWhkIx2NB67okBHPwC7hs8=
26-
google.golang.org/protobuf v1.31.0/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I=

google/appengine.go

+11-9
Original file line numberDiff line numberDiff line change
@@ -6,25 +6,24 @@ package google
66

77
import (
88
"context"
9-
"time"
9+
"log"
10+
"sync"
1011

1112
"golang.org/x/oauth2"
1213
)
1314

14-
// Set at init time by appengine_gen1.go. If nil, we're not on App Engine standard first generation (<= Go 1.9) or App Engine flexible.
15-
var appengineTokenFunc func(c context.Context, scopes ...string) (token string, expiry time.Time, err error)
16-
17-
// Set at init time by appengine_gen1.go. If nil, we're not on App Engine standard first generation (<= Go 1.9) or App Engine flexible.
18-
var appengineAppIDFunc func(c context.Context) string
15+
var logOnce sync.Once // only spam about deprecation once
1916

2017
// AppEngineTokenSource returns a token source that fetches tokens from either
2118
// the current application's service account or from the metadata server,
2219
// depending on the App Engine environment. See below for environment-specific
2320
// details. If you are implementing a 3-legged OAuth 2.0 flow on App Engine that
2421
// involves user accounts, see oauth2.Config instead.
2522
//
26-
// First generation App Engine runtimes (<= Go 1.9):
27-
// AppEngineTokenSource returns a token source that fetches tokens issued to the
23+
// The current version of this library requires at least Go 1.17 to build,
24+
// so first generation App Engine runtimes (<= Go 1.9) are unsupported.
25+
// Previously, on first generation App Engine runtimes, AppEngineTokenSource
26+
// returned a token source that fetches tokens issued to the
2827
// current App Engine application's service account. The provided context must have
2928
// come from appengine.NewContext.
3029
//
@@ -34,5 +33,8 @@ var appengineAppIDFunc func(c context.Context) string
3433
// context and scopes are not used. Please use DefaultTokenSource (or ComputeTokenSource,
3534
// which DefaultTokenSource will use in this case) instead.
3635
func AppEngineTokenSource(ctx context.Context, scope ...string) oauth2.TokenSource {
37-
return appEngineTokenSource(ctx, scope...)
36+
logOnce.Do(func() {
37+
log.Print("google: AppEngineTokenSource is deprecated on App Engine standard second generation runtimes (>= Go 1.11) and App Engine flexible. Please use DefaultTokenSource or ComputeTokenSource.")
38+
})
39+
return ComputeTokenSource("")
3840
}

google/appengine_gen1.go

-77
This file was deleted.

google/appengine_gen2_flex.go

-27
This file was deleted.

0 commit comments

Comments
 (0)