Skip to content

Commit

Permalink
Merge pull request #1 from Dainismo/feature/add_token_refresh_handler
Browse files Browse the repository at this point in the history
Added token refresh callback
  • Loading branch information
Dainismo authored Nov 8, 2023
2 parents 4c91c17 + 3639b6c commit 0fa29c2
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
4 changes: 4 additions & 0 deletions oauth2.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

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

0 comments on commit 0fa29c2

Please sign in to comment.