Add support for v3 API tokens in China (#1300)

* Add support for v3 API tokens in China

* Add support for refreshing tokens in China

* Log auth requests without debug output

* Log failed requests to the Owner API
This commit is contained in:
Adrian Kumpf
2021-02-06 17:28:29 +01:00
committed by GitHub
parent aee513db94
commit b1991f541e
5 changed files with 160 additions and 33 deletions

View File

@@ -0,0 +1,14 @@
defmodule TeslaApi.Middleware.TokenAuth do
@behaviour Tesla.Middleware
@impl Tesla.Middleware
def call(%Tesla.Env{} = env, next, _opts) do
env =
case env.opts[:access_token] do
nil -> env
token -> Tesla.put_header(env, "Authorization", "Bearer " <> token)
end
Tesla.run(env, next)
end
end