Skip to content
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

golang/oauth2: added OnTokenRefresh callback method #683

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 4 additions & 0 deletions oauth2.go
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,10 @@ func (s *reuseTokenSource) Token() (*Token, error) {
return nil, err
}
t.expiryDelta = s.expiryDelta
if s.t != nil && s.t.OnTokenRefresh != nil {
t.OnTokenRefresh = s.t.OnTokenRefresh
t.OnTokenRefresh(*t)
}
s.t = t
return t, nil
}
Expand Down
4 changes: 4 additions & 0 deletions token.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,10 @@ type Token struct {
// mechanisms for that TokenSource will not be used.
Expiry time.Time `json:"expiry,omitempty"`

// OnTokenRefresh is a function that's getting called whenever
// the TokenSource refreshed the Token.
OnTokenRefresh func(t Token)

// raw optionally contains extra metadata from the server
// when updating a token.
raw interface{}
Expand Down