Skip to content

Commit

Permalink
Proxy configuration for login.gov
Browse files Browse the repository at this point in the history
  • Loading branch information
jdonis committed Feb 27, 2025
1 parent 0cf3ed4 commit dcd841e
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions lib/challenge_gov/login_gov.ex
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,18 @@ defmodule ChallengeGov.LoginGov do
use HTTPoison.Base

alias ChallengeGov.LoginGov.Token
@proxy_config Application.get_env(:httpoison, :proxy, [])

def get_well_known_configuration(idp_authorize_url) do
idp_authorize_url
|> uri_join("/.well-known/openid-configuration")
|> get()
|> get([], proxy_options())
|> handle_response("Sorry, could not fetch well known configuration")
end

def get_public_key(jwks_uri) do
jwks_uri
|> get()
|> get([], proxy_options())
|> handle_response("Sorry, could not fetch public key")
|> case do
{:ok, body} -> {:ok, body |> Map.fetch!("keys") |> List.first()}
Expand All @@ -33,13 +34,13 @@ defmodule ChallengeGov.LoginGov do
}

token_endpoint
|> post(Poison.encode!(body), [{"Content-Type", "application/json"}])
|> post(Poison.encode!(body), [{"Content-Type", "application/json"}], proxy_options())
|> handle_response("Sorry, could not exchange code")
end

def get_user_info(userinfo_endpoint, access_token) do
userinfo_endpoint
|> get([{"Authorization", "Bearer " <> access_token}])
|> get([{"Authorization", "Bearer " <> access_token}], proxy_options())
|> handle_response("Sorry, could not fetch userinfo")
end

Expand Down Expand Up @@ -122,4 +123,13 @@ defmodule ChallengeGov.LoginGov do
def process_response_body(body) do
Poison.decode!(body)
end

defp proxy_options do
if @proxy_config == [] do
[]
else
@proxy_config
end
end

end

0 comments on commit dcd841e

Please sign in to comment.