Skip to content

x/oauth2: add Token.ExpiresIn struct field #61417

@andig

Description

@andig
Contributor

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:

Activity

added this to the Proposal milestone on Jul 18, 2023
moved this to Incoming in Proposalson Jul 18, 2023
rsc

rsc commented on Jul 26, 2023

@rsc
Contributor

This proposal has been added to the active column of the proposals project
and will now be reviewed at the weekly proposal review meetings.
— rsc for the proposal review group

moved this from Incoming to Active in Proposalson Jul 26, 2023
rsc

rsc commented on Aug 2, 2023

@rsc
Contributor

Is the specific proposal here to change Token.UnmarshalJSON to set the Expiry field based on expires_in?

andig

andig commented on Aug 2, 2023

@andig
ContributorAuthor

Yes. Token.UnmarshalJSON is not exposed today. If it gets exposed it should set the Expiry field based on expires_in. If exposing/adding Token.UnmarshalJSON is not feasible the proposal would be to provide another method to the same result. Thank you!

rsc

rsc commented on Aug 9, 2023

@rsc
Contributor

I'm very confused, since Token.UnmarshalJSON does not exist and yet the top proposal above mentions it. What is the specific API change we are discussing? Or do you have a link to an implementation of the change?

andig

andig commented on Aug 9, 2023

@andig
ContributorAuthor

I'm sorry for the confusion. The request here is to allow unmarshaling an oauth2.Token from its usual json representation, i.e. containing the expires_in field. Doing so by adding UnmarshalJson or exposing an existing internal function is irrelevant. I've updated the proposal.

rsc

rsc commented on Aug 16, 2023

@rsc
Contributor

What is the specific API that we should add?

andig

andig commented on Aug 17, 2023

@andig
ContributorAuthor

@rsc I'm proposing to add the ability of unmarshaling tokens from JSON. I'm in no position to propose a specific api. As written before options I see are:

  1. adding Token.UnmarshalJSON
  2. add a new oauth2.TokenFromJSON method based on internal.tokenJSON

I feel the weekly round trips on this proposal do not really help to move it forward as apparently I cannot make the required contribution. Is there any chance one of the oauth2 owners joins here to improve the contribution?

77 remaining items

gopherbot

gopherbot commented on Aug 16, 2024

@gopherbot
Contributor

Change https://go.dev/cl/605955 mentions this issue: x/oauth2: add Token.ExpiresIn

andig

andig commented on Aug 16, 2024

@andig
ContributorAuthor

Sorry, I don't get it right:

Fixes golang/go#61417

still points to oauth2.

magical

magical commented on Aug 16, 2024

@magical
Contributor

Odd. That's the right syntax; i'm not sure why gerrit's autolinker isn't parsing it correctly. Maybe something misconfigured? Here's another x/oauth2 CL showing the same problem (https://golang.org/cl/450155), whereas a recent x/tools CL shows a correct link (https://golang.org/cl/605015).

In any case, it should work correctly when the commit is eventually merged.

added a commit that references this issue on Aug 22, 2024
3e64809
mvdan

mvdan commented on Sep 19, 2024

@mvdan
Member

Thank you all for this proposal! Even in its minimal form, it's already saving me some amount of copy pasting: https://review.gerrithub.io/c/cue-lang/cue/+/1201519

gopherbot

gopherbot commented on Oct 20, 2024

@gopherbot
Contributor

Change https://go.dev/cl/621215 mentions this issue: x/oauth2: apply the expires_in value returned by the server to Token.ExpiresIn

modified the milestones: Backlog, Unreleased on Nov 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    Status

    Accepted

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @rsc@hickford@magical@andig@dmitshur

        Issue actions

          x/oauth2: add Token.ExpiresIn struct field · Issue #61417 · golang/go