From 3639b6cfb270a1acbdcd967f4ee5c6a395d176b6 Mon Sep 17 00:00:00 2001 From: Dainismo Date: Wed, 8 Nov 2023 20:00:44 +0100 Subject: [PATCH 1/3] Added token refresh callback --- oauth2.go | 4 ++++ token.go | 4 ++++ 2 files changed, 8 insertions(+) diff --git a/oauth2.go b/oauth2.go index 90a2c3d6d..a4b9a0161 100644 --- a/oauth2.go +++ b/oauth2.go @@ -318,7 +318,11 @@ func (s *reuseTokenSource) Token() (*Token, error) { return nil, err } t.expiryDelta = s.expiryDelta + t.OnTokenRefresh = s.t.OnTokenRefresh s.t = t + if t.OnTokenRefresh != nil { + t.OnTokenRefresh(*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{} From b1b9cc6b098d4b581f2fa4576b461e576233241c Mon Sep 17 00:00:00 2001 From: Dainismo Date: Sat, 11 Nov 2023 13:52:47 +0100 Subject: [PATCH 2/3] golang/oauth2: fixxed nil pointer reference --- oauth2.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/oauth2.go b/oauth2.go index a4b9a0161..5f87e2e5d 100644 --- a/oauth2.go +++ b/oauth2.go @@ -318,11 +318,11 @@ func (s *reuseTokenSource) Token() (*Token, error) { return nil, err } t.expiryDelta = s.expiryDelta - t.OnTokenRefresh = s.t.OnTokenRefresh - s.t = t - if t.OnTokenRefresh != nil { + if s.t.OnTokenRefresh != nil { + t.OnTokenRefresh = s.t.OnTokenRefresh t.OnTokenRefresh(*t) } + s.t = t return t, nil } From 88cd8be2cf267a18053232be153bde15533b32a0 Mon Sep 17 00:00:00 2001 From: Dainismo Date: Mon, 13 Nov 2023 21:26:18 +0100 Subject: [PATCH 3/3] golang/oauth2: fixxed nil pointer reference --- oauth2.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/oauth2.go b/oauth2.go index 5f87e2e5d..8372c8d4e 100644 --- a/oauth2.go +++ b/oauth2.go @@ -318,7 +318,7 @@ func (s *reuseTokenSource) Token() (*Token, error) { return nil, err } t.expiryDelta = s.expiryDelta - if s.t.OnTokenRefresh != nil { + if s.t != nil && s.t.OnTokenRefresh != nil { t.OnTokenRefresh = s.t.OnTokenRefresh t.OnTokenRefresh(*t) }