mirror of
https://github.com/netfun2000/hipudding-teslamate.git
synced 2026-02-27 09:44:28 +08:00
* 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
15 lines
335 B
Elixir
15 lines
335 B
Elixir
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
|