Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JLR: fix authentication #13960

Merged
merged 4 commits into from
May 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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