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

Jason.DecodeError from ExForce.OAuth.get_token/2 #70

Closed
ggiill opened this issue Feb 28, 2023 · 1 comment
Closed

Jason.DecodeError from ExForce.OAuth.get_token/2 #70

ggiill opened this issue Feb 28, 2023 · 1 comment

Comments

@ggiill
Copy link

ggiill commented Feb 28, 2023

This just started happening today:

{:error,
 {Tesla.Middleware.JSON, :decode,
  %Jason.DecodeError{
    data: <<...REDACTED...>>,
    position: 0,
    token: nil
  }}}

Dug in a bit, and the order of the Tesla.Middleware makes a difference here for some reason.

These don't work:

ExForce.OAuth.get_token(
  instance_url,
  grant_type: "refresh_token",
  client_id: client_id,
  client_secret: client_secret,
  refresh_token: refresh_token
)
instance_url
|> ExForce.Client.build_oauth_client()
|> Tesla.post(
  instance_url <> "/services/oauth2/token",
  %{
    grant_type: "refresh_token",
    client_id: client_id,
    client_secret: client_secret,
    refresh_token: refresh_token
  }
)
[
  {Tesla.Middleware.BaseUrl, instance_url},
  {Tesla.Middleware.Compression, format: "gzip"},
  Tesla.Middleware.FormUrlencoded,
  {Tesla.Middleware.DecodeJson, engine: Jason},
  {Tesla.Middleware.Headers, []}
]
|> Tesla.client()
|> Tesla.post(
  "/services/oauth2/token",
  %{
    grant_type: "refresh_token",
    client_id: client_id,
    client_secret: client_secret,
    refresh_token: refresh_token
  }
)

(This one ^^^ is basically ExForce.Client.Tesla.build_oauth_client/2)

But moving Tesla.Middleware.DecodeJson first in the list of middleware does, and yields an {:ok, %Tesla.Env{}} tuple with decoded JSON body:

[
  {Tesla.Middleware.DecodeJson, engine: Jason},
  {Tesla.Middleware.BaseUrl, instance_url},
  {Tesla.Middleware.Compression, format: "gzip"},
  Tesla.Middleware.FormUrlencoded,
  {Tesla.Middleware.Headers, []}
]
|> Tesla.client()
|> Tesla.post(
  "/services/oauth2/token",
  %{
  grant_type: "refresh_token",
  client_id: client_id,
  client_secret: client_secret,
  refresh_token: refresh_token
  }
)
@ggiill
Copy link
Author

ggiill commented Feb 28, 2023

Update: This seems to actually be an issue with bumping tesla from 1.4.4 to 1.5.1...

...though this could be fixed by switching the order of the middleware: #42

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant