Skip to content

Commit

Permalink
ElixirAuthGoogle.generate_oauth_url/1 now accepts an url as param #94…
Browse files Browse the repository at this point in the history
  • Loading branch information
nelsonic committed May 17, 2023
1 parent d84f394 commit c6e60f3
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 7 deletions.
8 changes: 2 additions & 6 deletions lib/elixir_auth_google.ex
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,6 @@ defmodule ElixirAuthGoogle do
"#{Atom.to_string(s)}://#{h}"
end

def get_baseurl_from_conn(url) when is_binary(url) do
"https://#{url}"
end

def get_baseurl_from_conn(%{host: h} = conn) do
scheme =
case h do
Expand All @@ -61,7 +57,7 @@ defmodule ElixirAuthGoogle do
"""
@spec generate_redirect_uri(conn) :: String.t()
def generate_redirect_uri(url) when is_binary(url) do
url <> get_app_callback_url()
"https://#{url}" <> get_app_callback_url()
end

def generate_redirect_uri(conn) do
Expand Down Expand Up @@ -175,7 +171,7 @@ defmodule ElixirAuthGoogle do
# https://stackoverflow.com/questions/31990134
end

defp google_client_id do
def google_client_id do
System.get_env("GOOGLE_CLIENT_ID") || Application.get_env(:elixir_auth_google, :client_id)
end

Expand Down
5 changes: 4 additions & 1 deletion test/elixir_auth_google_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,10 @@ defmodule ElixirAuthGoogleTest do

test "generate_oauth_url(url) passing in App.Endpoint.url() #94" do
url = "gcal.fly.dev"
assert ElixirAuthGoogle.get_baseurl_from_conn(url) == "https://gcal.fly.dev"
client_id = ElixirAuthGoogle.google_client_id
https = "https%3A%2F%2F#{url}"
auth_url = "https://accounts.google.com/o/oauth2/v2/auth?response_type=code&client_id=#{client_id}&redirect_uri=#{https}%2Fauth%2Fgoogle%2Fcallback&scope=profile%20email"
assert ElixirAuthGoogle.generate_oauth_url(url) =~ auth_url
end

test "generate_redirect_uri(conn) generate correct callback url with custom url path from application environment variable" do
Expand Down

0 comments on commit c6e60f3

Please sign in to comment.