chore: guard against initial token being nil
This commit is contained in:
parent
4b5435b080
commit
26276ed719
2 changed files with 6 additions and 1 deletions
|
|
@ -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,
|
||||
|
|
|
|||
|
|
@ -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))
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue