Skip to content

Commit

Permalink
Merge pull request #1573 from GSA/login-gov-proxy
Browse files Browse the repository at this point in the history
Login gov proxy
  • Loading branch information
jairoanaya authored Feb 28, 2025
2 parents 0cf3ed4 + eb94c3d commit 6456721
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 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,12 @@ 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 6456721

Please sign in to comment.