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 (#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:
14
lib/tesla_api/middleware/token_auth.ex
Normal file
14
lib/tesla_api/middleware/token_auth.ex
Normal 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
|
||||
Reference in New Issue
Block a user