Toyota: add missing x-channel header (#27542)

Co-authored-by: Martin Schuppert <mschuppert@redhat.com>
This commit is contained in:
andig 2026-02-20 12:06:35 +01:00 • committed by GitHub
parent c69c7672bd
commit 5ecf7795b8
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -10,6 +10,7 @@ import (
"github.com/evcc-io/evcc/util"
"github.com/evcc-io/evcc/util/request"
"github.com/evcc-io/evcc/util/transport"
"golang.org/x/oauth2"
)
@ -21,15 +22,15 @@ const (
AuthorizationPath = "oauth2/realms/root/realms/tme/authorize?client_id=oneapp&scope=openid+profile+write&response_type=code&redirect_uri=com.toyota.oneapp:/oauth2Callback&code_challenge=plain&code_challenge_method=plain"
VehicleGuidPath = "v2/vehicle/guid"
RemoteElectricStatusPath = "v1/global/remote/electric/status"
ApiKey = "tTZipv6liF74PwMfk9Ed68AQ0bISswwf3iHQdqcF"
ClientRefKey = "3e0b15f6c9c87fbd"
apiKey = "tTZipv6liF74PwMfk9Ed68AQ0bISswwf3iHQdqcF"
clientRefKey = "3e0b15f6c9c87fbd"
channel = "ONEAPP" // Required x-channel header value for Toyota OneApp API
)
type API struct {
*request.Helper
log *util.Logger
identity *Identity
clientRef string
log *util.Logger
identity *Identity
}
func NewAPI(log *util.Logger, identity *Identity) *API {
@ -41,16 +42,26 @@ func NewAPI(log *util.Logger, identity *Identity) *API {
v.Timeout = 120 * time.Second
// replace client transport with authenticated transport
v.Transport = &oauth2.Transport{
Source: identity,
Base: v.Transport,
}
// create HMAC digest for x-client-ref header
h := hmac.New(sha256.New, []byte(ClientRefKey))
h := hmac.New(sha256.New, []byte(clientRefKey))
h.Write([]byte(v.identity.uuid))
v.clientRef = hex.EncodeToString(h.Sum(nil))
clientRef := hex.EncodeToString(h.Sum(nil))
// replace client transport with authenticated transport
v.Transport = &transport.Decorator{
Decorator: transport.DecorateHeaders(map[string]string{
"Accept": request.JSONContent,
"x-guid": v.identity.uuid,
"x-api-key": apiKey,
"x-client-ref": clientRef,
"x-appversion": clientRefKey,
"x-channel": channel,
}),
Base: &oauth2.Transport{
Source: identity,
Base: v.Transport,
},
}
return v
}
@ -58,19 +69,11 @@ func NewAPI(log *util.Logger, identity *Identity) *API {
func (v *API) Vehicles() ([]string, error) {
uri := fmt.Sprintf("%s/%s", ApiBaseUrl, VehicleGuidPath)
req, err := request.New(http.MethodGet, uri, nil, map[string]string{
"Accept": request.JSONContent,
"x-guid": v.identity.uuid,
"x-api-key": ApiKey,
"x-client-ref": v.clientRef,
"x-appversion": ClientRefKey,
})
var resp Vehicles
if err == nil {
err = v.DoJSON(req, &resp)
}
var res Vehicles
err := v.GetJSON(uri, &res)
var vehicles []string
for _, v := range resp.Payload {
for _, v := range res.Payload {
vehicles = append(vehicles, v.VIN)
}
return vehicles, err
@ -79,17 +82,12 @@ func (v *API) Vehicles() ([]string, error) {
func (v *API) Status(vin string) (Status, error) {
uri := fmt.Sprintf("%s/%s", ApiBaseUrl, RemoteElectricStatusPath)
req, err := request.New(http.MethodGet, uri, nil, map[string]string{
"Accept": request.JSONContent,
"x-guid": v.identity.uuid,
"x-api-key": ApiKey,
"x-client-ref": v.clientRef,
"x-appversion": ClientRefKey,
"vin": vin,
req, _ := request.New(http.MethodGet, uri, nil, map[string]string{
"vin": vin,
})
var status Status
if err == nil {
err = v.DoJSON(req, &status)
}
return status, err
var res Status
err := v.DoJSON(req, &res)
return res, err
}