Skip to content

Commit 7352390

Browse files
committed
mod/modconfig: use oauth2.Token directly for the wire format
https://go.dev/issue/61417 added an ExpiresIn field next to Expiry to support the wire format, using expires_in as a duraiton in seconds. While here, apply a suggestion by gopls. Signed-off-by: Daniel Martí <[email protected]> Change-Id: Ic87201bbb6c50241af7f01c0dc4ae9dbea376d15 Reviewed-on: https://review.gerrithub.io/c/cue-lang/cue/+/1201519 TryBot-Result: CUEcueckoo <[email protected]> Unity-Result: CUE porcuepine <[email protected]> Reviewed-by: Roger Peppe <[email protected]>
1 parent 5ffaf1a commit 7352390

File tree

3 files changed

+6
-14
lines changed

3 files changed

+6
-14
lines changed

go.mod

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ require (
2222
github.com/yuin/goldmark v1.7.4
2323
golang.org/x/mod v0.20.0
2424
golang.org/x/net v0.28.0
25-
golang.org/x/oauth2 v0.22.0
25+
golang.org/x/oauth2 v0.23.0
2626
golang.org/x/sync v0.8.0
2727
golang.org/x/sys v0.23.0
2828
golang.org/x/text v0.17.0

go.sum

+2-2
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,8 @@ golang.org/x/mod v0.20.0 h1:utOm6MM3R3dnawAiJgn0y+xvuYRsm1RKM/4giyfDgV0=
6565
golang.org/x/mod v0.20.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c=
6666
golang.org/x/net v0.28.0 h1:a9JDOJc5GMUJ0+UDqmLT86WiEy7iWyIhz8gz8E4e5hE=
6767
golang.org/x/net v0.28.0/go.mod h1:yqtgsTWOOnlGLG9GFRrK3++bGOUEkNBoHZc8MEDWPNg=
68-
golang.org/x/oauth2 v0.22.0 h1:BzDx2FehcG7jJwgWLELCdmLuxk2i+x9UDpSiss2u0ZA=
69-
golang.org/x/oauth2 v0.22.0/go.mod h1:XYTD2NtWslqkgxebSiOHnXEap4TF09sJSc7H1sXbhtI=
68+
golang.org/x/oauth2 v0.23.0 h1:PbgcYx2W7i4LvjJWEbf0ngHV6qJYr86PkAV3bXdLEbs=
69+
golang.org/x/oauth2 v0.23.0/go.mod h1:XYTD2NtWslqkgxebSiOHnXEap4TF09sJSc7H1sXbhtI=
7070
golang.org/x/sync v0.8.0 h1:3NFvSEYkUoMifnESzZl15y791HH1qU2xm6eCJU5ZPXQ=
7171
golang.org/x/sync v0.8.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
7272
golang.org/x/sys v0.23.0 h1:YfKFowiIMvtgl1UERQoTPPToxltDeZfbj4H7dVUCwmM=

mod/modconfig/modconfig_test.go

+3-11
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import (
2020
"cuelabs.dev/go/oci/ociregistry/ocimem"
2121
"cuelabs.dev/go/oci/ociregistry/ociserver"
2222
"github.com/go-quicktest/qt"
23+
"golang.org/x/oauth2"
2324
"golang.org/x/sync/errgroup"
2425
"golang.org/x/tools/txtar"
2526

@@ -210,14 +211,14 @@ package bar
210211
auth := r.Header.Get("Authorization")
211212
if !strings.HasPrefix(auth, fmt.Sprintf("Bearer access_%d_", i)) {
212213
w.WriteHeader(401)
213-
w.Write([]byte(fmt.Sprintf("server %d: unexpected auth header: %s", i, auth)))
214+
fmt.Fprintf(w, "server %d: unexpected auth header: %s", i, auth)
214215
return
215216
}
216217
rh.ServeHTTP(w, r)
217218
})
218219
mux.HandleFunc("/login/oauth/token", func(w http.ResponseWriter, r *http.Request) {
219220
ctr := atomic.AddInt32(&counter, 1)
220-
writeJSON(w, 200, wireToken{
221+
writeJSON(w, 200, oauth2.Token{
221222
AccessToken: fmt.Sprintf("access_%d_%d", i, ctr),
222223
TokenType: "Bearer",
223224
RefreshToken: fmt.Sprintf("refresh_%d", ctr),
@@ -333,12 +334,3 @@ func writeJSON(w http.ResponseWriter, statusCode int, v any) {
333334
w.WriteHeader(statusCode)
334335
w.Write(b)
335336
}
336-
337-
// wireToken describes the JSON encoding for an OAuth 2.0 token
338-
// as specified in the RFC 6749.
339-
type wireToken struct {
340-
AccessToken string `json:"access_token,omitempty"`
341-
TokenType string `json:"token_type,omitempty"`
342-
RefreshToken string `json:"refresh_token,omitempty"`
343-
ExpiresIn int `json:"expires_in,omitempty"`
344-
}

0 commit comments

Comments
 (0)