Skip to content

Commit 696f7b3

Browse files
seankhliaogopherbot
authored andcommitted
all: modernize with doc links and any
Change-Id: If3fc4542b92da802a31dcabc3405f7b1ab06a18d Reviewed-on: https://go-review.googlesource.com/c/oauth2/+/666396 LUCI-TryBot-Result: Go LUCI <[email protected]> Reviewed-by: Junyang Shao <[email protected]> Reviewed-by: Michael Pratt <[email protected]> Auto-Submit: Sean Liao <[email protected]> Reviewed-by: Matt Hickford <[email protected]>
1 parent 471209b commit 696f7b3

20 files changed

+84
-98
lines changed

authhandler/authhandler.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ type PKCEParams struct {
3434
// and returns an auth code and state upon approval.
3535
type AuthorizationHandler func(authCodeURL string) (code string, state string, err error)
3636

37-
// TokenSourceWithPKCE is an enhanced version of TokenSource with PKCE support.
37+
// TokenSourceWithPKCE is an enhanced version of [oauth2.TokenSource] with PKCE support.
3838
//
3939
// The pkce parameter supports PKCE flow, which uses code challenge and code verifier
4040
// to prevent CSRF attacks. A unique code challenge and code verifier should be generated
@@ -43,12 +43,12 @@ func TokenSourceWithPKCE(ctx context.Context, config *oauth2.Config, state strin
4343
return oauth2.ReuseTokenSource(nil, authHandlerSource{config: config, ctx: ctx, authHandler: authHandler, state: state, pkce: pkce})
4444
}
4545

46-
// TokenSource returns an oauth2.TokenSource that fetches access tokens
46+
// TokenSource returns an [oauth2.TokenSource] that fetches access tokens
4747
// using 3-legged-OAuth flow.
4848
//
49-
// The provided context.Context is used for oauth2 Exchange operation.
49+
// The provided [context.Context] is used for oauth2 Exchange operation.
5050
//
51-
// The provided oauth2.Config should be a full configuration containing AuthURL,
51+
// The provided [oauth2.Config] should be a full configuration containing AuthURL,
5252
// TokenURL, and Scope.
5353
//
5454
// An environment-specific AuthorizationHandler is used to obtain user consent.

clientcredentials/clientcredentials.go

+5-5
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ type Config struct {
5555

5656
// Token uses client credentials to retrieve a token.
5757
//
58-
// The provided context optionally controls which HTTP client is used. See the oauth2.HTTPClient variable.
58+
// The provided context optionally controls which HTTP client is used. See the [oauth2.HTTPClient] variable.
5959
func (c *Config) Token(ctx context.Context) (*oauth2.Token, error) {
6060
return c.TokenSource(ctx).Token()
6161
}
@@ -64,18 +64,18 @@ func (c *Config) Token(ctx context.Context) (*oauth2.Token, error) {
6464
// The token will auto-refresh as necessary.
6565
//
6666
// The provided context optionally controls which HTTP client
67-
// is returned. See the oauth2.HTTPClient variable.
67+
// is returned. See the [oauth2.HTTPClient] variable.
6868
//
69-
// The returned Client and its Transport should not be modified.
69+
// The returned [http.Client] and its Transport should not be modified.
7070
func (c *Config) Client(ctx context.Context) *http.Client {
7171
return oauth2.NewClient(ctx, c.TokenSource(ctx))
7272
}
7373

74-
// TokenSource returns a TokenSource that returns t until t expires,
74+
// TokenSource returns a [oauth2.TokenSource] that returns t until t expires,
7575
// automatically refreshing it as necessary using the provided context and the
7676
// client ID and client secret.
7777
//
78-
// Most users will use Config.Client instead.
78+
// Most users will use [Config.Client] instead.
7979
func (c *Config) TokenSource(ctx context.Context) oauth2.TokenSource {
8080
source := &tokenSource{
8181
ctx: ctx,

google/externalaccount/basecredentials.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -486,11 +486,11 @@ func (ts tokenSource) Token() (*oauth2.Token, error) {
486486
ClientID: conf.ClientID,
487487
ClientSecret: conf.ClientSecret,
488488
}
489-
var options map[string]interface{}
489+
var options map[string]any
490490
// Do not pass workforce_pool_user_project when client authentication is used.
491491
// The client ID is sufficient for determining the user project.
492492
if conf.WorkforcePoolUserProject != "" && conf.ClientID == "" {
493-
options = map[string]interface{}{
493+
options = map[string]any{
494494
"userProject": conf.WorkforcePoolUserProject,
495495
}
496496
}

google/externalaccount/filecredsource.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ func (cs fileCredentialSource) subjectToken() (string, error) {
3535
tokenBytes = bytes.TrimSpace(tokenBytes)
3636
switch cs.Format.Type {
3737
case "json":
38-
jsonData := make(map[string]interface{})
38+
jsonData := make(map[string]any)
3939
err = json.Unmarshal(tokenBytes, &jsonData)
4040
if err != nil {
4141
return "", fmt.Errorf("oauth2/google/externalaccount: failed to unmarshal subject token file: %v", err)

google/externalaccount/urlcredsource.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ func (cs urlCredentialSource) subjectToken() (string, error) {
5353

5454
switch cs.Format.Type {
5555
case "json":
56-
jsonData := make(map[string]interface{})
56+
jsonData := make(map[string]any)
5757
err = json.Unmarshal(respBody, &jsonData)
5858
if err != nil {
5959
return "", fmt.Errorf("oauth2/google/externalaccount: failed to unmarshal subject token file: %v", err)

google/google.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -301,7 +301,7 @@ func (cs computeSource) Token() (*oauth2.Token, error) {
301301
// NOTE(cbro): add hidden metadata about where the token is from.
302302
// This is needed for detection by client libraries to know that credentials come from the metadata server.
303303
// This may be removed in a future version of this library.
304-
return tok.WithExtra(map[string]interface{}{
304+
return tok.WithExtra(map[string]any{
305305
"oauth2.google.tokenSource": "compute-metadata",
306306
"oauth2.google.serviceAccount": acct,
307307
}), nil

google/internal/stsexchange/sts_exchange.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ func defaultHeader() http.Header {
2727
// The first 4 fields are all mandatory. headers can be used to pass additional
2828
// headers beyond the bare minimum required by the token exchange. options can
2929
// be used to pass additional JSON-structured options to the remote server.
30-
func ExchangeToken(ctx context.Context, endpoint string, request *TokenExchangeRequest, authentication ClientAuthentication, headers http.Header, options map[string]interface{}) (*Response, error) {
30+
func ExchangeToken(ctx context.Context, endpoint string, request *TokenExchangeRequest, authentication ClientAuthentication, headers http.Header, options map[string]any) (*Response, error) {
3131
data := url.Values{}
3232
data.Set("audience", request.Audience)
3333
data.Set("grant_type", "urn:ietf:params:oauth:grant-type:token-exchange")

google/internal/stsexchange/sts_exchange_test.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ func TestExchangeToken_Opts(t *testing.T) {
146146
} else if len(strOpts) < 1 {
147147
t.Errorf("\"options\" field has length 0.")
148148
}
149-
var opts map[string]interface{}
149+
var opts map[string]any
150150
err = json.Unmarshal([]byte(strOpts[0]), &opts)
151151
if err != nil {
152152
t.Fatalf("Couldn't parse received \"options\" field.")
@@ -159,7 +159,7 @@ func TestExchangeToken_Opts(t *testing.T) {
159159
if !ok {
160160
t.Errorf("Couldn't find first option parameter.")
161161
} else {
162-
tOpts1, ok := val.(map[string]interface{})
162+
tOpts1, ok := val.(map[string]any)
163163
if !ok {
164164
t.Errorf("Failed to assert the first option parameter as type testOpts.")
165165
} else {
@@ -176,7 +176,7 @@ func TestExchangeToken_Opts(t *testing.T) {
176176
if !ok {
177177
t.Errorf("Couldn't find second option parameter.")
178178
} else {
179-
tOpts2, ok := val2.(map[string]interface{})
179+
tOpts2, ok := val2.(map[string]any)
180180
if !ok {
181181
t.Errorf("Failed to assert the second option parameter as type testOpts.")
182182
} else {
@@ -200,7 +200,7 @@ func TestExchangeToken_Opts(t *testing.T) {
200200

201201
firstOption := testOpts{optsValues[0][0], optsValues[0][1]}
202202
secondOption := testOpts{optsValues[1][0], optsValues[1][1]}
203-
inputOpts := make(map[string]interface{})
203+
inputOpts := make(map[string]any)
204204
inputOpts["one"] = firstOption
205205
inputOpts["two"] = secondOption
206206
ExchangeToken(context.Background(), ts.URL, &exchangeTokenRequest, auth, headers, inputOpts)

internal/doc.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@
22
// Use of this source code is governed by a BSD-style
33
// license that can be found in the LICENSE file.
44

5-
// Package internal contains support packages for oauth2 package.
5+
// Package internal contains support packages for [golang.org/x/oauth2].
66
package internal

internal/oauth2.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import (
1313
)
1414

1515
// ParseKey converts the binary contents of a private key file
16-
// to an *rsa.PrivateKey. It detects whether the private key is in a
16+
// to an [*rsa.PrivateKey]. It detects whether the private key is in a
1717
// PEM container or not. If so, it extracts the private key
1818
// from PEM container before conversion. It only supports PEM
1919
// containers with no passphrase.

internal/token.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,9 @@ import (
2525
// the requests to access protected resources on the OAuth 2.0
2626
// provider's backend.
2727
//
28-
// This type is a mirror of oauth2.Token and exists to break
28+
// This type is a mirror of [golang.org/x/oauth2.Token] and exists to break
2929
// an otherwise-circular dependency. Other internal packages
30-
// should convert this Token into an oauth2.Token before use.
30+
// should convert this Token into an [golang.org/x/oauth2.Token] before use.
3131
type Token struct {
3232
// AccessToken is the token that authorizes and authenticates
3333
// the requests.
@@ -58,7 +58,7 @@ type Token struct {
5858

5959
// Raw optionally contains extra metadata from the server
6060
// when updating a token.
61-
Raw interface{}
61+
Raw any
6262
}
6363

6464
// tokenJSON is the struct representing the HTTP response from OAuth2
@@ -319,7 +319,7 @@ func doTokenRoundTrip(ctx context.Context, req *http.Request) (*Token, error) {
319319
RefreshToken: tj.RefreshToken,
320320
Expiry: tj.expiry(),
321321
ExpiresIn: int64(tj.ExpiresIn),
322-
Raw: make(map[string]interface{}),
322+
Raw: make(map[string]any),
323323
}
324324
json.Unmarshal(body, &token.Raw) // no error checks for optional fields
325325
}

internal/transport.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ import (
99
"net/http"
1010
)
1111

12-
// HTTPClient is the context key to use with [context.WithValue]'s
13-
// function to associate an *http.Client value with a context.
12+
// HTTPClient is the context key to use with [context.WithValue]
13+
// to associate an [*http.Client] value with a context.
1414
var HTTPClient ContextKey
1515

1616
// ContextKey is just an empty struct. It exists so HTTPClient can be

jws/jws.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
// Package jws provides a partial implementation
66
// of JSON Web Signature encoding and decoding.
7-
// It exists to support the golang.org/x/oauth2 package.
7+
// It exists to support the [golang.org/x/oauth2] package.
88
//
99
// See RFC 7515.
1010
//
@@ -48,7 +48,7 @@ type ClaimSet struct {
4848

4949
// See http://tools.ietf.org/html/draft-jones-json-web-token-10#section-4.3
5050
// This array is marshalled using custom code (see (c *ClaimSet) encode()).
51-
PrivateClaims map[string]interface{} `json:"-"`
51+
PrivateClaims map[string]any `json:"-"`
5252
}
5353

5454
func (c *ClaimSet) encode() (string, error) {
@@ -152,7 +152,7 @@ func EncodeWithSigner(header *Header, c *ClaimSet, sg Signer) (string, error) {
152152
}
153153

154154
// Encode encodes a signed JWS with provided header and claim set.
155-
// This invokes EncodeWithSigner using crypto/rsa.SignPKCS1v15 with the given RSA private key.
155+
// This invokes [EncodeWithSigner] using [crypto/rsa.SignPKCS1v15] with the given RSA private key.
156156
func Encode(header *Header, c *ClaimSet, key *rsa.PrivateKey) (string, error) {
157157
sg := func(data []byte) (sig []byte, err error) {
158158
h := sha256.New()

jwt/jwt.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ type Config struct {
6868

6969
// PrivateClaims optionally specifies custom private claims in the JWT.
7070
// See http://tools.ietf.org/html/draft-jones-json-web-token-10#section-4.3
71-
PrivateClaims map[string]interface{}
71+
PrivateClaims map[string]any
7272

7373
// UseIDToken optionally specifies whether ID token should be used instead
7474
// of access token when the server returns both.
@@ -157,7 +157,7 @@ func (js jwtSource) Token() (*oauth2.Token, error) {
157157
AccessToken: tokenRes.AccessToken,
158158
TokenType: tokenRes.TokenType,
159159
}
160-
raw := make(map[string]interface{})
160+
raw := make(map[string]any)
161161
json.Unmarshal(body, &raw) // no error checks for optional fields
162162
token = token.WithExtra(raw)
163163

jwt/jwt_test.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@ func TestJWTFetch_AssertionPayload(t *testing.T) {
227227
PrivateKey: dummyPrivateKey,
228228
PrivateKeyID: "ABCDEFGHIJKLMNOPQRSTUVWXYZ",
229229
TokenURL: ts.URL,
230-
PrivateClaims: map[string]interface{}{
230+
PrivateClaims: map[string]any{
231231
"private0": "claim0",
232232
"private1": "claim1",
233233
},
@@ -273,11 +273,11 @@ func TestJWTFetch_AssertionPayload(t *testing.T) {
273273
t.Errorf("payload prn = %q; want %q", got, want)
274274
}
275275
if len(conf.PrivateClaims) > 0 {
276-
var got interface{}
276+
var got any
277277
if err := json.Unmarshal(gotjson, &got); err != nil {
278278
t.Errorf("failed to parse payload; err = %q", err)
279279
}
280-
m := got.(map[string]interface{})
280+
m := got.(map[string]any)
281281
for v, k := range conf.PrivateClaims {
282282
if !reflect.DeepEqual(m[v], k) {
283283
t.Errorf("payload private claims key = %q: got %#v; want %#v", v, m[v], k)

0 commit comments

Comments
 (0)