chore: guard against initial token being nil

This commit is contained in:
andig 2023-12-08 16:45:13 +01:00
parent 4b5435b080
commit 26276ed719
2 changed files with 6 additions and 1 deletions

View file

@ -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,

View file

@ -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))