log setup web

This commit is contained in:
Elizabeth Hunt 2023-09-13 19:47:50 -06:00
parent 8f722fde72
commit 87bd117289
Signed by: simponic
GPG Key ID: 52B3774857EB24B1

View File

@ -26,17 +26,25 @@ defmodule Chessh.Web.Endpoint do
redirect_uri redirect_uri
] = get_discord_configs() ] = get_discord_configs()
Logger.warn(
inspect(
{String.to_charlist(discord_login_url), [], ~c"application/x-www-form-urlencoded",
~c"scope=#{discord_scope}&client_id=#{client_id}&client_secret=#{client_secret}&code=#{req_token}&grant_type=authorization_code&redirect_uri=#{redirect_uri}"}
)
)
resp = resp =
case conn.params do case conn.params do
%{"code" => req_token} -> %{"code" => req_token} ->
case :httpc.request( case :httpc.request(
:post, :post,
{String.to_charlist(discord_login_url), [], 'application/x-www-form-urlencoded', {String.to_charlist(discord_login_url), [],
'scope=#{discord_scope}&client_id=#{client_id}&client_secret=#{client_secret}&code=#{req_token}&grant_type=authorization_code&redirect_uri=#{redirect_uri}'}, ~c"application/x-www-form-urlencoded",
~c"scope=#{discord_scope}&client_id=#{client_id}&client_secret=#{client_secret}&code=#{req_token}&grant_type=authorization_code&redirect_uri=#{redirect_uri}"},
[], [],
[] []
) do ) do
{:ok, {{_, 200, 'OK'}, _, resp}} -> {:ok, {{_, 200, ~c"OK"}, _, resp}} ->
Jason.decode!(String.Chars.to_string(resp)) Jason.decode!(String.Chars.to_string(resp))
end end
end end
@ -442,7 +450,7 @@ defmodule Chessh.Web.Endpoint do
conn conn
|> put_resp_cookie("jwt", token) |> put_resp_cookie("jwt", token)
|> put_resp_header("location", client_redirect_location) |> put_resp_header("location", client_redirect_location)
|> send_resp(301, '') |> send_resp(301, ~c"")
_ -> _ ->
conn conn
@ -458,13 +466,13 @@ defmodule Chessh.Web.Endpoint do
:get, :get,
{String.to_charlist(discord_user_api_url), {String.to_charlist(discord_user_api_url),
[ [
{'Authorization', String.to_charlist("Bearer #{access_token}")}, {~c"Authorization", String.to_charlist("Bearer #{access_token}")},
{'User-Agent', discord_user_agent} {~c"User-Agent", discord_user_agent}
]}, ]},
[], [],
[] []
) do ) do
{:ok, {{_, 200, 'OK'}, _, user_details}} -> {:ok, {{_, 200, ~c"OK"}, _, user_details}} ->
%{"username" => username, "discriminator" => discriminator, "id" => discord_id} = %{"username" => username, "discriminator" => discriminator, "id" => discord_id} =
Jason.decode!(String.Chars.to_string(user_details)) Jason.decode!(String.Chars.to_string(user_details))