-
Notifications
You must be signed in to change notification settings - Fork 10
Description
Thanks for publishing an easy-to-use client library! I was wondering about the API design for actual use.
In the current code, it seems that oauth2.TokenSource is created for each request.
Line 159 in 4609d30
| tokenSource := c.config.Oauth2.TokenSource(ctx, oauth2Token) |
The internal implementation of oauth2.TokenSource , oauth2.reuseTokenSource , checks to see if the token is currently valid, and if not, it reclaims and updates the token. It is then serialized by Mutex.
https://github.com/golang/oauth2/blob/d3ed0bb246c8d3c75b63937d9a5eecff9c74d7fe/oauth2.go#L295-L310
With the current design of this client library, I believe there is a possibility of multiple refreshes and race conditions when parallel requests are made. This problem can be solved by changing the function signature to the following and passing the TokenSource from outside. (I understand that this is a big change.)
func (c *Client) GetUsersMe(ctx context.Context, tokenSource *oauth2.TokenSource, opts GetUsersMeOpts) (*Me, error)
tokenSource := config.Oauth2.TokenSource(ctx, token)
me, err := client.GetUsersMe(ctx, tokenSource, freee.GetUsersMeOpts{})What are your thoughts on these issues?