Skip to content

Commit 6968da2

Browse files
committed
oauth2: sync Token.ExpiresIn from internal Token
The internal.Token type is intended to mirror the public Token type. Unmarshalling is sometimes done on the internal token. Sync the field addition, and update the conversion. Updates #61417 Fixes #746 Change-Id: I55818810394adf743afb8d6d3be477a425c233b5 Reviewed-on: https://go-review.googlesource.com/c/oauth2/+/666815 LUCI-TryBot-Result: Go LUCI <[email protected]> Reviewed-by: David Chase <[email protected]> Reviewed-by: Matt Hickford <[email protected]> Reviewed-by: Junyang Shao <[email protected]>
1 parent d2c4e0a commit 6968da2

File tree

2 files changed

+9
-0
lines changed

2 files changed

+9
-0
lines changed

internal/token.go

+8
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,13 @@ type Token struct {
4949
// mechanisms for that TokenSource will not be used.
5050
Expiry time.Time
5151

52+
// ExpiresIn is the OAuth2 wire format "expires_in" field,
53+
// which specifies how many seconds later the token expires,
54+
// relative to an unknown time base approximately around "now".
55+
// It is the application's responsibility to populate
56+
// `Expiry` from `ExpiresIn` when required.
57+
ExpiresIn int64 `json:"expires_in,omitempty"`
58+
5259
// Raw optionally contains extra metadata from the server
5360
// when updating a token.
5461
Raw interface{}
@@ -311,6 +318,7 @@ func doTokenRoundTrip(ctx context.Context, req *http.Request) (*Token, error) {
311318
TokenType: tj.TokenType,
312319
RefreshToken: tj.RefreshToken,
313320
Expiry: tj.expiry(),
321+
ExpiresIn: int64(tj.ExpiresIn),
314322
Raw: make(map[string]interface{}),
315323
}
316324
json.Unmarshal(body, &token.Raw) // no error checks for optional fields

token.go

+1
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,7 @@ func tokenFromInternal(t *internal.Token) *Token {
163163
TokenType: t.TokenType,
164164
RefreshToken: t.RefreshToken,
165165
Expiry: t.Expiry,
166+
ExpiresIn: t.ExpiresIn,
166167
raw: t.Raw,
167168
}
168169
}

0 commit comments

Comments
 (0)