diff --git a/oauth2.go b/oauth2.go index 90a2c3d6d..8372c8d4e 100644 --- a/oauth2.go +++ b/oauth2.go @@ -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 } diff --git a/token.go b/token.go index 5bbb33217..87a9c6c4a 100644 --- a/token.go +++ b/token.go @@ -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{}