Migrated from golang/oauth2#484, refs #56402 (comment)
There are a number of OAuth2 token uses outside of the oauth2 library with the token structure being the common denominator. Unfortunately, unmarshaling JSON into an oauth2.Token does not populate it's Expiry field. Hence, the token structure needs be duplicated/embedded to provide this logic as it currently lives in oauth2/internal.
Proposed solution:
Allow unmarshaling an oauth2.Token from its usual json representation, i.e. containing the expires_in field.
An implementation choice might be to add a Token.UnmarshalJSON method though that might imply that (later) adding Token.MarshalJSON may not make sense given the nature of expires_in being relative to the current moment.
Consequence of not implementing:
Duplicated code like https://cs.github.com/?scopeName=All+repos&scope=&q=language%3Agolang+ExpiresIn+int#.
Alternatives:
Migrated from golang/oauth2#484, refs #56402 (comment)
There are a number of OAuth2 token uses outside of the oauth2 library with the token structure being the common denominator. Unfortunately, unmarshaling JSON into an
oauth2.Tokendoes not populate it'sExpiryfield. Hence, the token structure needs be duplicated/embedded to provide this logic as it currently lives inoauth2/internal.Proposed solution:
Allow unmarshaling an oauth2.Token from its usual json representation, i.e. containing the
expires_infield.An implementation choice might be to add a
Token.UnmarshalJSONmethod though that might imply that (later) addingToken.MarshalJSONmay not make sense given the nature ofexpires_inbeing relative to the current moment.Consequence of not implementing:
Duplicated code like https://cs.github.com/?scopeName=All+repos&scope=&q=language%3Agolang+ExpiresIn+int#.
Alternatives:
internal/RetrieveTokento avoid new methods onTokenlike Make RetrieveToken usable by client packages oauth2#354oauth2.Configlike custom exchange request attribute/header oauth2#533, Config: Refresh Token Request with Custom Parameters oauth2#521 or Add additional headers during token refresh oauth2#483