Skip to content

Commit

Permalink
JLR: fix authentication (#13960)
Browse files Browse the repository at this point in the history
  • Loading branch information
andig authored May 19, 2024
1 parent cee3cf7 commit 90285a6
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 17 deletions.
7 changes: 2 additions & 5 deletions vehicle/jlr.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,15 +100,12 @@ func (v *JLR) RegisterDevice(log *util.Logger, user, device string, t jlr.Token)

uri := fmt.Sprintf("%s/users/%s/clients", jlr.IFOP_BASE_URL, url.PathEscape(user))

req, err := request.New(http.MethodPost, uri, request.MarshalJSON(data), map[string]string{
req, err := request.New(http.MethodPost, uri, request.MarshalJSON(data), jlr.Headers(device, map[string]string{
"Authorization": "Bearer " + t.AccessToken,
"Content-type": "application/json",
"Accept": "application/json",
"X-Device-Id": device,
"x-telematicsprogramtype": "jlrpy",
"x-App-Id": "ICR_JAGUAR_ANDROID",
"x-App-Secret": "7bf6f544-1926-4714-8066-ceceb40d538d",
})
}))
if err == nil {
_, err = c.DoBody(req)
}
Expand Down
9 changes: 3 additions & 6 deletions vehicle/jlr/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,10 @@ func NewAPI(log *util.Logger, device string, ts oauth2.TokenSource) *API {
Decorator: func(req *http.Request) error {
token, err := ts.Token()
if err == nil {
for k, v := range map[string]string{
"Authorization": fmt.Sprintf("Bearer %s", token.AccessToken),
"X-Device-Id": device,
for k, v := range Headers(device, map[string]string{
"Authorization": "Bearer " + token.AccessToken,
"x-telematicsprogramtype": "jlrpy",
"x-App-Id": "ICR_JAGUAR_ANDROID",
"x-App-Secret": "7bf6f544-1926-4714-8066-ceceb40d538d",
} {
}) {
req.Header.Set(k, v)
}
}
Expand Down
22 changes: 16 additions & 6 deletions vehicle/jlr/identity.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package jlr

import (
"fmt"
"maps"
"net/http"
"time"

Expand All @@ -21,6 +22,18 @@ type Identity struct {
oauth2.TokenSource
}

func Headers(device string, headers map[string]string) map[string]string {
res := map[string]string{
"X-Device-Id": device,
"x-App-Id": "ICR_JAGUAR",
"x-App-Secret": "018dd168-6271-707f-9fd4-aed2bf76905e",
}

maps.Copy(res, headers)

return res
}

// NewIdentity creates Fiat identity
func NewIdentity(log *util.Logger, user, password, device string) *Identity {
return &Identity{
Expand All @@ -32,15 +45,12 @@ func NewIdentity(log *util.Logger, user, password, device string) *Identity {
}

// Login authenticates with given payload
func (v *Identity) login(data map[string]string) (Token, error) {
func (v *Identity) login(data any) (Token, error) {
uri := fmt.Sprintf("%s/tokens", IFAS_BASE_URL)
req, err := request.New(http.MethodPost, uri, request.MarshalJSON(data), map[string]string{
req, err := request.New(http.MethodPost, uri, request.MarshalJSON(data), Headers(v.device, map[string]string{
"Authorization": "Basic YXM6YXNwYXNz",
"Content-type": request.JSONContent,
"X-Device-Id": v.device,
"x-App-Id": "ICR_JAGUAR_ANDROID",
"x-App-Secret": "7bf6f544-1926-4714-8066-ceceb40d538d",
})
}))

var token Token
if err == nil {
Expand Down

0 comments on commit 90285a6

Please sign in to comment.