Current section

Files

Jump to
indieweb lib indieweb clients indieauth.ex
Raw

lib/indieweb/clients/indieauth.ex

defmodule IndieWeb.Clients.IndieAuth do
def verify_token(token_endpoint, token) do
with(
{:ok, %IndieWeb.Http.Response{body: body, code: 200}} <-
IndieWeb.Http.get(token_endpoint,
headers: [
{"Authorization", "Bearer #{token}"},
{"Content-Type", "application/json"}
]
),
{:ok, json_body} <- Jason.decode(body)
) do
{:ok, json_body}
else
{:ok, %IndieWeb.Http.Response{} = resp} ->
{:error, reason: :invalid_request, response: resp}
{:error, error} ->
{:error, reason: :invalid_response, error: inspect(error)}
end
end
end