mirror of
https://github.com/golang/oauth2.git
synced 2025-07-21 00:00:09 +08:00
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 golang/oauth2#746 Change-Id: I55818810394adf743afb8d6d3be477a425c233b5 Reviewed-on: https://go-review.googlesource.com/c/oauth2/+/666815 LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: David Chase <drchase@google.com> Reviewed-by: Matt Hickford <matt.hickford@gmail.com> Reviewed-by: Junyang Shao <shaojunyang@google.com>
This commit is contained in:
parent
d2c4e0a625
commit
6968da209b
@ -49,6 +49,13 @@ type Token struct {
|
|||||||
// mechanisms for that TokenSource will not be used.
|
// mechanisms for that TokenSource will not be used.
|
||||||
Expiry time.Time
|
Expiry time.Time
|
||||||
|
|
||||||
|
// ExpiresIn is the OAuth2 wire format "expires_in" field,
|
||||||
|
// which specifies how many seconds later the token expires,
|
||||||
|
// relative to an unknown time base approximately around "now".
|
||||||
|
// It is the application's responsibility to populate
|
||||||
|
// `Expiry` from `ExpiresIn` when required.
|
||||||
|
ExpiresIn int64 `json:"expires_in,omitempty"`
|
||||||
|
|
||||||
// Raw optionally contains extra metadata from the server
|
// Raw optionally contains extra metadata from the server
|
||||||
// when updating a token.
|
// when updating a token.
|
||||||
Raw interface{}
|
Raw interface{}
|
||||||
@ -311,6 +318,7 @@ func doTokenRoundTrip(ctx context.Context, req *http.Request) (*Token, error) {
|
|||||||
TokenType: tj.TokenType,
|
TokenType: tj.TokenType,
|
||||||
RefreshToken: tj.RefreshToken,
|
RefreshToken: tj.RefreshToken,
|
||||||
Expiry: tj.expiry(),
|
Expiry: tj.expiry(),
|
||||||
|
ExpiresIn: int64(tj.ExpiresIn),
|
||||||
Raw: make(map[string]interface{}),
|
Raw: make(map[string]interface{}),
|
||||||
}
|
}
|
||||||
json.Unmarshal(body, &token.Raw) // no error checks for optional fields
|
json.Unmarshal(body, &token.Raw) // no error checks for optional fields
|
||||||
|
Loading…
x
Reference in New Issue
Block a user