-
Notifications
You must be signed in to change notification settings - Fork 1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Provide a way for a client to access refreshed Access Token #131
Comments
For reference, there used to be support for token caches but it was removed for some reason. See 93ad3f4 |
Okay, I read this now. Let's just use a func. Then the caller can do a channel or goroutine if they want. Maybe we create a new TokenSource which calls your func when the Token is refreshed. // NotifyUseSource returns a TokenSource which calls notify whenever src is used.
// The arguments to notify are the return values from src.Token.
// The returned TokenSource returns the Token from src and the returned error from notify.
// The notify func is allowed to change or add an an error from src, but cannot change
// a non-nil error to nil, as there would be no Token to return.
// A NotifyUseSource can be used to refresh cached tokens.
func NotifyUseSource(src TokenSource, notify func(*Token, error) error) TokenSource |
Sounds good to use a func but it would be redundant to call it every time a token is used. It suffices to call |
Yes, you would compose it with a |
Right. It's just Config.TokenSource already returns a c := &Config{...}
// src is reuseTokenSource(tokenRefresher)
src := c.TokenSource(ctx, tok)
// src is reuseTokenSource(notifyUseToken(reuseTokenSource(tokenRefresher)))
src = ReuseTokenSource(nil, NotifyUseSource(src, notifyMe)) Unless, func (c *Config) NotifyUseTokenSource(ctx context.Context, t *Token, notify func(*Token, error) error) TokenSource |
I'd prefer the composable way, rather than the all-in-one, one-special-case way. |
Alright. I'll work on a CL. |
Closing as duplicate of #84 |
It is often desirable for a program to get access to newly obtained access token upon refresh. Consider the following use case:
I'm proposing the following:
Then, a program could do something like this:
I can open a CL if you guys think this is useful.
The text was updated successfully, but these errors were encountered: