Skip to content

Commit

Permalink
chore: guard against initial token being nil
Browse files Browse the repository at this point in the history
  • Loading branch information
andig committed Dec 8, 2023
1 parent 4b5435b commit 26276ed
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
5 changes: 5 additions & 0 deletions util/oauth/tokensource.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@ type TokenSource struct {
}

func RefreshTokenSource(token *oauth2.Token, refresher TokenRefresher) oauth2.TokenSource {
if token == nil {
// allocate an (expired) token or mergeToken will fail
token = new(oauth2.Token)
}

ts := &TokenSource{
token: token,
refresher: refresher,
Expand Down
2 changes: 1 addition & 1 deletion vehicle/tronity.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ func NewTronityFromConfig(other map[string]interface{}) (api.Vehicle, error) {
// https://app.platform.tronity.io/docs#tag/Authentication
if err := cc.Tokens.Error(); err != nil {
// use app flow if we don't have tokens
ts = oauth.RefreshTokenSource(&oauth2.Token{}, v)
ts = oauth.RefreshTokenSource(nil, v)
} else {
// use provided tokens generated by code flow
ctx := context.WithValue(context.Background(), oauth2.HTTPClient, request.NewClient(log))
Expand Down

0 comments on commit 26276ed

Please sign in to comment.