Mercedes: fix token refresh (#21128)

This commit is contained in:
Rene Nulsch 2025-05-08 17:17:14 +02:00 • committed by GitHub
parent d0d6ac9810
commit 76ff5baf81
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 16 additions and 14 deletions

View file

@ -35,11 +35,11 @@ const (
BffUriNORAM = "https://bff.amap-prod.mobilesdk.mercedes-benz.com"
WidgetUriNORAM = "https://widget.amap-prod.mobilesdk.mercedes-benz.com"
IdUri = "https://id.mercedes-benz.com"
RisApplicationVersionEMEA = "1.52.0"
RisApplicationVersionEMEA = "1.55.0"
RisSdkVersionEMEA = "2.160.1"
RisApplicationVersionAPAC = "1.52.0"
RisApplicationVersionAPAC = "1.55.0"
RisSdkVersionAPAC = "2.160.1"
RisApplicationVersionNORAM = "3.52.0"
RisApplicationVersionNORAM = "3.55.0"
RisSdkVersionNORAM = "2.160.1"
RisOsVersion = "17.3"
RisOsName = "ios"
@ -86,7 +86,6 @@ func mbheaders(includeAuthServerHeader bool, region string) map[string]string {
"Content-Type": "application/json",
"Accept-Language": "en-GB",
"Accept": "*/*",
"x-dev": "1",
}
switch region {

View file

@ -7,7 +7,6 @@ import (
"net/url"
"strings"
"sync"
"time"
"github.com/evcc-io/evcc/server/db/settings"
"github.com/evcc-io/evcc/util"
@ -64,17 +63,14 @@ func NewIdentity(log *util.Logger, token *oauth2.Token, account string, region s
return instance, nil
}
if !token.Valid() {
token.Expiry = time.Now().Add(time.Duration(10) * time.Second)
}
// store config token for potential re-use
var configToken = token
// database token
if !token.Valid() {
var tok oauth2.Token
if err := settings.Json(v.settingsKey(), &tok); err == nil {
v.log.DEBUG.Println("identity.NewIdentity - database token found")
token = &tok
}
var tok oauth2.Token
if err := settings.Json(v.settingsKey(), &tok); err == nil {
v.log.DEBUG.Println("identity.NewIdentity - database token found")
token = &tok
}
if !token.Valid() && token.RefreshToken != "" {
@ -84,6 +80,13 @@ func NewIdentity(log *util.Logger, token *oauth2.Token, account string, region s
}
}
if !token.Valid() {
v.log.DEBUG.Println("identity.NewIdentity - config refreshToken started")
if tok, err := v.RefreshToken(configToken); err == nil {
token = tok
}
}
if !token.Valid() {
return nil, errors.New("token expired")
}