Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
andig committed Dec 17, 2023
1 parent 1113b10 commit 9d41094
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 31 deletions.
26 changes: 13 additions & 13 deletions vehicle/polestar/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@ import (
"github.com/evcc-io/evcc/util"
"github.com/evcc-io/evcc/util/request"
"github.com/evcc-io/evcc/util/transport"
"github.com/samber/lo"
"github.com/shurcooL/graphql"
"github.com/hasura/go-graphql-client"
"golang.org/x/oauth2"
)

Expand Down Expand Up @@ -49,22 +48,23 @@ func NewAPI(log *util.Logger, identity oauth2.TokenSource) *API {

func (v *API) Vehicles(ctx context.Context) ([]string, error) {
var res struct {
MyStar struct {
// Type string `graphql:"__typename"`
GetConsumer Consumer
GetConsumerCars []ConsumerCar
GetConsumerCarsV2 struct {
Vin string
InternalVehicleIdentifier string
}
}

var vins []string
err := v.client.Query(ctx, &res, nil)
if err == nil {
vins = lo.Map(res.MyStar.GetConsumerCars, func(v ConsumerCar, _ int) string {
return v.Vin
})
}
err := v.client.Query(ctx, &res, nil, graphql.OperationName("getCars"))
// if err == nil {
// vins = lo.Map(res.MyStar.GetConsumerCars, func(v ConsumerCar, _ int) string {
// return v.Vin
// })
// }

fmt.Println(res)

v.Status(ctx, vins[0])
// v.Status(ctx, vins[0])

return vins, err
}
Expand Down
27 changes: 11 additions & 16 deletions vehicle/polestar/identity.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import (
"github.com/evcc-io/evcc/util"
"github.com/evcc-io/evcc/util/oauth"
"github.com/evcc-io/evcc/util/request"
cv "github.com/nirasan/go-oauth-pkce-code-verifier"
"golang.org/x/net/publicsuffix"
"golang.org/x/oauth2"
)
Expand Down Expand Up @@ -72,29 +71,25 @@ func (v *Identity) Login(user, password string) error {
}
}

cv, err := cv.CreateCodeVerifier()
if err != nil {
return err
}
cv := oauth2.GenerateVerifier()

uri := v.oc.AuthCodeURL(state(), oauth2.AccessTypeOffline,
oauth2.SetAuthURLParam("code_challenge", cv.CodeChallengeS256()),
oauth2.SetAuthURLParam("code_challenge_method", "S256"),
oauth2.S256ChallengeOption(cv),
oauth2.SetAuthURLParam("access_token_manager_id", "JWTpolxplore"),
)

var resume string
if err == nil {
var param request.InterceptResult
v.Client.CheckRedirect, param = request.InterceptRedirect("resumePath", false)
var param request.InterceptResult
v.Client.CheckRedirect, param = request.InterceptRedirect("resumePath", false)

if _, err = v.Get(uri); err == nil {
resume, err = param()
}
_, err := v.Get(uri)

v.Client.CheckRedirect = nil
var resume string
if err == nil {
resume, err = param()
}

v.Client.CheckRedirect = nil

var code string
if err == nil {
params := url.Values{
Expand All @@ -118,7 +113,7 @@ func (v *Identity) Login(user, password string) error {
if err == nil {
params := url.Values{
"code": []string{code},
"code_verifier": []string{cv.CodeChallengePlain()},
"code_verifier": []string{cv},
"redirect_uri": []string{OAuth2Config.RedirectURL},
"grant_type": []string{"authorization_code"},
}
Expand Down
4 changes: 2 additions & 2 deletions vehicle/polestar/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ func NewProvider(log *util.Logger, api *API, vin string, expiry, cache time.Dura
// return res, err
// }

// SoC implements the api.Vehicle interface
func (v *Provider) SoC() (float64, error) {
// Soc implements the api.Vehicle interface
func (v *Provider) Soc() (float64, error) {
// res, err := v.statusG()
return 0, nil
}
Expand Down

0 comments on commit 9d41094

Please sign in to comment.